adjacency matrix/Floyd/Warshall
Posted: Tue May 24, 2011 11:03 pm
Apparently my teacher believes that even if we don't have time to learn stuff (nor enough examples) we should move on, so I now need to know how to make Floyd-Warshall's and Warshall's algorithms in clisp.
My first problem is to generate the adjacency matrix from the graph, in this case it would be a list of lists, e.g.:
I've got this:
Any help is greatly appreciated.
PS: I've been told I should have been using let instead of setf to declare variables, but I don't know how to use it (I investigated but can't make matrix function work with let ;__;). I hate when there's a class in school and they teach you wrong u__u
My first problem is to generate the adjacency matrix from the graph, in this case it would be a list of lists, e.g.:
That should generate:((A B) (A C) (A D) (B C) (C D))
Code: Select all
((0 1 1 1) (1 0 1 9) (1 1 0 1) (1 9 1 0))
Code: Select all
(defun floyd(graph)
(setf l (length graph))
(setf mat (matrix l graph)))
(defun matrix(l graph)
(setf matrix (make-array (list l l)))
(dotimes (i l)
(dotimes (j l)
(if (= i j)
(setf (aref matrix i j) 0)
(setf (aref matrix i j) ???))))
matrix)
PS: I've been told I should have been using let instead of setf to declare variables, but I don't know how to use it (I investigated but can't make matrix function work with let ;__;). I hate when there's a class in school and they teach you wrong u__u