public abstract class PathSearchExtension extends Object
PathSearch
to influence the search process.
An extension contains several callback methods that are used by the PathSearch
to, e.g., calculate the costs for
the next possible steps (i.e., entering the next partition cell) and to decide when the target is reached.
The PathSearch
uses the callbacks in the following order:
initialize(PathSearchConfiguration)
initializeEdges(PathSearchContext)
initializeCurrentEdge(PathSearchContext)
appendStartEntrances(List)
calculateStartEntranceCost(CellEntrance)
calculateCosts(CellEntrance, PartitionCell, OrthogonalInterval, EdgeCellInfo, double)
calculateHeuristicCosts(CellEntrance)
isValidTargetEntrance(CellEntrance)
finalizePath(Path)
finalizeCurrentEdge(PathSearchContext)
or cancelCurrentEdge(PathSearchContext)
finalizeEdges(PathSearchContext)
finalizePathSearchResult(PathSearchResult)
cleanUp()
Constructor and Description |
---|
PathSearchExtension()
Creates a new instance of
PathSearchExtension . |
Modifier and Type | Method and Description |
---|---|
protected void |
appendStartEntrances(List<Object> allStartEntrances)
Appends additional start
entrances for the path search of the current edge to the given list of all
previously generated entrances. |
protected double |
calculateCosts(CellEntrance currentEntrance,
PartitionCell enteredCell,
OrthogonalInterval enterInterval,
EdgeCellInfo edgeCellInfo,
double maxAllowedCosts)
Calculates the costs for entering the given
PartitionCell via the given enter OrthogonalInterval . |
protected double |
calculateHeuristicCosts(CellEntrance entrance)
Calculates the heuristic costs for the given
CellEntrance that describe the minimal costs that will arise to
finish the path if the given cell entrance is used as next step. |
protected double |
calculateStartEntranceCost(CellEntrance startEntrance)
Returns the cost for starting the path in the given entrance.
|
protected void |
cancelCurrentEdge(PathSearchContext context)
Handles the cancellation of the path search for the current edge.
|
protected void |
cleanUp()
Cleans up the extension from the path searches with the current
configuration and
context . |
protected void |
finalizeCurrentEdge(PathSearchContext context)
Handles the completion of the path search for the current edge.
|
protected void |
finalizeEdges(PathSearchContext context)
Handles the completion of all marked edges.
|
protected void |
finalizePath(Path path)
After finding a valid target entrance and creating a
Path , the extension is notified of the found path. |
protected void |
finalizePathSearchResult(PathSearchResult pathSearchResult)
Completes the path search result.
|
protected PathSearchConfiguration |
getConfiguration()
Gets the configuration used for the path search.
|
protected PathSearchContext |
getContext()
Gets the current context of the path search.
|
protected void |
initialize(PathSearchConfiguration configuration)
Initializes this extension for path searches using the given configuration.
|
protected void |
initializeCurrentEdge(PathSearchContext context)
Initializes this extension with the current edge set in the given context.
|
protected void |
initializeEdges(PathSearchContext context)
Initializes this extension with the context that contains the list of edges for which paths are calculated.
|
protected boolean |
isValidTargetEntrance(CellEntrance entrance)
Determines whether or not this extension considers the given
CellEntrance as a valid target entrance, i.e., the
path may end with the given entrance. |
public PathSearchExtension()
PathSearchExtension
.protected void appendStartEntrances(List<Object> allStartEntrances)
entrances
for the path search of the current edge to the given list of all
previously generated entrances.
This method is called before starting the actual path search to determine possible starting points. The current
implementation doesn't add any CellEntrance
s. It may be overridden to add CellEntrance
s with specific
enter intervals, e.g., to consider PortConstraint
s.
allStartEntrances
- a list of all previously generated entrancesprotected double calculateCosts(CellEntrance currentEntrance, PartitionCell enteredCell, OrthogonalInterval enterInterval, EdgeCellInfo edgeCellInfo, double maxAllowedCosts)
PartitionCell
via the given enter OrthogonalInterval
.
The given EdgeCellInfo
describes how the partition cell that has been entered by the current entrance would be
traversed if this enter interval to the neighboring cell would be chosen.
The maxAllowedCosts
describe the maximum costs that entering the neighboring cell via the given enter interval
may induce. If the maximum cost is exceeded, calculations that may further increase its cost may be skipped because this
interval won't be chosen anyway.
This implementation doesn't add any costs. It may be overridden to add costs, e.g., if entering through the given interval would create a bend.
currentEntrance
- the entrance that was used for entering the current cellenteredCell
- the neighboring cell that shall be enteredenterInterval
- the interval that shall be used for entering the neighboring celledgeCellInfo
- the information about how the current cell would be traversed if the neighboring cell would be entered by this enter
intervalmaxAllowedCosts
- the maximum allowed costs for this enter intervalprotected double calculateHeuristicCosts(CellEntrance entrance)
CellEntrance
that describe the minimal costs that will arise to
finish the path if the given cell entrance is used as next step.
After evaluating the costs for each enter interval to a neighboring cell, this method is called for each of the
resulting CellEntrance
s.
This implementation doesn't add any costs. It may be overridden to add some heuristic costs, e.g., if the edge would
have to bend to reach the target node from the given CellEntrance
.
entrance
- the entrance to calculate the heuristic costs for the rest of the pathprotected double calculateStartEntranceCost(CellEntrance startEntrance)
This method is called for each start entrance of the current edge.
The current implementation doesn't add any costs for the given CellEntrance
. It may be overridden to make start
entrances with less specific intervals more expensive. For example, intervals that allow more than just the PortConstraint
location to connect to the source node become more expensive.
startEntrance
- the start entrance for which the cost is calculatedprotected void cancelCurrentEdge(PathSearchContext context)
This callback notifies the extension when the path search for the current edge is canceled. Then, the path search will proceed with altering the penalties of the current edge and reinitializing it again.
This implementation does nothing. It may be overridden to reset some edge specific information, e.g., removing previously added listeners.
context
- the context containing the current edge for which the path search has been canceledinitializeCurrentEdge(PathSearchContext)
,
finalizeEdges(PathSearchContext)
protected void cleanUp()
configuration
and
context
.protected void finalizeCurrentEdge(PathSearchContext context)
This callback notifies the extension when enough paths are found for the current edge. After that, the path search
either proceeds with initializing the next current edge in the context's edge list or calls finalizeEdges(PathSearchContext)
if all edges in this list have been handled.
This implementation does nothing. It may be overridden to add/reset some edge specific information, e.g., removing previously added listeners or adding new start entrances.
context
- the context containing the current edge for which the path search has been finishedinitializeCurrentEdge(PathSearchContext)
,
finalizeEdges(PathSearchContext)
protected void finalizeEdges(PathSearchContext context)
This callback notifies the extension if enough paths have been found for all edges in the context's edge list.
context
- the context containing the list of edges for which paths have been foundPathSearchContext.getEdges()
protected void finalizePath(Path path)
Path
, the extension is notified of the found path.
If the path search is configured to calculate several possible paths for an edge, the path search proceeds with choosing
another unhandled CellEntrance
.
This implementation does nothing. It may be overridden to collect some information about the given path that may influence the path search of later edges.
path
- the path found for the current edge in the contextPathSearchContext.getCurrentEdge()
protected void finalizePathSearchResult(PathSearchResult pathSearchResult)
This callback notifies the extensions of the paths chosen for the edges in the current context. After calling
finalizeEdges
, the PathSearch
decides, which of the found paths to use for each edge and adds them to the PathSearchResult
.
With this callback, the registered extensions are notified of this result before the path search either initializes the
next list of edges to route or ends the path search by calling cleanUp()
. This implementation does nothing.
pathSearchResult
- the path search result for the edge in the current context's edge listinitializeEdges(PathSearchContext)
,
cleanUp()
protected PathSearchConfiguration getConfiguration()
This property is initialized in initialize(PathSearchConfiguration)
.
protected PathSearchContext getContext()
This property is initialized in initializeEdges(PathSearchContext)
.
protected void initialize(PathSearchConfiguration configuration)
This method is the first one to be called by the PathSearch
. It may be
overridden to initialize this extension with necessary settings like GroupingSupport
.
configuration
- the configuration to use for the following path searchesprotected void initializeCurrentEdge(PathSearchContext context)
This method is called for each edge of the context
. Each call will be balanced by a call to either
finalizeCurrentEdge(PathSearchContext)
or cancelCurrentEdge(PathSearchContext)
.
It may be overridden to initialize/reset the settings for the current edge (e.g. minimum distances).
context
- the context containing the current edgePathSearchContext.getCurrentEdge()
protected void initializeEdges(PathSearchContext context)
This method may be called several times during a path search. Each call will be balanced by calls to finalizeEdges(PathSearchContext)
and finalizePathSearchResult(PathSearchResult)
.
It may be overridden to initialize/reset the settings for the routed edges (e.g. minimum distances).
context
- the context containing the list of edges for which paths shall be foundPathSearchContext.getEdges()
protected boolean isValidTargetEntrance(CellEntrance entrance)
CellEntrance
as a valid target entrance, i.e., the
path may end with the given entrance.
Each time a CellEntrance
is chosen as next step, all registered extensions are asked if this entrance is a valid
target entrance. Only if none of the extensions returns false
, a Path
is created.
This implementation accepts all
CellEntrance
s as valid targets. It may be overridden to only activate the target if the route fulfills a
certain condition.
entrance
- the entrance to decide if it is a valid target entrancetrue
if the path may end with this entrance, false
otherwise