class Dijkstra implements AlgorithmInterface (View source)

Properties

protected $startingVertex
protected $endingVertex
protected $graph
protected $paths
protected $solution

Methods

__construct(GraphInterface $graph)

Instantiates a new algorithm, requiring a graph to work with.

integer
getDistance()

Returns the distance between the starting and the ending point.

getEndingVertex()

Gets the vertex which we are pointing to.

string
getLiteralShortestPath()

Returns the solution in a human-readable style.

Array
getShortestPath()

Reverse-calculates the shortest path of the graph thanks the potentials stored in the vertices.

getStartingVertex()

Retrieves the vertex which we are starting from to calculate the shortest path.

setEndingVertex(VertexInterface $vertex)

Sets the vertex which we are pointing to.

setStartingVertex(VertexInterface $vertex)

Sets the vertex which we are starting from to calculate the shortest path.

mixed
solve()

Solves the algorithm and returns all possible results.

calculatePotentials(VertexInterface $vertex)

Recursively calculates the potentials of the graph, from the starting point you specify with ->setStartingVertex(), traversing the graph due to Vertex's $connections attribute.

getGraph()

Returns the graph associated with this algorithm instance.

Array
getPaths()

Returns the possible paths registered in the graph.

boolean
isSolved()

Checks wheter the current algorithm has been solved or not.

Details

__construct(GraphInterface $graph)

Instantiates a new algorithm, requiring a graph to work with.

Parameters

GraphInterface $graph

integer getDistance()

Returns the distance between the starting and the ending point.

Return Value

integer

VertexInterface getEndingVertex()

Gets the vertex which we are pointing to.

Return Value

VertexInterface

string getLiteralShortestPath()

Returns the solution in a human-readable style.

Return Value

string

Array getShortestPath()

Reverse-calculates the shortest path of the graph thanks the potentials stored in the vertices.

Return Value

Array

VertexInterface getStartingVertex()

Retrieves the vertex which we are starting from to calculate the shortest path.

Return Value

VertexInterface

setEndingVertex(VertexInterface $vertex)

Sets the vertex which we are pointing to.

Parameters

VertexInterface $vertex

setStartingVertex(VertexInterface $vertex)

Sets the vertex which we are starting from to calculate the shortest path.

Parameters

VertexInterface $vertex

mixed solve()

Solves the algorithm and returns all possible results.

Return Value

mixed

protected calculatePotentials(VertexInterface $vertex)

Recursively calculates the potentials of the graph, from the starting point you specify with ->setStartingVertex(), traversing the graph due to Vertex's $connections attribute.

Parameters

VertexInterface $vertex

protected GraphInterface getGraph()

Returns the graph associated with this algorithm instance.

Return Value

GraphInterface

protected Array getPaths()

Returns the possible paths registered in the graph.

Return Value

Array

protected boolean isSolved()

Checks wheter the current algorithm has been solved or not.

Return Value

boolean