Table of Contents

IReadOnlyWeightedGraph<TVertex> Interface

Definition

Namespace
Bodu.Collections.Generic.Graphs
Assembly
Bodu.Collections.dll
Package
Bodu.Collections 1.0.0
Source
IReadOnlyWeightedGraph{T}.cs

Defines a read-only view over a graph whose edges carry double weights, extending IReadOnlyGraph<TVertex> with weight queries.

public interface IReadOnlyWeightedGraph<TVertex> : IReadOnlyGraph<TVertex> where TVertex : notnull

Type Parameters

TVertex

The vertex type.

Inherited Members
Extension Methods

Remarks

Weighted algorithms (for example shortest path) accept this interface so they can run over any weighted graph representation. The default Graph<T> implements this interface.

Methods

ContainsEdge(TVertex, TVertex)

Determines whether an edge exists between the specified vertices.

bool ContainsEdge(TVertex from, TVertex to)

Parameters

from TVertex

The source vertex.

to TVertex

The destination vertex.

Returns

bool

true if the edge exists; otherwise, false.

TryGetEdgeWeight(TVertex, TVertex, out double)

Attempts to get the weight of the edge between the specified vertices.

bool TryGetEdgeWeight(TVertex from, TVertex to, out double weight)

Parameters

from TVertex

The source vertex.

to TVertex

The destination vertex.

weight double

When this method returns, contains the edge weight if the edge exists; otherwise, the default value.

Returns

bool

true if the edge exists; otherwise, false.

WeightedNeighbors(TVertex)

Returns the successor vertices reachable from the specified vertex, paired with their edge weights.

IEnumerable<(TVertex Neighbor, double Weight)> WeightedNeighbors(TVertex vertex)

Parameters

vertex TVertex

The vertex whose weighted neighbors are requested.

Returns

IEnumerable<(TVertex Neighbor, double Weight)>

The neighboring vertices and the weight of each connecting edge.

Remarks

Weights may be negative in general, but individual algorithms impose their own preconditions: Dijkstra-based shortest-path methods in GraphAlgorithms require every weight yielded here to be non-negative and throw ArgumentException when a negative weight is encountered.

Applies to

ProductVersions
.NET8, 10