;------------------------------------------------------------------------------------ ;first, creating breath-first-tree. second,finding path and then counting costs at each path ;After comparing with each cost, I can find the shortest path. ;But I finished until creating breath-first-tree. ;----------------------------------------------------------------------------------- (setf nodes (list '(a h 3) '(a b 4) '(b c 2) '(b f 3) '(c i 6) '(i e 4) '(e d 3) '(c d 4) '(d g 4) ;input date '(e g 7) '(f g 6) '(g j 1) '(f m 5) '(m j 2) '(j k 4) '(g k 3) '(e l 2) '(l k 3) )) ; initalizing (setf nodes2 nodes) (setf neig_list nil) ;neighbor (setf start nil) ;starting point for atom (setf start_list nil) ;startig point for list (setf child_a nil) ; successors and parents (setf check_error nil) (setf search_a nil) ; main function (defun breath (start goal) (cond ( (atom start) (setf start_list (list start))) ( t (setf start_list start) ) ) (push (car start_list) check_error) ;to check overlap parents node (setf nodes2 nodes) (setf neig_list nil) (check_goal goal (car start_list)) (setf search_a (neighbor (car start_list))) (check_over check_error search_a) ; searching neighbor (setf child_a (append (cdr start_list) search_a)) ;composing neighbor with parents (print child_a) (breath child_a goal) ) ; finding neighbor (defun neighbor (state) (cond ((eql state (first (car nodes2))) (push (setf neighbor (second (car nodes2))) neig_list) (setq nodes2 (cdr nodes2)) (neighbor state)) ((eql state (second (car nodes2))) (push (setf neighbor (first (car nodes2))) neig_list) (setq nodes2 (cdr nodes2)) (neighbor state)) ((eql nodes2 nil) (print neig_list) ) (t (setq nodes2 (cdr nodes2)) (neighbor state)) )) ; checking goal (defun check_goal (x y) (cond ( (eql x y) (print "I got it!!") (exit) ) (t nil) ) ) ; checking overlaping (defun check_over (p search_a) (cond ( (eql p nil) nil) ( t (delete (car (member (car p) search_a)) search_a ) (check_over (setf p (cdr p)) search_a )) ) )