Class GraphOperationsExtensions
- Namespace
- Graph1x.Algorithms
- Assembly
- Graph1x.dll
Graph set operations: induced subgraphs, unions, and complements. Every operation returns a new graph matching the source's direction and parallel-edge policy (comparer included); the inputs are never mutated.
public static class GraphOperationsExtensions
- Inheritance
-
GraphOperationsExtensions
- Inherited Members
Methods
Complement<TVertex>(IDirectedGraph<TVertex, Edge<TVertex>>)
Builds the complement of a simple directed graph, keeping the IDirectedGraph<TVertex, TEdge> static type.
public static IDirectedGraph<TVertex, Edge<TVertex>> Complement<TVertex>(this IDirectedGraph<TVertex, Edge<TVertex>> graph) where TVertex : notnull
Parameters
graphIDirectedGraph<TVertex, Edge<TVertex>>The simple directed graph to complement.
Returns
- IDirectedGraph<TVertex, Edge<TVertex>>
A new directed graph containing the complement.
Type Parameters
TVertexThe vertex type.
Exceptions
- ArgumentNullException
graphis null.- ArgumentException
The graph allows parallel edges, so its complement is undefined.
Complement<TVertex>(IReadOnlyGraph<TVertex, Edge<TVertex>>)
Builds the complement of a simple graph with Edge<TVertex> edges.
public static IMutableGraph<TVertex, Edge<TVertex>> Complement<TVertex>(this IReadOnlyGraph<TVertex, Edge<TVertex>> graph) where TVertex : notnull
Parameters
graphIReadOnlyGraph<TVertex, Edge<TVertex>>The simple graph to complement.
Returns
- IMutableGraph<TVertex, Edge<TVertex>>
A new graph containing the complement.
Type Parameters
TVertexThe vertex type.
Exceptions
- ArgumentNullException
graphis null.- ArgumentException
The graph allows parallel edges, so its complement is undefined.
Complement<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>, Func<TVertex, TVertex, TEdge>)
Builds the complement of a simple graph: same vertices, and an edge between two distinct vertices exactly when the original has none. Self-loops are never emitted (and existing ones simply disappear).
public static IMutableGraph<TVertex, TEdge> Complement<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph, Func<TVertex, TVertex, TEdge> edgeFactory) where TVertex : notnull where TEdge : IEdge<TVertex>
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The simple graph to complement.
edgeFactoryFunc<TVertex, TVertex, TEdge>Builds the complement edge for a (source, target) pair.
Returns
- IMutableGraph<TVertex, TEdge>
A new graph containing the complement.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
Exceptions
- ArgumentNullException
An argument is null.
- ArgumentException
The graph allows parallel edges, so its complement is undefined.
Subgraph<TVertex, TEdge>(IDirectedGraph<TVertex, TEdge>, IEnumerable<TVertex>)
Builds the subgraph induced by vertices, keeping the
IDirectedGraph<TVertex, TEdge> static type.
public static IDirectedGraph<TVertex, TEdge> Subgraph<TVertex, TEdge>(this IDirectedGraph<TVertex, TEdge> graph, IEnumerable<TVertex> vertices) where TVertex : notnull where TEdge : IEdge<TVertex>
Parameters
graphIDirectedGraph<TVertex, TEdge>The directed graph to take the subgraph of.
verticesIEnumerable<TVertex>The vertices to keep.
Returns
- IDirectedGraph<TVertex, TEdge>
A new directed graph containing the induced subgraph.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
Exceptions
- ArgumentNullException
An argument is null.
Subgraph<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>, IEnumerable<TVertex>)
Builds the subgraph induced by vertices: the selected
vertices that exist in the graph, plus every edge whose endpoints are
both selected. Vertices not present in the graph are ignored.
public static IMutableGraph<TVertex, TEdge> Subgraph<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph, IEnumerable<TVertex> vertices) where TVertex : notnull where TEdge : IEdge<TVertex>
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to take the subgraph of.
verticesIEnumerable<TVertex>The vertices to keep.
Returns
- IMutableGraph<TVertex, TEdge>
A new graph of the same family containing the induced subgraph.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
Exceptions
- ArgumentNullException
An argument is null.
Union<TVertex, TEdge>(IDirectedGraph<TVertex, TEdge>, IDirectedGraph<TVertex, TEdge>)
Builds the union of two directed graphs, keeping the IDirectedGraph<TVertex, TEdge> static type.
public static IDirectedGraph<TVertex, TEdge> Union<TVertex, TEdge>(this IDirectedGraph<TVertex, TEdge> first, IDirectedGraph<TVertex, TEdge> second) where TVertex : notnull where TEdge : IEdge<TVertex>
Parameters
firstIDirectedGraph<TVertex, TEdge>The first operand; decides the result's family and comparer.
secondIDirectedGraph<TVertex, TEdge>The second operand.
Returns
- IDirectedGraph<TVertex, TEdge>
A new directed graph containing the union.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
Exceptions
- ArgumentNullException
An argument is null.
Union<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>, IReadOnlyGraph<TVertex, TEdge>)
Builds the union of two graphs: all vertices and all edges of both.
The result's family and comparer come from first;
when the result is a simple graph, edges sharing endpoints collapse
(the copy from first wins).
public static IMutableGraph<TVertex, TEdge> Union<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> first, IReadOnlyGraph<TVertex, TEdge> second) where TVertex : notnull where TEdge : IEdge<TVertex>
Parameters
firstIReadOnlyGraph<TVertex, TEdge>The first operand; decides the result's family and comparer.
secondIReadOnlyGraph<TVertex, TEdge>The second operand; must have the same direction as
first.
Returns
- IMutableGraph<TVertex, TEdge>
A new graph containing the union.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
Exceptions
- ArgumentNullException
An argument is null.
- ArgumentException
One graph is directed and the other is not.