(defun diagram () (progn (defvar path) (setq path (list 0)) (defvar nodepath) (setq nodepath (list 0)) (setq branch (list 0)) (defvar startpoint) (defvar endpoint) (defvar x) (defvar result) (setq result (list 0)) (defun member-in-current-list (m e) (defvar templist) (defvar output) (defvar flag) (print "searching for the node in the start list function") (print m) (setq output (list 0)) (print e) (loop (setq templist (list 0)) (setf flag 0) (cond ((not (car m)) (return (cdr output)))) (setq templist (append (cdr templist) e)) (loop (cond ((or (not (car templist)) (equal (car (car m)) (car (car templist)) )) (return)) ((not (equal (car (car m)) (car (car templist)) )) (setf flag 1))) (setq templist (cdr templist)) ) (cond ((equal flag 1) (setq output (append output (list (car m)))))) (setq m (cdr m)) (print m) (print " output so far") (print output)) ) (defun member-in-final-list (m) (defvar templist) (print "searching for the node in the final list function") (print m) (setq templist (list 0)) (loop (cond ((not (car m)) (return (cdr templist))) ( (not (member (car (car m)) nodepath)) (setq templist (append templist (list (car m))))) ) (setq m (cdr m)) (print " templist so far") (print (cdr templist)) )) (defun search-for-the-end-point (m b) (progn (print "searching for the goal function") (print m) (cond ((equal (car (car m)) b ) (progn (setq path (append (list (car m)) path )) (setq result (append result (list path))) (print "The Shortest Path is ") (print result) (print t))) (t (progn (setq m (cdr m)) (cond((not (equal m nil)) (search-for-the-end-point m b)))))) )) (defun search-graph (a b h) (defvar new-sub-branch) (defvar tempnode) (defvar end) (setq branch (list 0)) (setf end 0) (setf x h) (setq end nil) (setq new-sub-branch (list 0)) (setq branch (cdr (append branch (list (list a x))))) (setq path (list 0)) (print branch) (loop (setf x (incf x)) (print " creating new sub branch") (setq new-sub-branch (new-level (car (car branch)) x)) (print new-sub-branch) (print "enter the members functions") (setq new-sub-branch (member-in-current-list new-sub-branch branch)) (setq new-sub-branch (member-in-final-list new-sub-branch)) (cond ((not new-sub-branch) (cond ((car branch) (setq new-sub-branch (cdr branch))) (t (progn (print path) (print "no solution") (recursion b) ))))) (move branch) (setq branch (cdr branch)) (setq branch (append new-sub-branch branch)) (print "new branch") (print branch) (setq end (search-for-the-end-point branch b)) (cond ( end (progn (cond ((not(equal firstlevel nil)) (recursion b)) (t (return nil)))))) (print "done with one loop") )) (defun recursion (b) (setq firstlevel (cdr firstlevel)) (cond ((equal firstlevel nil) (progn (print " the list of different paths is ") (setq result (cdr result)) (print result) (shortest-path) (print "the end of the job") (return))) (t (search-graph (car (car firstlevel)) b 1)))) (defun move (m) (progn (print " move function") (setq path (append (list (car m)) path )) (setq nodepath (append (list (car (car m))) nodepath )) (print path) (print nodepath) (setq m (cdr m)) ) ) (defun new-level ( b x) (defvar tem) (setq tem (list 0)) (setq i 0) (print " in the new-level function") (setq level (list 0)) (loop (when (= i 19) (progn (print (cdr level))(return (cdr level)))) (COND ((equal b (car (aref k i))) (progn ( setq tem (cdr (aref k i) )) (setq tem (append tem (list x)) ) (setq level (append level (list tem)))))) (setq i (incf i)) ) ) (defun shortest-path () (defvar shortestpath) (setq shortestpath result) (setq n (cadr (car (car shortestpath)))) (setq finallist (car shortestpath)) (loop (setq shortestpath (cdr shortestpath)) (cond ((not (equal shortestpath nil)) (progn (setq v (cadr (car (car shortestpath)))) (cond ((< v n) (setq finallist (car shortestpath)))))) (t (print "shortestpath is ") (print finallist) (return))))) (setq K (make-array '20)) (setf (aref k 0) (list 'S 'A )) (setf (aref k 1) (list 'S 'Z )) (setf (aref k 2) (list 'A 'S )) (setf (aref k 3) (list 'A 'D )) (setf (aref k 4) (list 'Z 'S )) (setf (aref k 7) (list 'Z 'D )) (setf (aref k 5) (list 'D 'A )) (setf (aref k 6) (list 'D 'Z )) (setf (aref k 8 ) (list 'D 'E )) (setf (aref k 9 ) (list 'D 'F )) (setf (aref K 10) (list 'E 'D )) (setf (aref k 11 ) (list 'F 'D )) (setf (aref k 12 ) (list 'a 'c )) (setf (aref k 13 ) (list 'D 'c )) (setf (aref K 14) (list 'E 'c )) (setf (aref k 15 ) (list 'e 'a )) (setf (aref k 16 ) (list 'c 'a )) (setf (aref k 17 ) (list 'c 'd )) (setf (aref K 18) (list 'c 'e )) (setf (aref k 19 ) (list 'a 'e )) (print "enter the start point") (setf x 0) (setq startpoint (read)) (print "enter the second point") (setq endpoint (read)) (setq firstlevel (new-level startpoint 0)) (search-graph startpoint endpoint 0) ))