Add maxflow.

This commit is contained in:
Sergiu Ivanov 2021-11-07 21:49:32 +01:00
parent 80831c3b7c
commit 22a5720da0
1 changed files with 14 additions and 0 deletions

View File

@ -45,6 +45,8 @@
coloring coloring/greedy coloring/brelaz
order-smallest-last valid-coloring?
maxflow
graphviz)
;; Wrap the opaque graph structure coming from the generic
@ -228,6 +230,10 @@
(define (valid-coloring? g coloring)
(g:valid-coloring? (gg g) coloring))
;; 9 Maximum Flow
(define (maxflow g source sink)
(g:maxflow (gg g) source sink))
;; 10 Graphviz
(define (graphviz g #:output [output #f] #:colors [colors #f])
(g:graphviz (gg g) #:output output #:colors colors)))
@ -345,6 +351,9 @@
[order-smallest-last (-> Graph (Listof Any))]
[valid-coloring? (-> Graph (HashTable Any Number) Boolean)]
;; 9 Maximum Flow
[maxflow (-> Graph Any Any (HashTable (List Any Any) Number))]
;; 10 Graphviz
[graphviz (->* (Graph)
(#:output Output-Port
@ -565,6 +574,11 @@
(check-true (valid-coloring? g0 #hash((a . 0) (b . 1) (c . 0) (d . 2)))))
(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))))
(test-case "10 Graphviz"
(define g (directed-graph '((a b) (b c))))
(check-equal? (graphviz g)