Class UndirectedGraph<TVertex, TEdge>
Mutable undirected graph data structure.
Inheritance
Implements
Inherited Members
Namespace: QuikGraph
Assembly: QuikGraph.dll
Syntax
[Serializable]
public class UndirectedGraph<TVertex, TEdge> : IMutableUndirectedGraph<TVertex, TEdge>, IUndirectedGraph<TVertex, TEdge>, IImplicitUndirectedGraph<TVertex, TEdge>, IMutableVertexAndEdgeSet<TVertex, TEdge>, IMutableVertexSet<TVertex>, IMutableEdgeListGraph<TVertex, TEdge>, IMutableGraph<TVertex, TEdge>, IEdgeListGraph<TVertex, TEdge>, IGraph<TVertex, TEdge>, IEdgeSet<TVertex, TEdge>, IVertexSet<TVertex>, IImplicitVertexSet<TVertex>, ICloneable, ISerializable where TEdge : IEdge<TVertex>
Type Parameters
Name | Description |
---|---|
TVertex | Vertex type. |
TEdge | Edge type |
Constructors
| Improve this Doc View SourceUndirectedGraph()
Initializes a new instance of the UndirectedGraph<TVertex, TEdge> class.
Declaration
public UndirectedGraph()
Remarks
Allow parallel edges and gets the best edge equality comparer.
UndirectedGraph(Boolean)
Initializes a new instance of the UndirectedGraph<TVertex, TEdge> class.
Declaration
public UndirectedGraph(bool allowParallelEdges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowParallelEdges | Indicates if parallel edges are allowed. |
Remarks
Gets the best edge equality comparer.
UndirectedGraph(Boolean, EdgeEqualityComparer<TVertex>)
Initializes a new instance of the UndirectedGraph<TVertex, TEdge> class.
Declaration
public UndirectedGraph(bool allowParallelEdges, EdgeEqualityComparer<TVertex> edgeEqualityComparer)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowParallelEdges | Indicates if parallel edges are allowed. |
EdgeEqualityComparer<TVertex> | edgeEqualityComparer | Equality comparer to use to compare edges. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
UndirectedGraph(SerializationInfo, StreamingContext)
Constructor used during runtime serialization.
Declaration
protected UndirectedGraph(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | |
System.Runtime.Serialization.StreamingContext | context |
Properties
| Improve this Doc View SourceAllowParallelEdges
Gets a value indicating if the graph allows parallel edges
Declaration
public bool AllowParallelEdges { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
EdgeCapacity
Gets or sets the edge capacity.
Declaration
public int EdgeCapacity { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
EdgeCount
Gets the edge count.
Declaration
public int EdgeCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
EdgeEqualityComparer
Comparer for edges.
Declaration
public EdgeEqualityComparer<TVertex> EdgeEqualityComparer { get; }
Property Value
Type | Description |
---|---|
EdgeEqualityComparer<TVertex> |
Edges
Gets the edges.
Declaration
public IEnumerable<TEdge> Edges { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TEdge> |
IsDirected
Gets a value indicating if the graph is directed
Declaration
public bool IsDirected { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsEdgesEmpty
Gets a value indicating whether there are no edges in this set. It is true if this edge set is empty, otherwise false.
Declaration
public bool IsEdgesEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsVerticesEmpty
Gets a value indicating whether there are no vertices in this set. It is true if this vertex set is empty, otherwise false.
Declaration
public bool IsVerticesEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
VertexCount
Gets the vertex count.
Declaration
public int VertexCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Vertices
Gets the vertices.
Declaration
public IEnumerable<TVertex> Vertices { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TVertex> |
Methods
| Improve this Doc View SourceAddEdge(TEdge)
Adds the edge
to this graph.
Declaration
public bool AddEdge(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | An edge. |
Returns
Type | Description |
---|---|
System.Boolean | True if the edge was added, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AddEdgeRange(IEnumerable<TEdge>)
Adds a set of edges to this graph.
Declaration
public int AddEdgeRange(IEnumerable<TEdge> edges)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TEdge> | edges | Edges to add. |
Returns
Type | Description |
---|---|
System.Int32 | The number of edges successfully added to this graph. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AddVertex(TVertex)
Adds a vertex to this set.
Declaration
public bool AddVertex(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Vertex to add. |
Returns
Type | Description |
---|---|
System.Boolean | True if the vertex was added, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AddVertexRange(IEnumerable<TVertex>)
Adds given vertices to this set.
Declaration
public int AddVertexRange(IEnumerable<TVertex> vertices)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TVertex> | vertices | Vertices to add. |
Returns
Type | Description |
---|---|
System.Int32 | The number of vertex added. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AddVerticesAndEdge(TEdge)
Adds edge
and its vertices to this graph.
Declaration
public bool AddVerticesAndEdge(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | The edge to add. |
Returns
Type | Description |
---|---|
System.Boolean | True if the edge was added, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AddVerticesAndEdgeRange(IEnumerable<TEdge>)
Adds a set of edges (and it's vertices if necessary).
Declaration
public int AddVerticesAndEdgeRange(IEnumerable<TEdge> edges)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TEdge> | edges | Edges to add. |
Returns
Type | Description |
---|---|
System.Int32 | The number of edges added. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
AdjacentDegree(TVertex)
Gives the adjacent degree of the given vertex
.
Declaration
public int AdjacentDegree(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Int32 | Vertex adjacent degree. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
AdjacentEdge(TVertex, Int32)
Gets the index
th adjacent edge of the given vertex
.
Declaration
public TEdge AdjacentEdge(TVertex vertex, int index)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
System.Int32 | index | Index of the adjacent edge requested. |
Returns
Type | Description |
---|---|
TEdge | The adjacent edge. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException | No vertex at |
VertexNotFoundException |
|
AdjacentEdges(TVertex)
Gives the enumerable of edges adjacent to the given vertex
.
Declaration
public IEnumerable<TEdge> AdjacentEdges(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TEdge> | Enumerable of adjacent edges. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
AdjacentVertices(TVertex)
Gets the set of vertices adjacent to the given vertex
.
Declaration
public IEnumerable<TVertex> AdjacentVertices(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Vertex to get adjacent ones. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TVertex> | Set of adjacent vertices. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Clear()
Clears the vertex and edges.
Declaration
public void Clear()
ClearAdjacentEdges(TVertex)
Clears adjacent edges of the given vertex
.
Declaration
public void ClearAdjacentEdges(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ClearEdges(TVertex)
Clears edges of the given vertex
.
Declaration
public void ClearEdges(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Clone()
Clones this graph.
Declaration
public UndirectedGraph<TVertex, TEdge> Clone()
Returns
Type | Description |
---|---|
UndirectedGraph<TVertex, TEdge> | Cloned graph. |
ContainsEdge(TVertex, TVertex)
Checks if this graph contains an edge that link
source
and target
vertices.
Declaration
public bool ContainsEdge(TVertex source, TVertex target)
Parameters
Type | Name | Description |
---|---|---|
TVertex | source | Source vertex. |
TVertex | target | Target vertex. |
Returns
Type | Description |
---|---|
System.Boolean | True if an edge exists, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
ContainsEdge(TEdge)
Determines whether this set contains the specified edge
.
Declaration
public bool ContainsEdge(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Edge to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ContainsVertex(TVertex)
Determines whether this set contains the specified vertex
.
Declaration
public bool ContainsVertex(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Vertex to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetObjectData(SerializationInfo, StreamingContext)
Gets the data to serialize.
Declaration
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | |
System.Runtime.Serialization.StreamingContext | context |
IsAdjacentEdgesEmpty(TVertex)
Indicates if the given vertex
has at least one adjacent edge.
Declaration
public bool IsAdjacentEdgesEmpty(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Boolean | True if the vertex has at least one adjacent edge, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
OnEdgeAdded(TEdge)
Called on each added edge.
Declaration
protected virtual void OnEdgeAdded(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Added edge. |
OnEdgeRemoved(TEdge)
Called on each removed edge.
Declaration
protected virtual void OnEdgeRemoved(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Removed edge. |
OnVertexAdded(TVertex)
Called on each added vertex.
Declaration
protected virtual void OnVertexAdded(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Added vertex. |
OnVertexRemoved(TVertex)
Called for each removed vertex.
Declaration
protected virtual void OnVertexRemoved(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Removed vertex. |
RemoveAdjacentEdgeIf(TVertex, EdgePredicate<TVertex, TEdge>)
Removes adjacent edges of the given vertex
if edge matches the predicate
.
Declaration
public int RemoveAdjacentEdgeIf(TVertex vertex, EdgePredicate<TVertex, TEdge> predicate)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
EdgePredicate<TVertex, TEdge> | predicate | Predicate to match edges. |
Returns
Type | Description |
---|---|
System.Int32 | The number of removed edges. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
RemoveEdge(TEdge)
Removes the edge
from this graph.
Declaration
public bool RemoveEdge(TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TEdge | edge | Edge to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if the |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveEdgeIf(EdgePredicate<TVertex, TEdge>)
Removes all edges that match the given predicate
.
Declaration
public int RemoveEdgeIf(EdgePredicate<TVertex, TEdge> predicate)
Parameters
Type | Name | Description |
---|---|---|
EdgePredicate<TVertex, TEdge> | predicate | Predicate to check if an edge should be removed. |
Returns
Type | Description |
---|---|
System.Int32 | The number of edges removed. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveEdges(IEnumerable<TEdge>)
Removes the given set of edges.
Declaration
public int RemoveEdges(IEnumerable<TEdge> edges)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TEdge> | edges | Edges to remove. |
Returns
Type | Description |
---|---|
System.Int32 | The number of removed edges. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveVertex(TVertex)
Removes the given vertex from this set.
Declaration
public bool RemoveVertex(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | Vertex to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if the vertex was removed, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveVertexIf(VertexPredicate<TVertex>)
Removes all vertices matching the given predicate
.
Declaration
public int RemoveVertexIf(VertexPredicate<TVertex> predicate)
Parameters
Type | Name | Description |
---|---|---|
VertexPredicate<TVertex> | predicate | Predicate to check on each vertex. |
Returns
Type | Description |
---|---|
System.Int32 | The number of vertex removed. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
TrimEdgeExcess()
Trims excess storage allocated for edges.
Declaration
public void TrimEdgeExcess()
TryGetEdge(TVertex, TVertex, out TEdge)
Tries to get the edge that link
source
and target
vertices.
Declaration
public bool TryGetEdge(TVertex source, TVertex target, out TEdge edge)
Parameters
Type | Name | Description |
---|---|---|
TVertex | source | Source vertex. |
TVertex | target | Target vertex. |
TEdge | edge | Edge found, otherwise null. |
Returns
Type | Description |
---|---|
System.Boolean | True if an edge was found, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
Events
| Improve this Doc View SourceEdgeAdded
Fired when an edge is added to this graph.
Declaration
public event EdgeAction<TVertex, TEdge> EdgeAdded
Event Type
Type | Description |
---|---|
EdgeAction<TVertex, TEdge> |
EdgeRemoved
Fired when an edge has been removed from this graph.
Declaration
public event EdgeAction<TVertex, TEdge> EdgeRemoved
Event Type
Type | Description |
---|---|
EdgeAction<TVertex, TEdge> |
VertexAdded
Fired when a vertex is added to this set.
Declaration
public event VertexAction<TVertex> VertexAdded
Event Type
Type | Description |
---|---|
VertexAction<TVertex> |
VertexRemoved
Fired when a vertex is removed from this set.
Declaration
public event VertexAction<TVertex> VertexRemoved
Event Type
Type | Description |
---|---|
VertexAction<TVertex> |
Explicit Interface Implementations
| Improve this Doc View SourceICloneable.Clone()
Declaration
object ICloneable.Clone()
Returns
Type | Description |
---|---|
System.Object |
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Declaration
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | |
System.Runtime.Serialization.StreamingContext | context |