This is a pathfinding algorithm that calculates the shortest (i.e., the cheapest) paths for a set of edges through a GraphPartition.
Remarks
It is based on an A*-algorithm and uses PartitionCells as steps between source node and target node.
In each step, the algorithm takes a CellEntrance, that consists mainly of a PartitionCell and from where it was entered, from a queue with all seen CellEntrances, determines all possible neighbor cells and their enter intervals and enqueues the resulting CellEntrance. To influence the order in which the CellEntrances will be processed, the path search assigns real costs (like Dijkstra) as well as heuristic costs (A*-algorithm's heuristic) to the enqueued CellEntrances. The real costs arise from entering a neighbor cell, e.g., a bend has to be created, while the heuristic costs are an estimation of how expensive it will be to reach the target node continuing the path with this neighboring cell. Therefore, the path search prefers searching in the direction in which the target node lies. The CellEntrance with the lowest combined costs is processed next until the target cell is reached.
PathSearchExtensions modify the path search as they are able to add start entrances and weight them with costs. They also add real and heuristic costs to CellEntrances that are created for the currently entered PartitionCell and calculate shorter enter intervals that are less expensive to pass.
The algorithm gets a PathSearchContext which provides information about the graph and the currently routed edge. It stores the results of the path search that can then be retrieved calling pathSearchResult.
Type Details
- yfiles module
- router-polyline
- yfiles-umd modules
- layout-area, layout-multipage, layout-orthogonal-compact, layout, router-bus, router-polyline
- Legacy UMD name
- yfiles.router.PathSearch
See Also
Constructors
Creates a new instance of PathSearch.
Methods
Adds a new interval calculator to the list of registered IEnterIntervalCalculators.
Remarks
Parameters
A map of options to pass to the method.
- enterIntervalCalculator - IEnterIntervalCalculator
- the calculator to add
Returns
- ↪boolean
true
if the calculator was successfully added,false
otherwise
Adds the given extension to the list of PathSearchExtensions.
Remarks
Parameters
A map of options to pass to the method.
- extension - PathSearchExtension
- the extension to add to this path search
Returns
- ↪boolean
true
if the extension has been added,false
otherwise
calculateCosts
(currentEntrance: CellEntrance, enteredCell: PartitionCell, enterIntervals: OrthogonalInterval[], lastEdgeCellInfos: EdgeCellInfo[], context: PathSearchContext, costs: number[], maxAllowedCosts: number[])Calculates the costs for moving from the current CellEntrance to the neighboring PartitionCell using different enter intervals.
Remarks
It is called by handleNeighbor to determine the costs for all CellEntrances that it will create and enqueue afterwards.
The costs for the given enter intervals are retrieved from all registered PathSearchExtensions. The calculation stops when it reaches the given maximum cost value.
Parameters
A map of options to pass to the method.
- currentEntrance - CellEntrance
- the current cell entrance
- enteredCell - PartitionCell
- the partition cell to enter
- enterIntervals - OrthogonalInterval[]
- the different entering intervals of the entered cell
- lastEdgeCellInfos - EdgeCellInfo[]
- the information about how the last cell was crossed
- context - PathSearchContext
- the context information
- costs - number[]
- the array in which the calculated costs for entering the neighbor cell via the according enter intervals shall be written
- maxAllowedCosts - number[]
- the maximum costs an enter interval may induce. If this cost is exceeded, no further additional costs for this interval are calculated. Note that the entries in this array get modified during cost calculation
See Also
Returns the estimated costs for the rest of the path when using the given CellEntrance for the next step in the path search.
Remarks
It is called by handleNeighbor to determine the heuristic part of the costs with which the entrance will be enqueued.
The heuristic costs for the given entrance are retrieved from all registered PathSearchExtensions.
Parameters
A map of options to pass to the method.
- entrance - CellEntrance
- the current entrance
- context - PathSearchContext
- the context information
Returns
- ↪number
- the heuristic costs for the rest of the path if the given entrance is used
See Also
Resets all registered PathSearchExtensions and DataProviders added to this PathSearch.
decreasePenaltySettings
(penaltySettings: PenaltySettings, decreaseFactor: number, context: PathSearchContext)Decreases the given penalty settings for the current edge.
Remarks
If finding a path for the current edge takes too long according to the maximum duration of the edge routing algorithm, the path search for the current edge is canceled and restarted using decreased penalties. The decreaseFactor
indicates, how much the penalties shall be reduced.
This method is called by findPathsForCurrentEdge. If overriding this method, note that the penalty for creating bends should not be reduced as this results in more possible turns of the edge path and, therefore, a longer runtime of the path search. Furthermore, not all penalties should be decreased equally as these decreases would neutralize each other.
The decreaseFactor
takes values from [0,1]
, where 0
means no reduction while 1
means the strongest reduction.
Parameters
A map of options to pass to the method.
- penaltySettings - PenaltySettings
- the penalty settings whose penalties shall be reduced
- decreaseFactor - number
- the factor with values between
0
and1
that indicates how strong to reduce the penalties - context - PathSearchContext
- the context information of the current path search
Informs all registered path search extensions about completing a path by calling their finalizePath(Path) method.
Remarks
That way, extensions can collect data about this path to use it later during path search.
This method is called by findPathsForCurrentEdge and may be overridden to use a custom finalization step.
Parameters
A map of options to pass to the method.
- path - EdgeRouterPath
- the path to finalize
Finds paths for the edges in the given context and stores them in its PathSearchResult.
Remarks
This is the main method of PathSearch.
It initializes its extensions using initializeEdges and delegates the path search for each edge to findPathsForCurrentEdge.
The path calculations for all edges are finalized by calling the extensions' finalizeEdges method and, after that, the path search result is filled with the path for each edge.
At last, the extensions are asked to finalize the path search result using their finalizePathSearchResult callback.
Parameters
A map of options to pass to the method.
- context - PathSearchContext
- the context to use during the path search
See Also
Finds the path for the current edge in the given context.
Remarks
This method:
- Calls initializeCurrentEdge for all extensions.
- Collects and enqueues all start entrances.
- Iteratively processes the next cheapest cell entrance and
- adds a path result after a finalizePath call if it is a valid target entrance and/or
- calls handleNeighbor for all neighbor cells of the entered cell.
- Calls finalizeCurrentEdge for all extensions.
It is called by findPaths and may be overridden to skip certain edges or implement a custom path search.
Parameters
A map of options to pass to the method.
- context - PathSearchContext
- the context information needed for finding a path
Returns the path for the given edge if it has already been finalized.
Remarks
Parameters
A map of options to pass to the method.
- edge - Edge
- the edge for which the path is returned
Returns
- ↪EdgeRouterPath
- the finalized path for the given edge or
null
if no path has been found and finalized
handleNeighbor
(currentEntrance: CellEntrance, neighborCell: PartitionCell, context: PathSearchContext)Adds CellEntrances for every interval through which the neighboring cell can be entered from the current entrance to the queue.
Remarks
The algorithm calls this method in every step for each neighbor of the current cell to collect all next possible entrances for the current path. This path consists of several entrances where each knows the entrance through which it has been entered.
After calculating all possible enter intervals to the given neighboring cell, each interval gets rated with costs. If there is already an entrance for the neighboring cell whose interval is the same with one of these intervals, this entrance will be used and re-enqueued, so that the path search can still reach it. The current entrance is set as its predecessor within the current path and its enter interval and costs will be updated.
If there is an entrance for the neighboring cell whose interval is intersected by a current interval, new entrances will be created with the new enter intervals and enqueued. The same happens if there is no entrance that has been matched with one of the current intervals, yet. Costs will be added. If there are some entries afterwards that are intersected by the current interval and have higher costs, they will be removed from the queue.
This method is called during cost calculation. It may be overridden to change the interval handling for the CellEntrances.
Parameters
A map of options to pass to the method.
- currentEntrance - CellEntrance
- the current cell entrance
- neighborCell - PartitionCell
- the neighboring cell that is handled.
- context - PathSearchContext
- the context information
See Also
Initializes the fields of this PathSearch.
Remarks
Parameters
A map of options to pass to the method.
- configuration - PathSearchConfiguration
- the configuration that the path search shall use
removeAdditionalEnterIntervalCalculator
(enterIntervalCalculator: IEnterIntervalCalculator) : booleanRemoves the given interval calculator from the list of registered IEnterIntervalCalculators.
Parameters
A map of options to pass to the method.
- enterIntervalCalculator - IEnterIntervalCalculator
- the calculator to remove
Returns
- ↪boolean
true
if an interval calculator was removed as a result of this call,false
if the given calculator was not part of the list
Removes the given extension from the list of PathSearchExtensions.
Parameters
A map of options to pass to the method.
- extension - PathSearchExtension
- the extension to remove from the path search
Returns
- ↪boolean
true
if an extension was removed as a result of this call,false
if the given extension was not contained in the list