Add johnson.
This commit is contained in:
parent
8a4d087a73
commit
709c1360b9
1 changed files with 23 additions and 2 deletions
25
graph.rkt
25
graph.rkt
|
@ -40,7 +40,7 @@
|
|||
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
|
||||
|
||||
bellman-ford dijkstra dag-shortest-paths
|
||||
floyd-warshall transitive-closure
|
||||
floyd-warshall transitive-closure johnson
|
||||
|
||||
graphviz)
|
||||
|
||||
|
@ -210,6 +210,8 @@
|
|||
(g:floyd-warshall (gg g)))
|
||||
(define (transitive-closure g)
|
||||
(g:transitive-closure (gg g)))
|
||||
(define (johnson g)
|
||||
(g:johnson (gg g)))
|
||||
|
||||
;; 10 Graphviz
|
||||
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
||||
|
@ -313,6 +315,7 @@
|
|||
;; 7 All-pairs Shortest Paths
|
||||
[floyd-warshall (-> Graph (Mutable-HashTable (List Any Any) Number))]
|
||||
[transitive-closure (-> Graph (Mutable-HashTable (List Any Any) Boolean))]
|
||||
[johnson (-> Graph (Mutable-HashTable (List Any Any) Number))]
|
||||
|
||||
;; 10 Graphviz
|
||||
[graphviz (->* (Graph)
|
||||
|
@ -495,7 +498,25 @@
|
|||
((b d) . #t)
|
||||
((b b) . #t)
|
||||
((d b) . #f)
|
||||
((a b) . #t))))
|
||||
((a b) . #t)))
|
||||
|
||||
(check-equal? (hash->ordered-list (johnson g0))
|
||||
'(((a d) . 4)
|
||||
((c c) . 0)
|
||||
((b a) . +inf.0)
|
||||
((a a) . 0)
|
||||
((d c) . +inf.0)
|
||||
((a c) . 2)
|
||||
((c b) . +inf.0)
|
||||
((d d) . 0)
|
||||
((c a) . +inf.0)
|
||||
((b c) . +inf.0)
|
||||
((d a) . +inf.0)
|
||||
((c d) . 3)
|
||||
((b d) . 3)
|
||||
((b b) . 0)
|
||||
((d b) . +inf.0)
|
||||
((a b) . 1))))
|
||||
|
||||
(test-case "10 Graphviz"
|
||||
(define g (directed-graph '((a b) (b c))))
|
||||
|
|
Loading…
Reference in a new issue