Add transitive-closure.
This commit is contained in:
parent
caa684d8a9
commit
8a4d087a73
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
|
||||
floyd-warshall transitive-closure
|
||||
|
||||
graphviz)
|
||||
|
||||
|
@ -208,6 +208,8 @@
|
|||
;; 7 All-pairs Shortest Paths
|
||||
(define (floyd-warshall g)
|
||||
(g:floyd-warshall (gg g)))
|
||||
(define (transitive-closure g)
|
||||
(g:transitive-closure (gg g)))
|
||||
|
||||
;; 10 Graphviz
|
||||
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
||||
|
@ -310,6 +312,7 @@
|
|||
|
||||
;; 7 All-pairs Shortest Paths
|
||||
[floyd-warshall (-> Graph (Mutable-HashTable (List Any Any) Number))]
|
||||
[transitive-closure (-> Graph (Mutable-HashTable (List Any Any) Boolean))]
|
||||
|
||||
;; 10 Graphviz
|
||||
[graphviz (->* (Graph)
|
||||
|
@ -474,7 +477,25 @@
|
|||
((b d) . 3.0)
|
||||
((b b) . 0)
|
||||
((d b) . +inf.0)
|
||||
((a b) . 1.0))))
|
||||
((a b) . 1.0)))
|
||||
|
||||
(check-equal? (hash->ordered-list (transitive-closure g0))
|
||||
'(((a d) . #t)
|
||||
((c c) . #t)
|
||||
((b a) . #f)
|
||||
((a a) . #t)
|
||||
((d c) . #f)
|
||||
((a c) . #t)
|
||||
((c b) . #f)
|
||||
((d d) . #t)
|
||||
((c a) . #f)
|
||||
((b c) . #f)
|
||||
((d a) . #f)
|
||||
((c d) . #t)
|
||||
((b d) . #t)
|
||||
((b b) . #t)
|
||||
((d b) . #f)
|
||||
((a b) . #t))))
|
||||
|
||||
(test-case "10 Graphviz"
|
||||
(define g (directed-graph '((a b) (b c))))
|
||||
|
|
Loading…
Reference in a new issue