Class Graph
getCost(Long, Long) or cached entries in pathCost).
Methods that require a tour id will throw IllegalArgumentException
when the id is not present in the tour map.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRun a weighted A* search fromstartIdtoendIdusing this Graph's adjacency and cost information.getAssociatedPoI(Long id) Return the associated PoI id for a pickup/delivery node.Find the first warehouse id in the tour.Return the direct edge cost fromitojstored in this Graph instance.intReturn the number of nodes held by this graph.getNeighbors(Long i) Return the outgoing neighbors for nodeiin this Graph.getPathCost(Long i, Long j) Return the cached cost of the optimal path betweeniandjin this Graph instance.Retrieve all the Pickup PoI in the tourgetTour()getTypePoI(Long id) Return the PoI type for the given id.booleanLightweight test whether two tour ids can form an edge.
-
Constructor Details
-
Graph
Create a Graph instance.- Parameters:
nodes- map of node id ->Node; must not be nulledges- list of graph edges; must not be nulltour- list of point-of-interest; must not be null All parameters are stored by reference. Null parameters will cause aNullPointerExceptionduring construction.
-
-
Method Details
-
getTypePoI
Return the PoI type for the given id.- Parameters:
id- id of the PoI- Returns:
- the PoI enum type
- Throws:
IllegalArgumentException- if the id is not present in the tour map
-
getAssociatedPoI
Return the associated PoI id for a pickup/delivery node.- Parameters:
id- PoI id- Returns:
- associated PoI id, or null when the PoI is a warehouse or id is unknown
-
getBeginId
Find the first warehouse id in the tour.- Returns:
- a warehouse id if present; otherwise null
-
getPickupPoIs
Retrieve all the Pickup PoI in the tour- Returns:
- a list of Pickup PoI
-
getNbNodes
public int getNbNodes()Return the number of nodes held by this graph.- Returns:
- the number of entries in
all_nodes - Throws:
NullPointerException- ifall_nodesis null
-
getCost
Return the direct edge cost fromitojstored in this Graph instance.This method looks up the cost in the internal cost table built from the edges that were provided when this Graph was created. The graph instance represents the full graph loaded into memory for this run, but it may be incomplete or sparse (not every pair of nodes has a direct edge).
- Parameters:
i- origin node idj- destination node id- Returns:
- the cost as a
Floatwhen a direct edge (i,j) is present in this graph; otherwisenullwhen no direct edge is recorded - Throws:
NullPointerException- wheni,jor internal maps are null
-
isEdge
Lightweight test whether two tour ids can form an edge.This checks only that both ids exist in the
tourmap and that they are not equal. It does not consult the stored cost table; therefore atrueresult does not guarantee that a direct edge (with a cost) is recorded in this Graph. UsegetCost(java.lang.Long, java.lang.Long)orgetAllCosts()to check for an actual stored edge.- Parameters:
i- first idj- second id- Returns:
truewhen both ids are present in the tour and differ; otherwisefalse
-
getPathCost
Return the cached cost of the optimal path betweeniandjin this Graph instance.If the cost is not cached this method triggers
AWAStar(Long, Long)which computes an optimal path using the internal adjacency and cost tables belonging to this Graph object. If no path exists (according to the graph loaded in this object) the method throwsIllegalArgumentException.- Parameters:
i- origin idj- destination id- Returns:
- the Float cost of the optimal path
- Throws:
IllegalArgumentException- when AWAStar determines there is no pathNullPointerException- when parameters or internal maps are null
-
getNeighbors
Return the outgoing neighbors for nodeiin this Graph.- Parameters:
i- node id- Returns:
- a non-null Set of neighbor ids; empty when no neighbors are present Note: the returned set is the actual set stored in the adjacency map and modifying it will change this Graph's adjacency. Treat it as read-only.
-
AWAStar
Run a weighted A* search fromstartIdtoendIdusing this Graph's adjacency and cost information.This method updates
pathCostfor the (startId,endId) pair with the computed Float cost when a path is found, or withnullwhen no path exists. The returned map maps each reachable node id to its predecessor id and can be used to reconstruct the path.- Parameters:
startId- start node idendId- end node id- Returns:
- a predecessor map (node -> predecessor) for reachable nodes, or
nullwhen startId equals endId or the search early-exits because a node has no neighbors
-
getAllEdges
- Returns:
- list of all edges (may be null if not set)
-
getAllNodes
- Returns:
- map of node id -> Node (may be null if not set)
-
getAllCosts
- Returns:
- map of direct edge costs (pair -> cost); entries absent when no direct edge
-
getTour
- Returns:
- tour map of PoIs (id -> PointOfInterest)
-
getPathCostMap
- Returns:
- cached path costs computed by AWAStar
-
getAdjacency
- Returns:
- adjacency map (id -> set of neighbor ids)
-