Class DijkstraGraphDistance
Compute Dijkstra shortest-path algorithm on a graph.
Computation is index-based, but can use sparse data
structures if the index space will be sparse.
Construction is somewhat complicated, but see shortcut static
methods at end of file for common construction cases:
- MeshVertices(mesh) - compute on vertices of mesh
- MeshVertices(mesh) - compute on vertices of mesh
Inheritance
DijkstraGraphDistance
Namespace: g3
Assembly: cs.temp.dll.dll
Syntax
public class DijkstraGraphDistance
Constructors
DijkstraGraphDistance(Int32, Boolean, Func<Int32, Boolean>, Func<Int32, Int32, Single>, Func<Int32, IEnumerable<Int32>>, IEnumerable<Vector2d>)
Constructor configures the graph as well. Graph is not specified
explicitly, is provided via functions, for maximum flexibility.
nMaxID: maximum ID that will be added.
bSparse: is ID space large but sparse? this will save memory
nodeFilterF: restrict to a subset of nodes (eg if you want to filter neighbours but not change neighboursF
nodeDistanceF: must return (symmetric) distance between two nodes a and b
neighboursF: return enumeration of neighbours of a
seeds: although Vector2d, are actually pairs (id, seedvalue) (or use AddSeed later)
Declaration
public DijkstraGraphDistance(int nMaxID, bool bSparse, Func<int, bool> nodeFilterF, Func<int, int, float> nodeDistanceF, Func<int, IEnumerable<int>> neighboursF, IEnumerable<Vector2d> seeds = null)
Parameters
Fields
InvalidValue
Declaration
public const float InvalidValue = 3.40282347E+38F
Field Value
TrackOrder
if you enable this, then you can call GetOrder()
Declaration
Field Value
Properties
MaxDistance
Get the maximum distance encountered during the Compute()
Declaration
public float MaxDistance { get; }
Property Value
Methods
AddSeed(Int32, Single)
Add seed point as id/distance pair
Declaration
public void AddSeed(int id, float seed_dist)
Parameters
Compute()
Compute distances from seeds to all other ids.
Declaration
Compute_Dense()
Declaration
protected void Compute_Dense()
Compute_Sparse()
Declaration
protected void Compute_Sparse()
ComputeToMaxDistance(Single)
Compute distances that are less/equal to fMaxDistance from the seeds
Terminates early, so Queue may not be empty
Declaration
public void ComputeToMaxDistance(float fMaxDistance)
Parameters
Type |
Name |
Description |
Single |
fMaxDistance |
|
ComputeToMaxDistance_Dense(Single)
Declaration
protected void ComputeToMaxDistance_Dense(float fMaxDistance)
Parameters
Type |
Name |
Description |
Single |
fMaxDistance |
|
ComputeToMaxDistance_Sparse(Single)
Declaration
protected void ComputeToMaxDistance_Sparse(float fMaxDistance)
Parameters
Type |
Name |
Description |
Single |
fMaxDistance |
|
ComputeToNode(Func<Int32, Boolean>, Single)
Compute distances until node_id is frozen, or (optional) max distance is reached
Terminates early, so Queue may not be empty
Declaration
public int ComputeToNode(Func<int, bool> terminatingNodeF, float fMaxDistance = 3.40282347E+38F)
Parameters
Returns
ComputeToNode(Int32, Single)
Compute distances until node_id is frozen, or (optional) max distance is reached
Terminates early, so Queue may not be empty
[TODO] can reimplement this w/ internal call to ComputeToNode(func) ?
Declaration
public void ComputeToNode(int node_id, float fMaxDistance = 3.40282347E+38F)
Parameters
Type |
Name |
Description |
Int32 |
node_id |
|
Single |
fMaxDistance |
|
ComputeToNode_Dense(Func<Int32, Boolean>, Single)
Declaration
protected int ComputeToNode_Dense(Func<int, bool> terminatingNodeF, float fMaxDistance)
Parameters
Returns
ComputeToNode_Dense(Int32, Single)
Declaration
protected void ComputeToNode_Dense(int node_id, float fMaxDistance)
Parameters
Type |
Name |
Description |
Int32 |
node_id |
|
Single |
fMaxDistance |
|
ComputeToNode_Sparse(Func<Int32, Boolean>, Single)
Declaration
protected int ComputeToNode_Sparse(Func<int, bool> terminatingNodeF, float fMaxDistance)
Parameters
Returns
ComputeToNode_Sparse(Int32, Single)
Declaration
protected void ComputeToNode_Sparse(int node_id, float fMaxDistance)
Parameters
Type |
Name |
Description |
Int32 |
node_id |
|
Single |
fMaxDistance |
|
GetDistance(Int32)
Get the computed distance at node id. returns InvalidValue if node was not computed.
Declaration
public float GetDistance(int id)
Parameters
Type |
Name |
Description |
Int32 |
id |
|
Returns
GetOrder()
Get (internal) list of frozen nodes in increasing distance-order.
Requries that TrackOrder=true before Compute call.
Declaration
public List<int> GetOrder()
Returns
GetPathToSeed(Int32, List<Int32>)
Walk from node fromv back to the (graph-)nearest seed point.
Declaration
public bool GetPathToSeed(int fromv, List<int> path)
Parameters
Returns
IsSeed(Int32)
Declaration
public bool IsSeed(int id)
Parameters
Type |
Name |
Description |
Int32 |
id |
|
Returns
MeshTriangles(DMesh3, Boolean)
shortcut to construct graph for mesh triangles
Declaration
public static DijkstraGraphDistance MeshTriangles(DMesh3 mesh, bool bSparse = false)
Parameters
Returns
MeshVertices(DMesh3, Boolean)
shortcut to construct graph for mesh vertices
Declaration
public static DijkstraGraphDistance MeshVertices(DMesh3 mesh, bool bSparse = false)
Parameters
Returns
Reset()
reset internal data structures/etc
Declaration