Class AStarCheapestOption
Burst compatible methods to find the cheapest path between a starting node and a set of possible targets.
Namespace: AnyPath.Native
Assembly: AnyPath.dll
Syntax
public static class AStarCheapestOption
Remarks
All of the methods contained in the AnyPath.Native namespace are compatible with Unity's Burst compiler
Methods
EvalCheapestTarget<TGraph, TNode, TH, TMod>(ref AStar<TNode>, ref TGraph, NativeSlice<TNode>, NativeSlice<OffsetInfo>, ref TH, ref TMod)
Similar to FindCheapestOption but only returns the index of the option that was the cheapest.
Declaration
public static AStarEvalOptionResult EvalCheapestTarget<TGraph, TNode, TH, TMod>(this ref AStar<TNode> aStar, ref TGraph graph, NativeSlice<TNode> nodes, NativeSlice<OffsetInfo> offsets, ref TH heuristicProvider, ref TMod edgeMod) where TGraph : struct, IGraph<TNode> where TNode : unmanaged, IEquatable<TNode> where TH : struct, IHeuristicProvider<TNode> where TMod : struct, IEdgeMod<TNode>
Parameters
| Type | Name | Description |
|---|---|---|
| AStar<TNode> | aStar | |
| TGraph | graph | |
| NativeSlice<TNode> | nodes | |
| NativeSlice<OffsetInfo> | offsets | |
| TH | heuristicProvider | |
| TMod | edgeMod |
Returns
| Type | Description |
|---|---|
| AStarEvalOptionResult |
Type Parameters
| Name | Description |
|---|---|
| TGraph | |
| TNode | |
| TH | |
| TMod |
FindCheapestOption<TGraph, TNode, TH, TMod, TProc, TSeg>(ref AStar<TNode>, ref TGraph, NativeSlice<TNode>, NativeSlice<OffsetInfo>, TH, TMod, NativeList<TSeg>, NativeList<TSeg>, TProc, NativeList<TSeg>)
Finds the path of the "cheapest" option that is encountered that has a valid path. This method works by comparing the heuristic value for an option against the cost of the currently known cheapest option. If that heuristic value is larger than the cost of the current cheapest path, that option is discarded before trying to find a path. Because of this, it might pay off to pre-sort the options provided by their start to goal heuristic value, lowering the chance of succcesive options being evaluated. This method does not pre-sort automatically though.
Declaration
public static AStarFindOptionResult FindCheapestOption<TGraph, TNode, TH, TMod, TProc, TSeg>(this ref AStar<TNode> aStar, ref TGraph graph, NativeSlice<TNode> nodes, NativeSlice<OffsetInfo> offsets, TH heuristicProvider, TMod edgeMod, NativeList<TSeg> tempBuffer1, NativeList<TSeg> tempBuffer2, TProc pathProcessor, NativeList<TSeg> pathBuffer) where TGraph : struct, IGraph<TNode> where TNode : unmanaged, IEquatable<TNode> where TH : struct, IHeuristicProvider<TNode> where TMod : struct, IEdgeMod<TNode> where TProc : struct, IPathProcessor<TNode, TSeg> where TSeg : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| AStar<TNode> | aStar | The memory container for the algorithm to use |
| TGraph | graph | The graph to perform the request on |
| NativeSlice<TNode> | nodes | A flattened representation of all the stops to visit in order, per option |
| NativeSlice<OffsetInfo> | offsets | Describes the mapping of stops from the nodes array per option using a starting index and length. For example, if you have two options that both only have a start and goal stop, this would look as follows: offets[0] = { start: 0, length: 2 } offsets[1] = { start: 2 : length 2 } |
| TH | heuristicProvider | |
| TMod | edgeMod | |
| NativeList<TSeg> | tempBuffer1 | A temporary buffer to an intermediate path in |
| NativeList<TSeg> | tempBuffer2 | Another temporary buffer to store an intermediate path |
| TProc | pathProcessor | Path processor to use |
| NativeList<TSeg> | pathBuffer | The edge buffer to append the path to |
Returns
| Type | Description |
|---|---|
| AStarFindOptionResult | A AStarFindOptionResult struct indicating if a path was found and the offsets in the path buffer |
Type Parameters
| Name | Description |
|---|---|
| TGraph | The type of graph to find a path on |
| TNode | Type of nodes |
| TH | |
| TMod | |
| TProc | Type of the path processor |
| TSeg | Type of segments make up the path |
Remarks
The temporary buffers are neccessary for the algorithm but won't contain a meaningful value afterwards. You can preallocate these and reuse them for each call. The temporary buffers are cleared before usage in this method.
GetTotalHeuristic<TNode, TH>(ref TH, NativeSlice<TNode>)
Calculates the heuristic for a series of stops. E.g. h(stops[0], stops[1]) + h(stops[1], stops[2]) + ...
Declaration
public static float GetTotalHeuristic<TNode, TH>(ref TH provider, NativeSlice<TNode> stops) where TNode : unmanaged, IEquatable<TNode> where TH : struct, IHeuristicProvider<TNode>
Parameters
| Type | Name | Description |
|---|---|---|
| TH | provider | The graph that provides the heuristic function |
| NativeSlice<TNode> | stops | The stops to calculate a combined heurisic value for |
Returns
| Type | Description |
|---|---|
| float | Heurstic for a series of stops |
Type Parameters
| Name | Description |
|---|---|
| TNode | Type of nodes |
| TH |