Example #1
0
 /**
    Рекурсивно вычисляет потенциалы  графа
 *
 * @param VertexInterface $vertex
 */
 protected function calculatePotentials(VertexInterface $vertex)
 {
     $connections = $vertex->getConnections();
     $sorted = array_flip($connections);
     krsort($sorted);
     foreach ($connections as $id => $distance) {
         $v = $this->getGraph()->getVertex($id);
         $v->setPotential($vertex->getPotential() + $distance, $vertex);
         foreach ($this->getPaths() as $path) {
             $count = count($path);
             if ($path[$count - 1]->getId() === $vertex->getId()) {
                 $this->paths[] = array_merge($path, array($v));
             }
         }
     }
     $vertex->markPassed();
     foreach ($sorted as $id) {
         $vertex = $this->getGraph()->getVertex($id);
         if (!$vertex->isPassed()) {
             $this->calculatePotentials($vertex);
         }
     }
 }