Пример #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);
         }
     }
 }
Пример #2
0
 /**
  * Connects the vertex to another $vertex.
  * A $distance, to balance the connection, can be specified.
  *
  * @param Vertex $vertex
  * @param integer $distance
  */
 public function connect(VertexInterface $vertex, $distance = 1)
 {
     $this->connections[$vertex->getId()] = $distance;
 }