Package org.goplanit.algorithms.shortest
Class ShortestPathAStar
- java.lang.Object
-
- org.goplanit.algorithms.shortest.ShortestPathAStar
-
- All Implemented Interfaces:
ShortestPathOneToOne
public class ShortestPathAStar extends Object implements ShortestPathOneToOne
A* shortest path algorithm A* shortest path is a one-to-one implementation of the shortest path algorithm based on the generalized costs on each link segment (edge). The costs should be provided upon instantiation and are reused whenever a One-To-One execution conditional on the chosen source node is performed. In its current form, it assumes a macroscopic network and macroscopic link segments to operate on- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
edgeSegmentCosts
The cost for each edge to determine shortest pathsprotected PlanitJtsCrsUtils
geoUtils
CRS based utility class to interpret the position information of verticesprotected double
heuristicDistanceMultiplier
conversion multiplier to convert distance (km) to costprotected int
numberOfEdgeSegments
The number of edge segments consideredprotected int
numberOfVertices
The number of vertices in the networkprotected static Comparator<Pair<DirectedVertex,Double>>
pairSecondComparator
Comparator to sort based on the second elements minimum value (ascending order)
-
Constructor Summary
Constructors Constructor Description ShortestPathAStar(double[] edgeSegmentCosts, int numberOfVertices, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double heuristicDistanceMultiplier)
Constructor for an edge cost based A* algorithm for finding shortest paths.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ShortestPathResult
executeOneToOne(DirectedVertex origin, DirectedVertex destination)
Construct shortest paths from source node to all other nodes in the network based on directed LinkSegment edgesShortestPathResult
executeOneToOne(DirectedVertex origin, DirectedVertex destination, Set<? extends EdgeSegment> bannedSegments)
Construct shortest paths from source node to all other nodes in the network based on directed LinkSegment edges while imposing custom constraints on certain edge segments not being allowed to be used
-
-
-
Field Detail
-
edgeSegmentCosts
protected final double[] edgeSegmentCosts
The cost for each edge to determine shortest paths
-
numberOfEdgeSegments
protected final int numberOfEdgeSegments
The number of edge segments considered
-
numberOfVertices
protected final int numberOfVertices
The number of vertices in the network
-
geoUtils
protected final PlanitJtsCrsUtils geoUtils
CRS based utility class to interpret the position information of vertices
-
heuristicDistanceMultiplier
protected final double heuristicDistanceMultiplier
conversion multiplier to convert distance (km) to cost
-
pairSecondComparator
protected static final Comparator<Pair<DirectedVertex,Double>> pairSecondComparator
Comparator to sort based on the second elements minimum value (ascending order)
-
-
Constructor Detail
-
ShortestPathAStar
public ShortestPathAStar(double[] edgeSegmentCosts, int numberOfVertices, org.opengis.referencing.crs.CoordinateReferenceSystem crs, double heuristicDistanceMultiplier)
Constructor for an edge cost based A* algorithm for finding shortest paths.- Parameters:
edgeSegmentCosts
- Edge segment costsnumberOfVertices
- number of vertices in the networkcrs
- the coordinate reference system used in the network, i.e., we can draw upon the geo information of the vertices to compute our heuristic componentheuristicDistanceMultiplier
- used to convert the distance between two vertices to a cost, in transport context this would generally be the 1/(maximum speed (km/h)), e.g. pace to convert a heuristic distance (km) into travel time (h) since (km* h/km = h).
-
-
Method Detail
-
executeOneToOne
public ShortestPathResult executeOneToOne(DirectedVertex origin, DirectedVertex destination, Set<? extends EdgeSegment> bannedSegments)
Construct shortest paths from source node to all other nodes in the network based on directed LinkSegment edges while imposing custom constraints on certain edge segments not being allowed to be used We create the heuristic costs on-the-fly based on the coordinates of the vertex and computing the as-the-crow-flies lower bound cost. Can only be used when instance was created by providing ${code CRS} and ${codeheuristicDistanceMultiplier} in constructor. Also, all network entities should hold geo positions otherwise the execution will fail with a nullpointer.- Specified by:
executeOneToOne
in interfaceShortestPathOneToOne
- Parameters:
origin
- vertex of source nodedestination
- vertex of sink nodebannedSegments
- segments not allowed to be used- Returns:
- shortest path result of the execution
-
executeOneToOne
public ShortestPathResult executeOneToOne(DirectedVertex origin, DirectedVertex destination)
Description copied from interface:ShortestPathOneToOne
Construct shortest paths from source node to all other nodes in the network based on directed LinkSegment edges- Specified by:
executeOneToOne
in interfaceShortestPathOneToOne
- Parameters:
origin
- vertex of source nodedestination
- vertex of sink node- Returns:
- shortest path result of the execution
-
-