Table of Contents

Class AStarShortestPath<TVertex, TEdge, TWeight>

Namespace
Graph1x.Algorithms
Assembly
Graph1x.dll

The A* shortest-path algorithm: Dijkstra guided by a caller-supplied heuristic estimating the remaining distance to the target. The heuristic must be consistent (never overestimate, and satisfy the triangle inequality) for the result to be optimal; a zero heuristic degrades to plain Dijkstra. Requires non-negative edge weights.

public sealed class AStarShortestPath<TVertex, TEdge, TWeight> : IShortestPathAlgorithm<TVertex, TEdge, TWeight> where TVertex : notnull where TEdge : IEdge<TVertex> where TWeight : INumber<TWeight>

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

TWeight

The numeric weight type.

Inheritance
AStarShortestPath<TVertex, TEdge, TWeight>
Implements
IShortestPathAlgorithm<TVertex, TEdge, TWeight>
Inherited Members

Constructors

AStarShortestPath(Func<TEdge, TWeight>, Func<TVertex, TVertex, TWeight>)

Initializes the algorithm with a weight selector and a heuristic.

public AStarShortestPath(Func<TEdge, TWeight> weightSelector, Func<TVertex, TVertex, TWeight> heuristic)

Parameters

weightSelector Func<TEdge, TWeight>

Maps an edge to its weight.

heuristic Func<TVertex, TVertex, TWeight>

Estimates the remaining distance from a vertex (first argument) to the target (second argument).

Exceptions

ArgumentNullException

Either argument is null.

Methods

FindPath(IReadOnlyGraph<TVertex, TEdge>, TVertex, TVertex)

Finds the shortest path from source to target.

public ShortestPathResult<TVertex, TWeight> FindPath(IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, TVertex target)

Parameters

graph IReadOnlyGraph<TVertex, TEdge>

The graph to search.

source TVertex

The start vertex.

target TVertex

The end vertex.

Returns

ShortestPathResult<TVertex, TWeight>

The query result, unreachable when no path exists.

Exceptions

ArgumentException

Either endpoint is not in the graph.

NegativeWeightException

A negative edge weight was encountered.