Show / Hide Table of Contents

Class GraphHelpers

Helpers to deal with graphs.

Inheritance
System.Object
GraphHelpers
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: GraphShape.Utils
Assembly: GraphShape.dll
Syntax
public static class GraphHelpers

Methods

| Improve this Doc View Source

Convert<TVertex, TEdge, TNewGraph>(IVertexAndEdgeListGraph<TVertex, TEdge>, TNewGraph)

Converts the oldGraph into the newGraph.

Declaration
public static TNewGraph Convert<TVertex, TEdge, TNewGraph>(this IVertexAndEdgeListGraph<TVertex, TEdge> oldGraph, TNewGraph newGraph)
    where TEdge : IEdge<TVertex> where TNewGraph : IMutableVertexAndEdgeListGraph<TVertex, TEdge>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TEdge> oldGraph

Graph to convert.

TNewGraph newGraph

Graph that will be filled with converted content.

Returns
Type Description
TNewGraph

The converted graph.

Type Parameters
Name Description
TVertex

Old vertex type.

TEdge

Old edge type.

TNewGraph

Converted graph type.

Exceptions
Type Condition
System.ArgumentNullException

oldGraph is null.

System.ArgumentNullException

newGraph is null.

| Improve this Doc View Source

Convert<TVertex, TOldEdge, TNewEdge>(IVertexAndEdgeListGraph<TVertex, TOldEdge>, Func<TOldEdge, TNewEdge>)

Converts the oldGraph into a QuikGraph.BidirectionalGraph{TVertex,TEdge}. Uses edgeConverter to convert edges if provided. Performs a direct cast otherwise.

Declaration
public static BidirectionalGraph<TVertex, TNewEdge> Convert<TVertex, TOldEdge, TNewEdge>(this IVertexAndEdgeListGraph<TVertex, TOldEdge> oldGraph, Func<TOldEdge, TNewEdge> edgeConverter)
    where TOldEdge : IEdge<TVertex> where TNewEdge : IEdge<TVertex>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TOldEdge> oldGraph

Graph to convert.

System.Func<TOldEdge, TNewEdge> edgeConverter

Function to convert edges from TOldEdge to TNewEdge.

Returns
Type Description
QuikGraph.BidirectionalGraph<TVertex, TNewEdge>

The converted graph.

Type Parameters
Name Description
TVertex

Old vertex type.

TOldEdge

Old edge type.

TNewEdge

New edge type.

Exceptions
Type Condition
System.ArgumentNullException

oldGraph is null.

| Improve this Doc View Source

Convert<TVertex, TOldEdge, TNewEdge, TNewGraph>(IVertexAndEdgeListGraph<TVertex, TOldEdge>, TNewGraph, Func<TOldEdge, TNewEdge>)

Converts the oldGraph into the newGraph. Uses edgeConverter to convert edges if provided. Performs a direct cast otherwise.

Declaration
public static TNewGraph Convert<TVertex, TOldEdge, TNewEdge, TNewGraph>(this IVertexAndEdgeListGraph<TVertex, TOldEdge> oldGraph, TNewGraph newGraph, Func<TOldEdge, TNewEdge> edgeConverter)
    where TOldEdge : IEdge<TVertex> where TNewEdge : IEdge<TVertex> where TNewGraph : IMutableVertexAndEdgeListGraph<TVertex, TNewEdge>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TOldEdge> oldGraph

Graph to convert.

TNewGraph newGraph

Graph that will be filled with converted content.

System.Func<TOldEdge, TNewEdge> edgeConverter

Function to convert edges from TOldEdge to TNewEdge.

Returns
Type Description
TNewGraph

The converted graph.

Type Parameters
Name Description
TVertex

Old vertex type.

TOldEdge

Old edge type.

TNewEdge

New edge type.

TNewGraph

Converted graph type.

Exceptions
Type Condition
System.ArgumentNullException

oldGraph is null.

System.ArgumentNullException

newGraph is null.

