Skip to content

Commit f34b5bf

Browse files
committed
Additional test cases and improved documentation
1 parent 919da02 commit f34b5bf

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/MaxFlow/EdmondsKarpTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ class EdmondsKarpTest extends PHPUnit_Framework_TestCase
1010
{
1111
public function testEdgeDirected()
1212
{
13+
// 0 -[0/10]-> 1
1314
$graph = new Graph();
1415
$v0 = $graph->createVertex(0);
1516
$v1 = $graph->createVertex(1);
1617

1718
$v0->createEdgeTo($v1)->setCapacity(10);
1819

20+
// 0 -[10/10]-> 1
1921
$alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1);
2022

2123
$this->assertEquals(10, $alg->getFlowMax());
2224
}
2325

2426
public function testEdgesMultiplePaths()
2527
{
28+
// 0 -[0/5]---------> 1
29+
// | ^
30+
// | |
31+
// \-[0/7]-> 2 -[0/9]-/
2632
$graph = new Graph();
2733
$v0 = $graph->createVertex(0);
2834
$v1 = $graph->createVertex(1);
@@ -32,11 +38,65 @@ public function testEdgesMultiplePaths()
3238
$v0->createEdgeTo($v2)->setCapacity(7);
3339
$v2->createEdgeTo($v1)->setCapacity(9);
3440

41+
// 0 -[5/5]---------> 1
42+
// | ^
43+
// | |
44+
// \-[7/7]-> 2 -[7/9]-/
3545
$alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1);
3646

3747
$this->assertEquals(12, $alg->getFlowMax());
3848
}
3949

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+
40100
// public function testEdgesParallel(){
41101
// $graph = new Graph();
42102
// $v0 = $graph->createVertex(0);
@@ -55,12 +115,14 @@ public function testEdgesMultiplePaths()
55115
*/
56116
public function testEdgesUndirected()
57117
{
118+
// 0 -[0/7]- 1
58119
$graph = new Graph();
59120
$v0 = $graph->createVertex(0);
60121
$v1 = $graph->createVertex(1);
61122

62123
$v1->createEdge($v0)->setCapacity(7);
63124

125+
// 0 -[7/7]- 1
64126
$alg = new AlgorithmMaxFlowEdmondsKarp($v0, $v1);
65127

66128
$this->assertEquals(7, $alg->getFlowMax());

0 commit comments

Comments
 (0)