Table of Contents

Class BellmanFord<TWeight>

Namespace
AlgorithmsSW.EdgeWeightedDigraph
Assembly
AlgorithmsSW.dll
public class BellmanFord<TWeight> : IShortestPath<TWeight> where TWeight : INumber<TWeight>, IMinMaxValue<TWeight>

Type Parameters

TWeight
Inheritance
BellmanFord<TWeight>
Implements
IShortestPath<TWeight>
Inherited Members
Extension Methods

Constructors

BellmanFord(IReadOnlyEdgeWeightedDigraph<TWeight>, int)

public BellmanFord(IReadOnlyEdgeWeightedDigraph<TWeight> graph, int sourceVertex)

Parameters

graph IReadOnlyEdgeWeightedDigraph<TWeight>
sourceVertex int

Methods

GetDistanceTo(int)

Gets the distance from the source vertex to the given vertex.

public TWeight GetDistanceTo(int vertex)

Parameters

vertex int

The vertex to find the distance to.

Returns

TWeight

The distance from the source vertex to the given vertex.

GetEdgesOfPathTo(int)

Gets the path from the source vertex to the given vertex.

public IEnumerable<DirectedEdge<TWeight>> GetEdgesOfPathTo(int target)

Parameters

target int

The vertex to find the path to.

Returns

IEnumerable<DirectedEdge<TWeight>>

An enumerable of edges representing the path from the source vertex to the given vertex.

Exceptions

InvalidOperationException

+there is no path from the source vertex to the given vertex.

HasNegativeCycle()

public bool HasNegativeCycle()

Returns

bool

HasPathTo(int)

Whether there is a path from the source vertex to the given vertex.

public bool HasPathTo(int vertex)

Parameters

vertex int

The vertex to check if there is a path to.

Returns

bool

true if there is a path from the source vertex to the given vertex; otherwise, false.

NegativeCycle()

public IEnumerable<DirectedEdge<TWeight>> NegativeCycle()

Returns

IEnumerable<DirectedEdge<TWeight>>