Browse Source

Add scc.

master
Sergiu Ivanov 3 months ago
parent
commit
f918eca123
  1. 14
      graph.rkt

14
graph.rkt

@ -35,7 +35,7 @@
bfs bfs/generalized fewest-vertices-path
dfs dfs/generalized
dag? tsort cc
dag? tsort cc cc/bfs scc
graphviz)
@ -177,6 +177,10 @@
(g:tsort (gg g)))
(define (cc g)
(g:cc (gg g)))
(define (cc/bfs g)
(g:cc/bfs (gg g)))
(define (scc g)
(g:scc (gg g)))
;; 10 Graphviz
(define (graphviz g #:output [output #f] #:colors [colors #f])
@ -260,6 +264,8 @@
[dag? (-> Graph Boolean)]
[tsort (-> Graph (Listof Any))]
[cc (-> Graph (Listof (Listof Any)))]
[cc/bfs (-> Graph (Listof (Listof Any)))]
[scc (-> Graph (Listof (Listof Any)))]
;; 10 Graphviz
[graphviz (->* (Graph)
@ -365,7 +371,11 @@
(check-equal? (tsort (directed-graph '((a b) (b c) (a d) (d b))))
'(a d b c))
(check-equal? (cc (undirected-graph '((a b) (b c) (d e))))
'((e d) (a b c))))
'((e d) (a b c)))
(check-equal? (cc/bfs (undirected-graph '((a b) (b c) (d e))))
'((e d) (a b c)))
(check-equal? (scc (directed-graph '((a b) (b c) (c a) (c d) (e a))))
'((e) (c b a) (d))))
(test-case "10 Graphviz"
(define g (directed-graph '((a b) (b c))))

Loading…
Cancel
Save