Class UndirectedShortestPathAlgorithmBase<TVertex, TEdge>
Base class for all shortest path finder algorithms in undirected graphs.
Inheritance
Implements
Inherited Members
Namespace: QuikGraph.Algorithms.ShortestPath
Assembly: QuikGraph.dll
Syntax
public abstract class UndirectedShortestPathAlgorithmBase<TVertex, TEdge> : RootedAlgorithmBase<TVertex, IUndirectedGraph<TVertex, TEdge>>, IAlgorithm<IUndirectedGraph<TVertex, TEdge>>, IComputation, IAlgorithmComponent, IVertexColorizerAlgorithm<TVertex>, IUndirectedTreeBuilderAlgorithm<TVertex, TEdge>, IDistancesCollection<TVertex> where TEdge : IEdge<TVertex>
Type Parameters
Name | Description |
---|---|
TVertex | Vertex type. |
TEdge | Edge type. |
Constructors
| Improve this Doc View SourceUndirectedShortestPathAlgorithmBase(IAlgorithmComponent, IUndirectedGraph<TVertex, TEdge>, Func<TEdge, Double>)
Initializes a new instance of the UndirectedShortestPathAlgorithmBase<TVertex, TEdge> class.
Declaration
protected UndirectedShortestPathAlgorithmBase(IAlgorithmComponent host, IUndirectedGraph<TVertex, TEdge> visitedGraph, Func<TEdge, double> edgeWeights)
Parameters
Type | Name | Description |
---|---|---|
IAlgorithmComponent | host | Host to use if set, otherwise use this reference. |
IUndirectedGraph<TVertex, TEdge> | visitedGraph | Graph to visit. |
System.Func<TEdge, System.Double> | edgeWeights | Function that computes the weight for a given edge. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
UndirectedShortestPathAlgorithmBase(IAlgorithmComponent, IUndirectedGraph<TVertex, TEdge>, Func<TEdge, Double>, IDistanceRelaxer)
Initializes a new instance of the UndirectedShortestPathAlgorithmBase<TVertex, TEdge> class.
Declaration
protected UndirectedShortestPathAlgorithmBase(IAlgorithmComponent host, IUndirectedGraph<TVertex, TEdge> visitedGraph, Func<TEdge, double> edgeWeights, IDistanceRelaxer distanceRelaxer)
Parameters
Type | Name | Description |
---|---|---|
IAlgorithmComponent | host | Host to use if set, otherwise use this reference. |
IUndirectedGraph<TVertex, TEdge> | visitedGraph | Graph to visit. |
System.Func<TEdge, System.Double> | edgeWeights | Function that computes the weight for a given edge. |
IDistanceRelaxer | distanceRelaxer | Distance relaxer. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
Properties
| Improve this Doc View SourceDistanceRelaxer
Distance relaxer.
Declaration
public IDistanceRelaxer DistanceRelaxer { get; }
Property Value
Type | Description |
---|---|
IDistanceRelaxer |
Distances
Vertices distances.
Declaration
[Obsolete("Use methods on IDistancesCollection to interact with the distances instead.")]
public IDictionary<TVertex, double> Distances { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<TVertex, System.Double> |
VerticesColors
Stores vertices associated to their colors (treatment state).
Declaration
public IDictionary<TVertex, GraphColor> VerticesColors { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<TVertex, GraphColor> |
Weights
Function that given an edge return the weight of this edge.
Declaration
public Func<TEdge, double> Weights { get; }
Property Value
Type | Description |
---|---|
System.Func<TEdge, System.Double> |
Methods
| Improve this Doc View SourceDistancesIndexGetter()
Gets the function that gives access to distances from a vertex.
Declaration
protected Func<TVertex, double> DistancesIndexGetter()
Returns
Type | Description |
---|---|
System.Func<TVertex, System.Double> |
GetDistance(TVertex)
Gets the distance associated to the given vertex
.
Declaration
public double GetDistance(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex to get the distance for. |
Returns
Type | Description |
---|---|
System.Double | The distance associated with the vertex. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Algorithm has not been run. |
GetDistances()
Gets the distances for all vertices currently known.
Declaration
public IEnumerable<KeyValuePair<TVertex, double>> GetDistances()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TVertex, System.Double>> | The System.Collections.Generic.KeyValuePair{Vertex,Distance} for the known vertices. |
GetVertexColor(TVertex)
Gets the GraphColor associated to the given vertex
.
Declaration
public GraphColor GetVertexColor(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
GraphColor | The vertex GraphColor. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
GetVertexDistance(TVertex)
Gets the distance associated to the given vertex
.
Declaration
protected double GetVertexDistance(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex to get the distance for. |
Returns
Type | Description |
---|---|
System.Double |
Initialize()
Called on algorithm initialization step.
Declaration
protected override void Initialize()
Overrides
OnTreeEdge(TEdge, Boolean)
Called on each TreeEdge event.
Declaration
protected virtual void OnTreeEdge(TEdge edge, bool reversed)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Concerned edge. |
System.Boolean | reversed | Indicates if the edge is reversed. |
Relax(TEdge, TVertex, TVertex)
Runs the relaxation algorithm on the given edge
.
Declaration
protected bool Relax(TEdge edge, TVertex source, TVertex target)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Edge to relax. |
TVertex | source | Source vertex. |
TVertex | target | Target vertex. |
Returns
Type | Description |
---|---|
System.Boolean | True if relaxation decreased the target vertex distance, false otherwise. |
SetVertexDistance(TVertex, Double)
Sets the distance associated to the given vertex
.
Declaration
protected void SetVertexDistance(TVertex vertex, double distance)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex to get the distance for. |
System.Double | distance | The distance. |
TryGetDistance(TVertex, out Double)
Tries to get the distance associated to the given vertex
.
Declaration
public bool TryGetDistance(TVertex vertex, out double distance)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
System.Double | distance | Associated distance. |
Returns
Type | Description |
---|---|
System.Boolean | True if the distance was found, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Algorithm has not been run. |
Events
| Improve this Doc View SourceTreeEdge
Fired when the distance label for the target vertex is decreased. The edge that participated in the last relaxation for vertex v is an edge in the shortest paths tree.
Declaration
public event UndirectedEdgeAction<TVertex, TEdge> TreeEdge
Event Type
Type | Description |
---|---|
UndirectedEdgeAction<TVertex, TEdge> |