예제 #1
0
 public function testNegativeComponents()
 {
     // 1 -- 2     3 --[-1]--> 4
     //            ^           |
     //            \---[-2]----/
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $v2 = $graph->createVertex(2);
     $v3 = $graph->createVertex(3);
     $v4 = $graph->createVertex(4);
     $e1 = $v1->createEdge($v2);
     $e2 = $v3->createEdgeTo($v4)->setWeight(-1);
     $e3 = $v4->createEdgeTo($v3)->setWeight(-2);
     $alg = new DetectNegativeCycle($graph);
     $this->assertTrue($alg->hasCycleNegative());
     $cycle = $alg->getCycleNegative();
     $this->assertCount(2, $cycle->getEdges());
     $this->assertCount(3, $cycle->getVertices());
     $this->assertTrue($cycle->getVertices()->hasVertexId(3));
     $this->assertTrue($cycle->getVertices()->hasVertexId(4));
 }