IReadOnlyWeightedGraph<TVertex> Interface
Definition
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
TVertexThe 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
fromTVertexThe source vertex.
toTVertexThe destination vertex.
Returns
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
fromTVertexThe source vertex.
toTVertexThe destination vertex.
weightdoubleWhen this method returns, contains the edge weight if the edge exists; otherwise, the default value.
Returns
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
vertexTVertexThe 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
| Product | Versions |
|---|---|
| .NET | 8, 10 |