-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcirculation_test.go
51 lines (47 loc) · 1.24 KB
/
circulation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package flownet_test
import (
"math/rand"
"testing"
"time"
"github.com/kalexmills/flownet"
)
func TestSanityAllCirculations(t *testing.T) {
rand.Seed(time.Now().UnixNano())
visitAllInstances(t, CircInstances, func(t *testing.T, path string, instance TestInstance) error {
graph := flownet.NewCirculation(instance.numNodes)
for edge, cap := range instance.capacities {
if edge.from == flownet.Source {
graph.SetNodeDemand(edge.to, -10)
}
if edge.to == flownet.Sink {
graph.SetNodeDemand(edge.from, 10)
}
if edge.from < 0 || edge.to < 0 {
continue
}
if cap <= 0 {
continue
}
demand, ok := instance.demands[edge]
if !ok {
demand = 0
}
if err := graph.AddEdge(edge.from, edge.to, cap, demand); err != nil {
t.Error(err)
}
}
graph.PushRelabel()
outflow := graph.Outflow()
if instance.expectedFlow != -1 {
if instance.expectedFlow > outflow {
t.Errorf("expected at least %d units of flow, found %d", instance.expectedFlow, outflow)
}
}
t.Logf("test %s had a flow of %d; satisfied demand? %t", path, outflow, graph.SatisfiesDemand())
if err := flownet.SanityChecks.Circulation(graph); err != nil {
t.Errorf("sanity checks failed: %v", err)
return err
}
return nil
})
}