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
Initializes a new instance of the GraphBase<TNode, TLink> class.
public GraphBase()
Properties
Gets whether the graph is acyclic.
public bool IsAcyclic { get; }
true if this instance is acyclic; otherwise, false.
- 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 .
Gets whether this graph is connected. See also this article; http://en.wikipedia.org/wiki/Connected_graph.
public bool IsConnected { get; }
true if this instance is connected; otherwise, false.
A graph is connected if every two vertices are connected by a path. A connected graph has only one component.
Gets whether this graph is directed.
public bool IsDirected { get; set; }
Gets whether the graph is hamiltonian.
public bool IsHamiltonian { get; }
true if this instance is acyclic; otherwise, false.
- 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 .
Gets or sets the links of this graph.
public IList<TLink> Links { get; protected set; }
The links collection.
Methods
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.
public TLink AddLink(TLink link)
The link to add.
Returns:TLink
The added link.
Adds a link to this graph.
public TLink AddLink(TNode source, TNode sink)
The source of the link.
sinkTNodeThe sink of the link.
Returns:TLink
The added link.
Adds the given node to the graph.
public void AddNode(TNode node)
The node to add.
Adds a series of nodes to the graph.
public void AddNodes(params TNode[] nodes)
The nodes.
Returns whether the given nodes are connected in one direction or the other.
public bool AreConnected(int nodeId1, int nodeId2, bool strict = false)
The id of the first node.
nodeId2intThe id of the second node.
strictboolIf set to true the first node has to be the source of the link and the second the sink..
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.
Because the structure allows multigraphs the connectedness means there is at least one link between the given nodes.
Returns whether the given nodes are connected in one direction or the other.
public bool AreConnected(TNode node1, TNode node2, bool strict = false)
A node.
node2TNodeAnother node.
strictboolIf set to true the first node has to be the source of the link and the second the sink..
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.
Because the structure allows multigraphs the connectedness means there is at least one link between the given nodes.
Assigns to each link and node an identifier based on their collection listIndex.
public void AssignIdentifiers()
Clones this instance.
Ensures that the graph nodes all have a unique identifier assigned.
public void EnsureUniqueIdentifiers()
If the nodes do have unique identifiers nothing will be altered.
Finds the longest path in this (directed acyclic) graph.
public GraphPath<TNode, TLink> FindLongestPath()
GraphPath<TNode, TLink>
A list of identifiers corresponding to the path, or null if the graph has cycles.
Finds the node with the specified identifier.
Attempts to find a tree root by looking at the longest paths in the graph.
public TNode FindTreeRoot()
TNode
A tree root or null is none was found.
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.
Returns the bounding rectangle of this layout graph.
public Rect GetBoundingRectangle<TNodeData, TLinkData>(bool includeLinks = false) where TNodeData : new() where TLinkData : new()
The include Links.
Returns:Rect
Returns the connected components of this graph.
public IEnumerable<GraphBase<TNode, TLink>> GetConnectedComponents()
IEnumerable<GraphBase<TNode, TLink>>
The list of connected components.
Ensures the unique identifiers.
Returns the number of (connected) components.
Returns the number of connected components.
public int NumberOfComponents(out Dictionary<int, int> componentMap)
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:Detaches all links from from the given node and removes them from the graph structure.
public void RemoveAllLinksFrom(TNode node)
The node.
Removes the link from the graph.
public void RemoveLink(TLink link)
The link.
Removes the given node from this graph.
public void RemoveNode(TNode node)
The node to remove.
Assigns a new identifier to the nodes.
public void RenumberNodes(int startId = 0)
The number to start the numbering from.
Gets the shortest path lengths between each two vertices.
public Dictionary<Tuple<TNode, TNode>, int> ShortestPaths()
Dictionary<Tuple<TNode, TNode>, int>
A dictionary keyed with the node id's and value equal to the path lengths.
Returns a string representation of the incidence structure of this graph.
Is a linear ordering of its vertices.
public IList<int> TopologicalSort(bool forceNewIdentifier = false)
The topologically sorted sequence of node identifiers or null is the graph has cycles.
- The sorting is not unique.
- The graph has to be acyclic in order to have a topological sort.
- The sorting works on disconnected graphs.