Package pfvisualizer.algorithms
Class Dijkstra
- java.lang.Object
-
- pfvisualizer.algorithms.Dijkstra
-
- All Implemented Interfaces:
Pathfinder
- Direct Known Subclasses:
AStar
public class Dijkstra extends java.lang.Object implements Pathfinder
Dijkstra's algorithm.
-
-
Field Summary
Fields Modifier and Type Field Description protected int[][]directionsprotected Nodeendprotected int[][]gridprotected intheightprotected int[][]mapprotected intwidth-
Fields inherited from interface pfvisualizer.algorithms.Pathfinder
CHECKED, DIAGONAL_DISTANCE, PATH, STRAIGHT_DISTANCE, UNVISITED, VISITED, WALL
-
-
Constructor Summary
Constructors Constructor Description Dijkstra()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected floatgetDistanceBetween(Node first, Node second)Calculates the distance between two nodes.protected Node[]getSuccessors(Node node)Returns a list of nodes that can be moved into from the given parent node.protected floatheuristic(Node node, Node end)Calculates the heuristic value which is an estimated distance between the given node and the end node.protected booleanisBlocked(int row, int col)Checks if the given node is blocked (i.e wall).Resultsearch(int[][] grid, int startCol, int startRow, int endCol, int endRow)Performs a search for a path from given starting coordinates to the given end coordinates on the given grid.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface pfvisualizer.algorithms.Pathfinder
buildPath
-
-
-
-
Field Detail
-
height
protected int height
-
width
protected int width
-
end
protected Node end
-
grid
protected int[][] grid
-
map
protected int[][] map
-
directions
protected int[][] directions
-
-
Method Detail
-
heuristic
protected float heuristic(Node node, Node end)
Calculates the heuristic value which is an estimated distance between the given node and the end node.- Parameters:
node- start nodeend- end node- Returns:
- the heuristic value
-
search
public Result search(int[][] grid, int startCol, int startRow, int endCol, int endRow)
Description copied from interface:PathfinderPerforms a search for a path from given starting coordinates to the given end coordinates on the given grid.- Specified by:
searchin interfacePathfinder- Parameters:
grid- map to perform the search onstartCol- start columnstartRow- start rowendCol- end columnendRow- end row- Returns:
- Result object which contains information such as the length of the optimal path
-
getDistanceBetween
protected float getDistanceBetween(Node first, Node second)
Calculates the distance between two nodes.- Parameters:
first- first nodesecond- second node- Returns:
- distance between the given nodes
-
getSuccessors
protected Node[] getSuccessors(Node node)
Returns a list of nodes that can be moved into from the given parent node.- Parameters:
node- the parent node- Returns:
- list of nodes that can be moved into from the parent node
-
isBlocked
protected boolean isBlocked(int row, int col)Checks if the given node is blocked (i.e wall).- Parameters:
row- row coordinate of the nodecol- column coordinate of the node- Returns:
- a boolean representing whether the node is blocked or not
-
-