Skip to content

Commit 7034a99

Browse files
committed
Explicitly fail for undirected edges
1 parent 2522757 commit 7034a99

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/MinimumCostFlow/SuccessiveShortestPath.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function createGraph()
3636
// initial flow of edges
3737
$edges = $resultGraph->getEdges();
3838
foreach ($edges as $edge) {
39+
if (!($edge instanceof EdgeDirected)) {
40+
throw new UnexpectedValueException('Undirected edges are not supported for SuccessiveShortestPath');
41+
}
42+
3943
// 0 if weight of edge is positive
4044
$flow = 0;
4145

tests/MinimumCostFlow/BaseMcfTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,19 @@ public function testUndirectedFails()
163163
$alg = $this->createAlgorithm($graph);
164164
$alg->getWeightFlow();
165165
}
166+
167+
/**
168+
* @expectedException UnexpectedValueException
169+
*/
170+
public function testUndirectedNegativeCycleFails()
171+
{
172+
// 1(+2) -[0/2/-1]- 2(-2)
173+
$graph = new Graph();
174+
$v1 = $graph->createVertex(1)->setBalance(2);
175+
$v2 = $graph->createVertex(2)->setBalance(-2);
176+
$v1->createEdge($v2)->setCapacity(2)->setWeight(-1);
177+
178+
$alg = $this->createAlgorithm($graph);
179+
$alg->getWeightFlow();
180+
}
166181
}

0 commit comments

Comments
 (0)