| Improve this Doc View Source

Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge>(IVertexAndEdgeListGraph<TOldVertex, TOldEdge>, Func<TOldVertex, TNewVertex>, Func<TOldEdge, TNewEdge>)

Converts the oldGraph into a QuikGraph.BidirectionalGraph{TVertex,TEdge}. Uses vertexConverter and edgeConverter to convert vertices and edges if provided. Performs a direct cast otherwise.

Declaration
public static BidirectionalGraph<TNewVertex, TNewEdge> Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge>(this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph, Func<TOldVertex, TNewVertex> vertexConverter, Func<TOldEdge, TNewEdge> edgeConverter)
    where TOldEdge : IEdge<TOldVertex> where TNewEdge : IEdge<TNewVertex>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph

Graph to convert.

System.Func<TOldVertex, TNewVertex> vertexConverter

Function to convert vertices from TOldVertex to TNewVertex.

System.Func<TOldEdge, TNewEdge> edgeConverter

Function to convert edges from TOldEdge to TNewEdge.

Returns
Type Description
QuikGraph.BidirectionalGraph<TNewVertex, TNewEdge>

The converted graph.

Type Parameters
Name Description
TOldVertex

Old vertex type.

TOldEdge

Old edge type.

TNewVertex

New vertex type.

TNewEdge

New edge type.

Exceptions
Type Condition
System.ArgumentNullException

oldGraph is null.

| Improve this Doc View Source

Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge, TNewGraph>(IVertexAndEdgeListGraph<TOldVertex, TOldEdge>, TNewGraph, Func<TOldVertex, TNewVertex>, Func<TOldEdge, TNewEdge>)

Converts the oldGraph into the newGraph. Uses vertexConverter and edgeConverter to convert vertices and edges if provided. Performs a direct cast otherwise.

Declaration
public static TNewGraph Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge, TNewGraph>(this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph, TNewGraph newGraph, Func<TOldVertex, TNewVertex> vertexConverter, Func<TOldEdge, TNewEdge> edgeConverter)
    where TOldEdge : IEdge<TOldVertex> where TNewEdge : IEdge<TNewVertex> where TNewGraph : IMutableVertexAndEdgeListGraph<TNewVertex, TNewEdge>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph

Graph to convert.

TNewGraph newGraph

Graph that will be filled with converted content.

System.Func<TOldVertex, TNewVertex> vertexConverter

Function to convert vertices from TOldVertex to TNewVertex.

System.Func<TOldEdge, TNewEdge> edgeConverter

Function to convert edges from TOldEdge to TNewEdge.

Returns
Type Description
TNewGraph

The converted graph.

Type Parameters
Name Description
TOldVertex

Old vertex type.

TOldEdge

Old edge type.

TNewVertex

New vertex type.

TNewEdge

New edge type.

TNewGraph

Converted graph type.

Exceptions
Type Condition
System.ArgumentNullException

oldGraph is null.

System.ArgumentNullException

newGraph is null.

| Improve this Doc View Source

CopyToBidirectionalGraph<TVertex, TEdge>(IVertexAndEdgeListGraph<TVertex, TEdge>)

Copies this graph into a QuikGraph.BidirectionalGraph{TVertex,TEdge} one.

Declaration
public static BidirectionalGraph<TVertex, TEdge> CopyToBidirectionalGraph<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> graph)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TEdge> graph

Graph to copy.

Returns
Type Description
QuikGraph.BidirectionalGraph<TVertex, TEdge>

QuikGraph.BidirectionalGraph{TVertex,TEdge} initialized from graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

| Improve this Doc View Source

CreateGraph<TVertex, TEdgeData>(IEnumerable<TVertex>, IEnumerable<TEdgeData>, String, String)

Creates a QuikGraph.BidirectionalGraph{TVertex,TEdge} with the given vertices and edges constructed by getting values of properties sourcePropertyName and targetPropertyName on type TEdgeData.

Declaration
public static BidirectionalGraph<TVertex, Edge<TVertex>> CreateGraph<TVertex, TEdgeData>(IEnumerable<TVertex> vertices, IEnumerable<TEdgeData> edgesData, string sourcePropertyName, string targetPropertyName)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TVertex> vertices

