protected function computeGraph($syntax)
 {
     $converter = new ASCIISyntax();
     $grid = $converter->convertToGrid($syntax);
     $distance = new Distances\Euclidean();
     $algorithmShortestDistance = new Algorithms\ShortestDistance\Dijkstra($distance);
     $algorithmShortestDistance->setGrid($grid);
     $matrix = $converter->convertToMatrix($syntax);
     $nodes = $converter->findAndCreateNodes($matrix, 'o');
     $graph = new NodeGraph($nodes);
     if (count($nodes) < 2) {
         return $graph;
     }
     $pairs = new Pairs($nodes);
     foreach ($pairs as $pair) {
         list($source, $target) = $pair;
         $length = $algorithmShortestDistance->computeLength($source, $target);
         $graph->createEdgeBetween($source, $target, $length);
     }
     return $graph;
 }
Esempio n. 2
0
 /**
  * @dataProvider providerExemples
  */
 public function testConvertToSyntax($expectedSyntax, NodeGrid $grid)
 {
     $converter = new ASCIISyntax();
     $syntax = $converter->convertToSyntax($grid);
     $this->assertSame($expectedSyntax, $syntax);
 }
 protected function parseGrid($syntax)
 {
     $converter = new ASCIISyntax();
     return $converter->convertToGrid($syntax);
 }