From 40059d1b75dd612a29c517ca5173c293c0cb7458 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 31 Oct 2021 21:50:19 +0100 Subject: [PATCH] Add min-st-kruskal. --- graph.rkt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/graph.rkt b/graph.rkt index 75ac80b..ebb681b 100644 --- a/graph.rkt +++ b/graph.rkt @@ -37,6 +37,8 @@ dfs dfs/generalized dag? tsort cc cc/bfs scc + min-st-kruskal + graphviz) ;; Wrap the opaque graph structure coming from the generic @@ -182,6 +184,10 @@ (define (scc g) (g:scc (gg g))) + ;; 5 Spanning Trees + (define (min-st-kruskal g) + (g:min-st-kruskal (gg g))) + ;; 10 Graphviz (define (graphviz g #:output [output #f] #:colors [colors #f]) (g:graphviz (gg g) #:output output #:colors colors))) @@ -267,6 +273,9 @@ [cc/bfs (-> Graph (Listof (Listof Any)))] [scc (-> Graph (Listof (Listof Any)))] + ;; 5 Spanning Trees + [min-st-kruskal (-> Graph (Listof (List Any Any)))] + ;; 10 Graphviz [graphviz (->* (Graph) (#:output Output-Port @@ -377,6 +386,13 @@ (check-equal? (scc (directed-graph '((a b) (b c) (c a) (c d) (e a)))) '((e) (c b a) (d)))) + ;; 5 Spanning Trees + (test-case "5 Spanning Trees" + (define g0 (weighted-graph/undirected '((1 a b) (2 b c) (3 c a) (4 c d) (5 e a)))) + + (check-equal? (min-st-kruskal g0) + '((a e) (c d) (c b) (a b)))) + (test-case "10 Graphviz" (define g (directed-graph '((a b) (b c)))) (check-equal? (graphviz g)