ClassGraphBase<TNode, TLink>
Base graph class for the various incarnations in the graph analysis.
Definition
Namespace:Telerik.Windows.Diagrams.Core
Assembly:Telerik.Windows.Diagrams.Core.dll
Type Parameters:
TNode
The data type of the node which should be an implementation of the INode<TNode, TLink> interface and have a parameterless constructor.
TLink
The data type of the edge which should be an implementation of the IEdge<TNode, TLink> interface and have a parameterless constructor.
Syntax:
public class GraphBase<TNode, TLink> where TNode : class, INode<TNode, TLink>, new() where TLink : class, IEdge<TNode, TLink>, new()
Inheritance: objectGraphBase<TNode, TLink>
Derived Classes:
Constructors
GraphBase()
Initializes a new instance of the GraphBase<TNode, TLink> class.
Declaration
public GraphBase()
GraphBase(GraphBase<TNode, TLink>)
Initializes a new instance of the GraphBase<TNode, TLink> class.
Declaration
public GraphBase(GraphBase<TNode, TLink> graph)
Parameters
graph
GraphBase<TNode, TLink>
The graph content to start with. Note that references will be added, not clones.
Properties
IsAcyclic
Gets whether the graph is acyclic.
Declaration
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
public bool IsAcyclic { get; }
Property Value
true if this instance is acyclic; otherwise, false.
Remarks
- If there are no cycles in a graph it's acyclic. A cycle means a closed path or loop.
- See also the article; http://en.wikipedia.org/wiki/Directed_acyclic_graph .
IsConnected
Gets whether this graph is connected. See also this article; http://en.wikipedia.org/wiki/Connected_graph.
Declaration
public bool IsConnected { get; }
Property Value
true if this instance is connected; otherwise, false.
Remarks
A graph is connected if every two vertices are connected by a path. A connected graph has only one component.
IsDirected
Gets whether this graph is directed.
IsHamiltonian
Gets whether the graph is hamiltonian.
Declaration
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
public bool IsHamiltonian { get; }
Property Value
true if this instance is acyclic; otherwise, false.
Remarks
- An Hamiltonian cycle is a cycle which contains all nodes of the graph. If there is at least one such cycle the graph is called Hamiltonian.
- See also the article http://en.wikipedia.org/wiki/Hamiltonian_graph .
Methods
AddLink(TLink)
Adds the given link to the graph. It will add the sink and source nodes to the Nodes collection if they are not yet part of it.
Declaration
public TLink AddLink(TLink link)
Parameters
link
TLink
The link to add.
Returns
TLink
The added link.
AddLink(TNode, TNode)
Adds a link to this graph.
Declaration
public TLink AddLink(TNode source, TNode sink)
Parameters
source
TNode
The source of the link.
sink
TNode
The sink of the link.
Returns
TLink
The added link.
AddNode(TNode)
Adds the given node to the graph.
Declaration
public void AddNode(TNode node)
Parameters
node
TNode
The node to add.
AddNodes(params TNode[])
Adds a series of nodes to the graph.
Declaration
public void AddNodes(params TNode[] nodes)
Parameters
nodes
TNode[]
The nodes.
AreConnected(TNode, TNode, bool)
Returns whether the given nodes are connected in one direction or the other.
Declaration
public bool AreConnected(TNode node1, TNode node2, bool strict = false)
Parameters
node1
TNode
A node.
node2
TNode
Another node.
strict
If set to true the first node has to be the source of the link and the second the sink..
Returns
true If there is a link connecting the given nodes with the first one as source and the second as sink, false if both options have to be considered.
Remarks
Because the structure allows multigraphs the connectedness means there is at least one link between the given nodes.
AreConnected(int, int, bool)
Returns whether the given nodes are connected in one direction or the other.
Declaration
public bool AreConnected(int nodeId1, int nodeId2, bool strict = false)
Parameters
nodeId1
The id of the first node.
nodeId2
The id of the second node.
strict
If set to true the first node has to be the source of the link and the second the sink..
Returns
true If there is a link connecting the given nodes with the first one as source and the second as sink, false if both options have to be considered.
Remarks
Because the structure allows multigraphs the connectedness means there is at least one link between the given nodes.
AreInSameComponent(int, int)
Returns whether the two nodes with specified ide's are the in same component.
AssignIdentifiers()
Assigns to each link and node an identifier based on their collection listIndex.
Declaration
public void AssignIdentifiers()
Clone()
Clones this instance.
Declaration
public GraphBase<TNode, TLink> Clone()
Returns
GraphBase<TNode, TLink>
DijkstraShortestPath(int, int)
Returns the shortest path between two nodes using the Dijkstra algorithm.
EnsureUniqueIdentifiers()
Ensures that the graph nodes all have a unique identifier assigned.
Declaration
public void EnsureUniqueIdentifiers()
Remarks
If the nodes do have unique identifiers nothing will be altered.
FindEdge(int, int, bool)
Finds the edge with the specified identifiers.
FindLongestPath()
Finds the longest path in this (directed acyclic) graph.
Declaration
public GraphPath<TNode, TLink> FindLongestPath()
Returns
GraphPath<TNode, TLink>
A list of identifiers corresponding to the path, or null if the graph has cycles.
FindNode(int)
Finds the node with the specified identifier.
Declaration
public TNode FindNode(int id)
Parameters
id
The id to look for.
Returns
TNode
FindTreeRoot()
Attempts to find a tree root by looking at the longest paths in the graph.
Declaration
public TNode FindTreeRoot()
Returns
TNode
A tree root or null is none was found.
Remarks
The algorithms looks for all shortest paths between all vertices, which means it will also function for disconnected graphs but will return the root of the tree with longest path.
GetBoundingRectangle<TNodeData, TLinkData>(bool)
Returns the bounding rectangle of this layout graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public Rect GetBoundingRectangle<TNodeData, TLinkData>(bool includeLinks = false) where TNodeData : new() where TLinkData : new()
Parameters
includeLinks
The include Links.
Returns
Rect
GetConnectedComponents()
Returns the connected components of this graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public IEnumerable<GraphBase<TNode, TLink>> GetConnectedComponents()
Returns
IEnumerable<GraphBase<TNode, TLink>>
The list of connected components.
GetNextIdInNodes(int)
Gets the next identifier of the nodes sequence.
HaveUniqueIdentifiers()
Ensures the unique identifiers.
NumberOfComponents()
Returns the number of (connected) components.
NumberOfComponents(out Dictionary<int, int>)
Returns the number of connected components.
Declaration
[SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public int NumberOfComponents(out Dictionary<int, int> componentMap)
Parameters
componentMap
Dictionary<int, int>
The component map as a dictionary where the key is the node identifier and the value is the number of the connected component to which the node belongs.
Returns
RemoveAllLinksFrom(TNode)
Detaches all links from from the given node and removes them from the graph structure.
Declaration
public void RemoveAllLinksFrom(TNode node)
Parameters
node
TNode
The node.
RemoveLink(TLink)
Removes the link from the graph.
Declaration
public void RemoveLink(TLink link)
Parameters
link
TLink
The link.
RemoveNode(TNode)
Removes the given node from this graph.
Declaration
public void RemoveNode(TNode node)
Parameters
node
TNode
The node to remove.
RenumberNodes(int)
Assigns a new identifier to the nodes.
Declaration
public void RenumberNodes(int startId = 0)
Parameters
startId
The number to start the numbering from.
ShortestPaths()
Gets the shortest path lengths between each two vertices.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public Dictionary<Tuple<TNode, TNode>, int> ShortestPaths()
Returns
Dictionary<Tuple<TNode, TNode>, int>
A dictionary keyed with the node id's and value equal to the path lengths.
ToLinkListString()
Returns a string representation of the incidence structure of this graph.
ToLinksList()
Returns the links structure of this graph as a list of identifier tuples.
ToString()
Returns a string that represents this instance.
TopologicalSort(bool)
Is a linear ordering of its vertices.
Declaration
public IList<int> TopologicalSort(bool forceNewIdentifier = false)
Parameters
forceNewIdentifier
Returns
The topologically sorted sequence of node identifiers or null is the graph has cycles.
Remarks
- The sorting is not unique.
- The graph has to be acyclic in order to have a topological sort.
- The sorting works on disconnected graphs.