From a544407f688d33e02a04ff4d0f5bab06a27133eb Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 7 Nov 2021 21:54:54 +0100 Subject: [PATCH] Add bipartite?. --- graph.rkt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/graph.rkt b/graph.rkt index a4b990a..adbd752 100644 --- a/graph.rkt +++ b/graph.rkt @@ -45,7 +45,7 @@ coloring coloring/greedy coloring/brelaz order-smallest-last valid-coloring? - maxflow + maxflow bipartite? graphviz) @@ -233,6 +233,8 @@ ;; 9 Maximum Flow (define (maxflow g source sink) (g:maxflow (gg g) source sink)) + (define (bipartite? g) + (g:bipartite? (gg g))) ;; 10 Graphviz (define (graphviz g #:output [output #f] #:colors [colors #f]) @@ -353,6 +355,7 @@ ;; 9 Maximum Flow [maxflow (-> Graph Any Any (HashTable (List Any Any) Number))] + [bipartite? (-> Graph (U (List (Listof Any) (Listof Any)) False))] ;; 10 Graphviz [graphviz (->* (Graph) @@ -577,7 +580,11 @@ (test-case "9 Maximum Flow" (define g0 (weighted-graph/directed '((1 a b) (2 a c) (3 b d) (3 c d)))) (check-equal? (hash->ordered-list (maxflow g0 'a 'd)) - '(((a b) . 1) ((c d) . 2) ((b d) . 1) ((a c) . 2)))) + '(((a b) . 1) ((c d) . 2) ((b d) . 1) ((a c) . 2))) + + (define g1 (directed-graph '((a b) (c b)))) + (check-false (bipartite? g0)) + (check-equal? (bipartite? g1) '((b) (a c)))) (test-case "10 Graphviz" (define g (directed-graph '((a b) (b c))))