Beispiel #1
0
 /**
  * get (first) best circle connecting all vertices
  *
  * @return Walk
  * @uses AlgorithmTsp::getEdges()
  * @uses AlgorithmTsp::getVertexStart()
  * @uses Walk::factoryCycleFromEdges()
  */
 public function getCycle()
 {
     return Walk::factoryCycleFromEdges($this->getEdges(), $this->getVertexStart());
 }
Beispiel #2
0
 public function testLoopCycle()
 {
     // 1 --\
     // ^   |
     // \---/
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $e1 = $v1->createEdgeTo($v1);
     $cycle = Walk::factoryCycleFromEdges(array($e1), $v1);
     $this->assertGraphEquals($graph, $cycle->createGraph());
     $cycle = Walk::factoryCycleFromPredecessorMap(array(1 => $v1), $v1);
     $this->assertGraphEquals($graph, $cycle->createGraph());
     $cycle = Walk::factoryCycleFromVertices(array($v1, $v1));
     $this->assertGraphEquals($graph, $cycle->createGraph());
     $this->assertCount(2, $cycle->getVertices());
     $this->assertCount(1, $cycle->getEdges());
     $this->assertSame($v1, $cycle->getVertices()->getVertexFirst());
     $this->assertSame($v1, $cycle->getVertices()->getVertexLast());
     $this->assertTrue($cycle->isValid());
     return $v1;
 }