From f918eca12331d5c96fa76a26fb5688f802834470 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 31 Oct 2021 21:43:28 +0100 Subject: [PATCH] Add scc. --- graph.rkt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/graph.rkt b/graph.rkt index b0b1198..75ac80b 100644 --- a/graph.rkt +++ b/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))))