@@ -10,19 +10,25 @@ class EdmondsKarpTest extends PHPUnit_Framework_TestCase
10
10
{
11
11
public function testEdgeDirected ()
12
12
{
13
+ // 0 -[0/10]-> 1
13
14
$ graph = new Graph ();
14
15
$ v0 = $ graph ->createVertex (0 );
15
16
$ v1 = $ graph ->createVertex (1 );
16
17
17
18
$ v0 ->createEdgeTo ($ v1 )->setCapacity (10 );
18
19
20
+ // 0 -[10/10]-> 1
19
21
$ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v1 );
20
22
21
23
$ this ->assertEquals (10 , $ alg ->getFlowMax ());
22
24
}
23
25
24
26
public function testEdgesMultiplePaths ()
25
27
{
28
+ // 0 -[0/5]---------> 1
29
+ // | ^
30
+ // | |
31
+ // \-[0/7]-> 2 -[0/9]-/
26
32
$ graph = new Graph ();
27
33
$ v0 = $ graph ->createVertex (0 );
28
34
$ v1 = $ graph ->createVertex (1 );
@@ -32,11 +38,65 @@ public function testEdgesMultiplePaths()
32
38
$ v0 ->createEdgeTo ($ v2 )->setCapacity (7 );
33
39
$ v2 ->createEdgeTo ($ v1 )->setCapacity (9 );
34
40
41
+ // 0 -[5/5]---------> 1
42
+ // | ^
43
+ // | |
44
+ // \-[7/7]-> 2 -[7/9]-/
35
45
$ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v1 );
36
46
37
47
$ this ->assertEquals (12 , $ alg ->getFlowMax ());
38
48
}
39
49
50
+ public function testEdgesMultiplePathsTwo ()
51
+ {
52
+ // 0 -[0/5]---------> 1-[0/10]-> 3
53
+ // | ^ |
54
+ // | | |
55
+ // \-[0/7]-> 2 -[0/9]-/ |
56
+ // ^ |
57
+ // \---[0/2]-----------/
58
+ $ graph = new Graph ();
59
+ $ v0 = $ graph ->createVertex (0 );
60
+ $ v1 = $ graph ->createVertex (1 );
61
+ $ v2 = $ graph ->createVertex (2 );
62
+ $ v3 = $ graph ->createVertex (3 );
63
+ $ v4 = $ graph ->createVertex (4 );
64
+ $ v5 = $ graph ->createVertex (5 );
65
+
66
+ $ v0 ->createEdgeTo ($ v1 )->setCapacity (5 );
67
+ $ v0 ->createEdgeTo ($ v2 )->setCapacity (7 );
68
+ $ v2 ->createEdgeTo ($ v1 )->setCapacity (9 );
69
+ $ v1 ->createEdgeTo ($ v3 )->setCapacity (10 );
70
+ $ v3 ->createEdgeTo ($ v2 )->setCapacity (2 );
71
+
72
+ $ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v3 );
73
+
74
+ $ this ->assertEquals (10 , $ alg ->getFlowMax ());
75
+
76
+ $ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v2 );
77
+
78
+ $ this ->assertEquals (9 , $ alg ->getFlowMax ());
79
+ }
80
+
81
+ public function testEdgesMultiplePathsTree ()
82
+ {
83
+ $ graph = new Graph ();
84
+ $ v0 = $ graph ->createVertex (0 );
85
+ $ v1 = $ graph ->createVertex (1 );
86
+ $ v2 = $ graph ->createVertex (2 );
87
+ $ v3 = $ graph ->createVertex (3 );
88
+
89
+ $ v0 ->createEdgeTo ($ v1 )->setCapacity (4 );
90
+ $ v0 ->createEdgeTo ($ v2 )->setCapacity (2 );
91
+ $ v1 ->createEdgeTo ($ v2 )->setCapacity (3 );
92
+ $ v1 ->createEdgeTo ($ v3 )->setCapacity (1 );
93
+ $ v2 ->createEdgeTo ($ v3 )->setCapacity (6 );
94
+
95
+ $ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v3 );
96
+
97
+ $ this ->assertEquals (6 , $ alg ->getFlowMax ());
98
+ }
99
+
40
100
// public function testEdgesParallel(){
41
101
// $graph = new Graph();
42
102
// $v0 = $graph->createVertex(0);
@@ -55,12 +115,14 @@ public function testEdgesMultiplePaths()
55
115
*/
56
116
public function testEdgesUndirected ()
57
117
{
118
+ // 0 -[0/7]- 1
58
119
$ graph = new Graph ();
59
120
$ v0 = $ graph ->createVertex (0 );
60
121
$ v1 = $ graph ->createVertex (1 );
61
122
62
123
$ v1 ->createEdge ($ v0 )->setCapacity (7 );
63
124
125
+ // 0 -[7/7]- 1
64
126
$ alg = new AlgorithmMaxFlowEdmondsKarp ($ v0 , $ v1 );
65
127
66
128
$ this ->assertEquals (7 , $ alg ->getFlowMax ());
0 commit comments