\GraphDS\AlgoDijkstra

Class defining Dijkstra's shortest path algorithm.

Summary

Methods
Properties
Constants
__construct()
run()
get()
$graph
$dist
$prev
$unvisitedVertices
$start
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$dist

$dist : array

Array holding the shortest distances to each vertex from the source.

Type

array

$prev

$prev : array

Array holding the previous vertices for each vertex for the shortest path.

Type

array

$unvisitedVertices

$unvisitedVertices : array

Array holding the unvisited vertices in the graph.

Type

array

$start

$start : array

ID of the start vertex.

Type

array

Methods

__construct()

__construct(\GraphDS\Graph\Graph  $graph) 

Constructor for the Dijkstra algorithm.

Parameters

\GraphDS\Graph\Graph $graph

The graph to which the Dijkstra algorithm should be applied

Throws

\InvalidArgumentException

run()

run(mixed  $start) : void

Calculates the shortest path to every vertex from vertex $start.

Parameters

mixed $start

ID of the starting vertex for Dijkstra's algorithm

Throws

\InvalidArgumentException

get()

get(string  $dest) : array

Returns the shortest path to $dest from the origin vertex in the graph.

Parameters

string $dest

ID of the destination vertex

Returns

array —

An array containing the shortest path and distance