Skip to content

Commit

Permalink
Merge fce7ae0 into 440ee08
Browse files Browse the repository at this point in the history
  • Loading branch information
kenikori committed Mar 1, 2017
2 parents 440ee08 + fce7ae0 commit 4b2d8a5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Dijkstra.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,20 @@ public function shortestPaths($source, $target, array $exclude = array()) {
return $this->extractPaths($target);
}
}

/**
* Calculate path distance.
*
* @param string[] $path The path
*
* @return integer Path distance
*/
public function getPathDistance(array $path) {
$distance = 0;
for ($i = 1; $i < count($path); $i++) {
$distance += $this->graph[$path[$i-1]][$path[$i]];
}

return $distance;
}
}

0 comments on commit 4b2d8a5

Please sign in to comment.