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();
// Get loop through the current node's nearest connections
// to calculate their potentials.
foreach ($sorted as $id) {
$vertex = $this->getGraph()->getVertex($id);
if (!$vertex->isPassed()) {
$this->calculatePotentials($vertex);
}
}
}