The set of the vertices.

System.Collections.Generic.IEnumerable<TEdgeData> edgesData

The set of data used to construct graph edges.

System.String sourcePropertyName

Name of the property to get value from TEdgeData to construct edge source.

System.String targetPropertyName

Name of the property to get value from TEdgeData to construct edge target.

Returns
Type Description
QuikGraph.BidirectionalGraph<TVertex, QuikGraph.Edge<TVertex>>

A QuikGraph.BidirectionalGraph{TVertex,TEdge}.

Type Parameters
Name Description
TVertex

Vertex type.

TEdgeData

Type of the object used to construct edges.

Exceptions
Type Condition
System.ArgumentNullException

vertices is null.

System.ArgumentNullException

edgesData is null.

System.ArgumentNullException

sourcePropertyName is null.

System.ArgumentNullException

targetPropertyName is null.

System.ArgumentNullException

Edge property sourcePropertyName and/or targetPropertyName has null value.

System.ArgumentException

sourcePropertyName is not the name of a property of type TEdgeData.

System.ArgumentException

targetPropertyName is not the name of a property of type TEdgeData.

System.ArgumentException

Edge property sourcePropertyName and/or targetPropertyName has a type that is not assignable to TVertex.

| Improve this Doc View Source

CreateGraph<TVertex, TEdge, TEdgeData>(IEnumerable<TVertex>, IEnumerable<TEdgeData>, Func<TEdgeData, TEdge>)

Creates a QuikGraph.BidirectionalGraph{TVertex,TEdgeTo} with the given vertices and edges constructed using edgeFactory. Note: The graph will allow parallel edges.

Declaration
public static BidirectionalGraph<TVertex, TEdge> CreateGraph<TVertex, TEdge, TEdgeData>(IEnumerable<TVertex> vertices, IEnumerable<TEdgeData> edgesData, Func<TEdgeData, TEdge> edgeFactory)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TVertex> vertices

The set of the vertices.

System.Collections.Generic.IEnumerable<TEdgeData> edgesData

The set of data used to construct graph edges.

System.Func<TEdgeData, TEdge> edgeFactory

Factory method to convert an edge data into an edge.

Returns
Type Description
QuikGraph.BidirectionalGraph<TVertex, TEdge>

A QuikGraph.BidirectionalGraph{TVertex,TEdge}.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TEdgeData

Type of the object used to construct edges.

Exceptions
Type Condition
System.ArgumentNullException

vertices is null.

System.ArgumentNullException

edgesData is null.

System.ArgumentNullException

edgeFactory is null or creates null edge.

| Improve this Doc View Source

CreateGraph<TVertex, TEdge, TEdgeData>(IEnumerable<TVertex>, IEnumerable<TEdgeData>, Func<TEdgeData, TEdge>, Boolean)

Creates a QuikGraph.BidirectionalGraph{TVertex,TEdgeTo} with the given vertices and edges constructed using edgeFactory.

Declaration
public static BidirectionalGraph<TVertex, TEdge> CreateGraph<TVertex, TEdge, TEdgeData>(IEnumerable<TVertex> vertices, IEnumerable<TEdgeData> edgesData, Func<TEdgeData, TEdge> edgeFactory, bool allowParallelEdges)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TVertex> vertices

The set of the vertices.

System.Collections.Generic.IEnumerable<TEdgeData> edgesData

The set of data used to construct graph edges.

System.Func<TEdgeData, TEdge> edgeFactory

Factory method to convert an edge data into an edge.

System.Boolean allowParallelEdges

Indicates if parallel edges are allowed.

Returns
Type Description
QuikGraph.BidirectionalGraph<TVertex, TEdge>

A QuikGraph.BidirectionalGraph{TVertex,TEdge}.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TEdgeData

Type of the object used to construct edges.

Exceptions
Type Condition
System.ArgumentNullException

vertices is null.

System.ArgumentNullException

edgesData is null.

System.ArgumentNullException

edgeFactory is null or creates null edge.

