Dijkstra's algorithm: Difference between revisions
Content added Content deleted
Line 1,379: | Line 1,379: | ||
(defun dijkstra-short-paths (z w) |
(defun dijkstra-short-paths (z w) |
||
(loop for (a b) in ( |
(loop for (a b) in (loop for v on z nconc |
||
⚫ | |||
collect `(,(car v) ,e))) |
|||
⚫ | |||
(format t "~{Path: ~A Distance: ~A~}~%" |
(format t "~{Path: ~A Distance: ~A~}~%" |
||
( |
(car (sort *r* #'< :key #'cadr))))) |
||
(defun pairs (w) |
|||
(loop for a in w and d on (cdr w) |
|||
⚫ | |||
(defun short-path (w i g) |
|||
⚫ | |||
(car (sort *r* #'< :key #'cadr))) |
|||
(defun paths (w c g z v) |
(defun paths (w c g z v) |
||
(if (eql c g) (push `(,(reverse v) ,z) *r*) |
(if (eql c g) (push `(,(reverse v) ,z) *r*) |
||
(loop for a in ( |
(loop for a in (sort (cdr (assoc c w)) #'< :key #'cddr) |
||
(unless (member b v) |
for b = (cadr a) do (unless (member b v) |
||
(paths w b g (+ (cddr a) z |
(paths w b g (+ (cddr a) z) |
||
(cons b v)))))) |
|||
(defun nodes (c w) |
|||
(sort (cdr (assoc c w)) #'< :key #'cddr)) |
|||
</lang> |
</lang> |
||
{{out}} |
{{out}} |