Table of Contents

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

graph IDirectedGraph<TVertex, Edge<TVertex>>

The simple directed graph to complement.

Returns

IDirectedGraph<TVertex, Edge<TVertex>>

A new directed graph containing the complement.

Type Parameters

TVertex

The vertex type.

Exceptions

ArgumentNullException

graph is 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

graph IReadOnlyGraph<TVertex, Edge<TVertex>>

The simple graph to complement.

Returns

IMutableGraph<TVertex, Edge<TVertex>>

A new graph containing the complement.

Type Parameters

TVertex

The vertex type.

Exceptions

ArgumentNullException

graph is 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

graph IReadOnlyGraph<TVertex, TEdge>

The simple graph to complement.

edgeFactory Func<TVertex, TVertex, TEdge>

Builds the complement edge for a (source, target) pair.

Returns

IMutableGraph<TVertex, TEdge>

A new graph containing the complement.

Type Parameters

TVertex

The vertex type.

TEdge

The 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

graph IDirectedGraph<TVertex, TEdge>

The directed graph to take the subgraph of.

vertices IEnumerable<TVertex>

The vertices to keep.

Returns

IDirectedGraph<TVertex, TEdge>

A new directed graph containing the induced subgraph.

Type Parameters

TVertex

The vertex type.

TEdge

The 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

graph IReadOnlyGraph<TVertex, TEdge>

The graph to take the subgraph of.

vertices IEnumerable<TVertex>

The vertices to keep.

Returns

IMutableGraph<TVertex, TEdge>

A new graph of the same family containing the induced subgraph.

Type Parameters

TVertex

The vertex type.

TEdge

The 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

first IDirectedGraph<TVertex, TEdge>

The first operand; decides the result's family and comparer.

second IDirectedGraph<TVertex, TEdge>

The second operand.

Returns

IDirectedGraph<TVertex, TEdge>

A new directed graph containing the union.

Type Parameters

TVertex

The vertex type.

TEdge

The 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

first IReadOnlyGraph<TVertex, TEdge>

The first operand; decides the result's family and comparer.

second IReadOnlyGraph<TVertex, TEdge>

The second operand; must have the same direction as first.

Returns

IMutableGraph<TVertex, TEdge>

A new graph containing the union.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

Exceptions

ArgumentNullException

An argument is null.

ArgumentException

One graph is directed and the other is not.