| Improve this Doc View Source

GetDiameter<TVertex, TEdge, TGraph>(TGraph)

Gets the diameter of the graph. Note: The diameter is the greatest distance between two vertices.

Declaration
public static double GetDiameter<TVertex, TEdge, TGraph>(this TGraph graph)
    where TEdge : IEdge<TVertex> where TGraph : IBidirectionalGraph<TVertex, TEdge>
Parameters
Type Name Description
TGraph graph

The graph.

Returns
Type Description
System.Double

The diameter of the graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

| Improve this Doc View Source

GetDiameter<TVertex, TEdge, TGraph>(TGraph, out Double[,])

Gets the diameter of the graph. Note: The diameter is the greatest distance between two vertices.

Declaration
public static double GetDiameter<TVertex, TEdge, TGraph>(this TGraph graph, out double[, ] distances)
    where TEdge : IEdge<TVertex> where TGraph : IBidirectionalGraph<TVertex, TEdge>
Parameters
Type Name Description
TGraph graph

The graph.

System.Double[,] distances

Will give distances between every vertex-pair.

Returns
Type Description
System.Double

The diameter of the graph.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

| Improve this Doc View Source

GetDistances<TVertex, TEdge, TGraph>(TGraph)

Gets the distances between the vertices of the graph. Note: The distance is the number of edges between 2 vertices.

Declaration
public static double[, ] GetDistances<TVertex, TEdge, TGraph>(this TGraph graph)
    where TEdge : IEdge<TVertex> where TGraph : IBidirectionalGraph<TVertex, TEdge>
Parameters
Type Name Description
TGraph graph

The graph.

Returns
Type Description
System.Double[,]

The distances between every vertex-pair.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

TGraph

Graph type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

| Improve this Doc View Source

GetEdgesBetween<TVertex, TEdge>(IVertexAndEdgeListGraph<TVertex, TEdge>, TVertex[], TVertex[])

Returns every edges which source is one of the vertices in the set1 and the target is one of the vertices in the set2.

Declaration
public static IEnumerable<TEdge> GetEdgesBetween<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> graph, TVertex[] set1, TVertex[] set2)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TEdge> graph

The graph.

TVertex[] set1

Source vertices set.

TVertex[] set2

Target vertices set

Returns
Type Description
System.Collections.Generic.IEnumerable<TEdge>

Edges with a source in set1 and a target in set2.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

set1 is null.

System.ArgumentNullException

set2 is null.

| Improve this Doc View Source

GetNeighbors<TVertex, TEdge>(IBidirectionalGraph<TVertex, TEdge>, TVertex)

Gets the neighbors (adjacent vertices) of the vertex.

Declaration
public static IEnumerable<TVertex> GetNeighbors<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph, TVertex vertex)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
QuikGraph.IBidirectionalGraph<TVertex, TEdge> graph

The graph.

TVertex vertex

The vertex of which we want to get neighbors.

Returns
Type Description
System.Collections.Generic.IEnumerable<TVertex>

Adjacent vertices of the vertex.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

vertex is null.

| Improve this Doc View Source

GetOutNeighbors<TVertex, TEdge>(IVertexAndEdgeListGraph<TVertex, TEdge>, TVertex)

Gets the out neighbors (only adjacent vertices from out-edges) of the vertex.

Declaration
public static IEnumerable<TVertex> GetOutNeighbors<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> graph, TVertex vertex)
    where TEdge : IEdge<TVertex>
Parameters
Type Name Description
QuikGraph.IVertexAndEdgeListGraph<TVertex, TEdge> graph

The graph.

TVertex vertex

The vertex of which we want to get neighbors.

Returns
Type Description
System.Collections.Generic.IEnumerable<TVertex>

Adjacent vertices of the vertex.

Type Parameters
Name Description
TVertex

Vertex type.

TEdge

Edge type.

Exceptions
Type Condition
System.ArgumentNullException

graph is null.

System.ArgumentNullException

vertex is null.

  • Improve this Doc
  • View Source
In This Article
Back to top GraphShape