Class AdjacencyGraph<TVertex, TEdge>
Mutable directed graph data structure.
Inheritance
Implements
Inherited Members
Namespace: QuikGraph
Assembly: QuikGraph.dll
Syntax
[Serializable]
public class AdjacencyGraph<TVertex, TEdge> : IEdgeListAndIncidenceGraph<TVertex, TEdge>, IMutableVertexAndEdgeListGraph<TVertex, TEdge>, IMutableVertexListGraph<TVertex, TEdge>, IMutableIncidenceGraph<TVertex, TEdge>, IMutableVertexAndEdgeSet<TVertex, TEdge>, IMutableVertexSet<TVertex>, IMutableEdgeListGraph<TVertex, TEdge>, IMutableGraph<TVertex, TEdge>, IVertexAndEdgeListGraph<TVertex, TEdge>, IVertexListGraph<TVertex, TEdge>, IIncidenceGraph<TVertex, TEdge>, IImplicitGraph<TVertex, TEdge>, IEdgeListGraph<TVertex, TEdge>, IGraph<TVertex, TEdge>, IEdgeSet<TVertex, TEdge>, IVertexSet<TVertex>, IImplicitVertexSet<TVertex>, ICloneable where TEdge : IEdge<TVertex>
Type Parameters
Name | Description |
---|---|
TVertex | Vertex type. |
TEdge | Edge type |
Remarks
It is efficient for sparse graph representation where out-edge need to be enumerated only.
Constructors
| Improve this Doc View SourceAdjacencyGraph()
Initializes a new instance of the AdjacencyGraph<TVertex, TEdge> class.
Declaration
public AdjacencyGraph()
AdjacencyGraph(Boolean)
Initializes a new instance of the AdjacencyGraph<TVertex, TEdge> class.
Declaration
public AdjacencyGraph(bool allowParallelEdges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowParallelEdges | Indicates if parallel edges are allowed. |
AdjacencyGraph(Boolean, Int32)
Initializes a new instance of the AdjacencyGraph<TVertex, TEdge> class.
Declaration
public AdjacencyGraph(bool allowParallelEdges, int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowParallelEdges | Indicates if parallel edges are allowed. |
System.Int32 | capacity | Vertex capacity. |
AdjacencyGraph(Boolean, Int32, Int32)
Initializes a new instance of the AdjacencyGraph<TVertex, TEdge> class.
Declaration
public AdjacencyGraph(bool allowParallelEdges, int vertexCapacity, int edgeCapacity)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowParallelEdges | Indicates if parallel edges are allowed. |
System.Int32 | vertexCapacity | Vertex capacity. |
System.Int32 | edgeCapacity | Edge capacity. |
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 |
Edges
Gets the edges.
Declaration
public virtual IEnumerable<TEdge> Edges { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TEdge> |
EdgeType
Gets the type of edges.
Declaration
public Type EdgeType { get; }
Property Value
Type | Description |
---|---|
System.Type |
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 |
VertexType
Gets the type of vertices.
Declaration
public Type VertexType { get; }
Property Value
Type | Description |
---|---|
System.Type |
Vertices
Gets the vertices.
Declaration
public virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 |
|
Clear()
Clears the vertex and edges.
Declaration
public void Clear()
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 |
|
ClearOutEdges(TVertex)
Trims the out-edges of the given vertex
Declaration
public void ClearOutEdges(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Clone()
Clones this graph.
Declaration
public AdjacencyGraph<TVertex, TEdge> Clone()
Returns
Type | Description |
---|---|
AdjacencyGraph<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 |
|
IsOutEdgesEmpty(TVertex)
Determines whether there are out-edges associated to vertex
.
Declaration
public bool IsOutEdgesEmpty(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Boolean | True if |
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. |
OutDegree(TVertex)
Gets the count of out-edges of vertex
.
Declaration
public int OutDegree(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Int32 | The count of out-edges of |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
OutEdge(TVertex, Int32)
Gets the out-edge of vertex
at position index
.
Declaration
public TEdge OutEdge(TVertex vertex, int index)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
System.Int32 | index | The index. |
Returns
Type | Description |
---|---|
TEdge | The out-edge at position |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException | No vertex at |
VertexNotFoundException |
|
OutEdges(TVertex)
Gets the out-edges of vertex
.
Declaration
public virtual IEnumerable<TEdge> OutEdges(TVertex vertex)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TEdge> | An enumeration of the out-edges of |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
VertexNotFoundException |
|
RemoveEdge(TEdge)
Removes the edge
from this graph.
Declaration
public virtual 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 |
|
RemoveOutEdgeIf(TVertex, EdgePredicate<TVertex, TEdge>)
Removes all out-edges of the vertex
where the predicate
is evaluated to true.
Declaration
public int RemoveOutEdgeIf(TVertex vertex, EdgePredicate<TVertex, TEdge> predicate)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
EdgePredicate<TVertex, TEdge> | predicate | Predicate to remove edges. |
Returns
Type | Description |
---|---|
System.Int32 | The number of removed edges. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
RemoveVertex(TVertex)
Removes the given vertex from this set.
Declaration
public virtual 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 |
|
TryGetEdges(TVertex, TVertex, out IEnumerable<TEdge>)
Tries to get edges that link
source
and target
vertices.
Declaration
public virtual bool TryGetEdges(TVertex source, TVertex target, out IEnumerable<TEdge> edges)
Parameters
Type | Name | Description |
---|---|---|
TVertex | source | Source vertex. |
TVertex | target | Target vertex. |
System.Collections.Generic.IEnumerable<TEdge> | edges | Edges found, otherwise null. |
Returns
Type | Description |
---|---|
System.Boolean | True if at least an edge was found, false otherwise. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
TryGetOutEdges(TVertex, out IEnumerable<TEdge>)
Tries to get the out-edges of vertex
.
Declaration
public virtual bool TryGetOutEdges(TVertex vertex, out IEnumerable<TEdge> edges)
Parameters
Type | Name | Description |
---|---|---|
TVertex | vertex | The vertex. |
System.Collections.Generic.IEnumerable<TEdge> | edges | Out-edges. |
Returns
Type | Description |
---|---|
System.Boolean | True if |
Exceptions
Type | Condition |
---|---|
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 |