Add floyd-warshall.
This commit is contained in:
parent
80be5c48e5
commit
caa684d8a9
29
graph.rkt
29
graph.rkt
|
@ -40,6 +40,7 @@
|
||||||
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
|
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
|
||||||
|
|
||||||
bellman-ford dijkstra dag-shortest-paths
|
bellman-ford dijkstra dag-shortest-paths
|
||||||
|
floyd-warshall
|
||||||
|
|
||||||
graphviz)
|
graphviz)
|
||||||
|
|
||||||
|
@ -204,6 +205,10 @@
|
||||||
(define (dag-shortest-paths g source)
|
(define (dag-shortest-paths g source)
|
||||||
(g:dag-shortest-paths (gg g) source))
|
(g:dag-shortest-paths (gg g) source))
|
||||||
|
|
||||||
|
;; 7 All-pairs Shortest Paths
|
||||||
|
(define (floyd-warshall g)
|
||||||
|
(g:floyd-warshall (gg g)))
|
||||||
|
|
||||||
;; 10 Graphviz
|
;; 10 Graphviz
|
||||||
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
||||||
(g:graphviz (gg g) #:output output #:colors colors)))
|
(g:graphviz (gg g) #:output output #:colors colors)))
|
||||||
|
@ -303,6 +308,9 @@
|
||||||
[dag-shortest-paths (-> Graph Any (Values (Mutable-HashTable Any Number)
|
[dag-shortest-paths (-> Graph Any (Values (Mutable-HashTable Any Number)
|
||||||
(Mutable-HashTable Any Any)))]
|
(Mutable-HashTable Any Any)))]
|
||||||
|
|
||||||
|
;; 7 All-pairs Shortest Paths
|
||||||
|
[floyd-warshall (-> Graph (Mutable-HashTable (List Any Any) Number))]
|
||||||
|
|
||||||
;; 10 Graphviz
|
;; 10 Graphviz
|
||||||
[graphviz (->* (Graph)
|
[graphviz (->* (Graph)
|
||||||
(#:output Output-Port
|
(#:output Output-Port
|
||||||
|
@ -447,6 +455,27 @@
|
||||||
(check-equal? (hash->ordered-list dsp-pred)
|
(check-equal? (hash->ordered-list dsp-pred)
|
||||||
'((a . #f) (b . a) (c . a) (d . b))))
|
'((a . #f) (b . a) (c . a) (d . b))))
|
||||||
|
|
||||||
|
(test-case "7 All-pairs Shortest Paths"
|
||||||
|
(define g0 (weighted-graph/directed '((1 a b) (2 a c) (3 b d) (3 c d))))
|
||||||
|
|
||||||
|
(check-equal? (hash->ordered-list (floyd-warshall g0))
|
||||||
|
'(((a d) . 4.0)
|
||||||
|
((c c) . 0.0)
|
||||||
|
((b a) . +inf.0)
|
||||||
|
((a a) . 0.0)
|
||||||
|
((d c) . +inf.0)
|
||||||
|
((a c) . 2.0)
|
||||||
|
((c b) . +inf.0)
|
||||||
|
((d d) . 0.0)
|
||||||
|
((c a) . +inf.0)
|
||||||
|
((b c) . +inf.0)
|
||||||
|
((d a) . +inf.0)
|
||||||
|
((c d) . 3.0)
|
||||||
|
((b d) . 3.0)
|
||||||
|
((b b) . 0)
|
||||||
|
((d b) . +inf.0)
|
||||||
|
((a b) . 1.0))))
|
||||||
|
|
||||||
(test-case "10 Graphviz"
|
(test-case "10 Graphviz"
|
||||||
(define g (directed-graph '((a b) (b c))))
|
(define g (directed-graph '((a b) (b c))))
|
||||||
(check-equal? (graphviz g)
|
(check-equal? (graphviz g)
|
||||||
|
|
Loading…
Reference in New Issue