Re: Floyd Warshall
- From: andrea <kerny404@xxxxxxxxx>
- Date: Thu, 30 Aug 2007 01:06:41 -0700
Another little thing, I also have a recursive version (the first I
did) which is working fine
(defun shortest-path (src dst k)
"algoritmo di calcolo principale, ritorna una cons della lista delle
tappe e la distanza totale.
Soluzione ricorsiva, piu' elegante ma purtroppo inutilizzabile con un
numero di citta anche piccolo"
(cond
((zerop k) (cons (list dst) (get-dist src dst)))
(T
(let*
((diretto (shortest-path src dst (1- k)))
(infra-list (remove src (remove dst cities))) ;; lista dei nodi che
possono essere intermediari
(min diretto)) ;; inizialmente il percorso diretto e' il minimo
(dolist
(inter infra-list)
;; (print (list src dst k inter infra-list))
(let
((before (shortest-path src inter (1- k))) (after (shortest-path
inter dst (1- k))))
(if
(> (cdr min) (+ (cdr before) (cdr after)))
(setq min (cons (append (car before) (car after)) (+ (cdr
before) (cdr after)))))))
min))))
BUT, for even a small number of cities (6) it take hours... That's
right because the numeber of function calls is factorial, but I think
there should be some ways to eliminate many calls...
Ideas?
.
- Follow-Ups:
- Re: Floyd Warshall
- From: Geoff Wozniak
- Re: Floyd Warshall
- References:
- Floyd Warshall
- From: andrea
- Re: Floyd Warshall
- From: Gene
- Re: Floyd Warshall
- From: andrea
- Floyd Warshall
- Prev by Date: Re: ANN: ABLE 0.4
- Next by Date: Re: Floyd Warshall
- Previous by thread: Re: Floyd Warshall
- Next by thread: Re: Floyd Warshall
- Index(es):