New to Telerik UI for WPFStart a free 30-day trial

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:

C#
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: Graph<TNodeData, TLinkData>

Constructors

Initializes a new instance of the GraphBase<TNode, TLink> class.

C#
public GraphBase()

Initializes a new instance of the GraphBase<TNode, TLink> class.

C#
public GraphBase(GraphBase<TNode, TLink> graph)
Parameters:graphGraphBase<TNode, TLink>

The graph content to start with. Note that references will be added, not clones.

Properties

Gets whether the graph is acyclic.

C#
public bool IsAcyclic { get; }
Property Value:

true if this instance is acyclic; otherwise, false.

Remarks:

Gets whether this graph is connected. See also this article; http://en.wikipedia.org/wiki/Connected_graph.

C#
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.

Gets whether this graph is directed.

C#
public bool IsDirected { get; set; }

Gets whether the graph is hamiltonian.

C#
public bool IsHamiltonian { get; }
Property Value:

true if this instance is acyclic; otherwise, false.

Remarks:

IList<TLink>

Gets or sets the links of this graph.

C#
public IList<TLink> Links { get; protected set; }
Property Value:

The links collection.

Nodes

IList<TNode>

Gets or sets the nodes of this graph.

C#
public IList<TNode> Nodes { get; protected set; }
Property Value:

The nodes 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.

C#
public TLink AddLink(TLink link)
Parameters:linkTLink

The link to add.

Returns:

TLink

The added link.

Adds a link to this graph.

C#
public TLink AddLink(TNode source, TNode sink)
Parameters:sourceTNode

The source of the link.

sinkTNode

The sink of the link.

Returns:

TLink

The added link.

Adds the given node to the graph.

C#
public void AddNode(TNode node)
Parameters:nodeTNode

The node to add.

Adds a series of nodes to the graph.

C#
public void AddNodes(params TNode[] nodes)
Parameters:nodesTNode[]

The nodes.

Returns whether the given nodes are connected in one direction or the other.

C#
public bool AreConnected(int nodeId1, int nodeId2, bool strict = false)
Parameters:nodeId1int

The id of the first node.

nodeId2int

The id of the second node.

strictbool

If set to true the first node has to be the source of the link and the second the sink..

Returns:

bool

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.

Returns whether the given nodes are connected in one direction or the other.

C#
public bool AreConnected(TNode node1, TNode node2, bool strict = false)
Parameters:node1TNode

A node.

node2TNode

Another node.

strictbool

If set to true the first node has to be the source of the link and the second the sink..

Returns:

bool

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.

Returns whether the two nodes with specified ide's are the in same component.

C#
public bool AreInSameComponent(int id1, int id2)
Parameters:id1int

The id1.

id2int

The id2.

Returns:

bool

Assigns to each link and node an identifier based on their collection listIndex.

C#
public void AssignIdentifiers()

Clones this instance.

C#
public GraphBase<TNode, TLink> Clone()
Returns:

GraphBase<TNode, TLink>

Returns the shortest path between two nodes using the Dijkstra algorithm.

C#
public GraphPath<TNode, TLink> DijkstraShortestPath(int sourceId, int targetId)
Parameters:sourceIdint

From id.

targetIdint

To id.

Returns:

GraphPath<TNode, TLink>

Ensures that the graph nodes all have a unique identifier assigned.

C#
public void EnsureUniqueIdentifiers()
Remarks:

If the nodes do have unique identifiers nothing will be altered.

Finds the edge with the specified identifiers.

C#
public TLink FindEdge(int nodeId1, int nodeId2, bool strict)
Parameters:nodeId1int

The id of the source.

nodeId2int

The id of the sink.

strictbool

If set to true the found link has to go from nodeId1 to nodeId2.

Returns:

TLink

Finds the longest path in this (directed acyclic) graph.

C#
public GraphPath<TNode, TLink> FindLongestPath()
Returns:

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.

C#
public TNode FindNode(int id)
Parameters:idint

The id to look for.

Returns:

TNode

Attempts to find a tree root by looking at the longest paths in the graph.

C#
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.

Returns the bounding rectangle of this layout graph.

C#
public Rect GetBoundingRectangle<TNodeData, TLinkData>(bool includeLinks = false) where TNodeData : new() where TLinkData : new()
Parameters:includeLinksbool

The include Links.

Returns:

Rect

Returns the connected components of this graph.

C#
public IEnumerable<GraphBase<TNode, TLink>> GetConnectedComponents()
Returns:

IEnumerable<GraphBase<TNode, TLink>>

The list of connected components.

Gets the next identifier of the nodes sequence.

C#
public int GetNextIdInNodes(int id)
Parameters:idint

The id.

Returns:

int

Ensures the unique identifiers.

C#
public bool HaveUniqueIdentifiers()
Returns:

bool

Returns the number of (connected) components.

C#
public int NumberOfComponents()
Returns:

int

Returns the number of connected components.

C#
public int NumberOfComponents(out Dictionary<int, int> componentMap)
Parameters:componentMapDictionary<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:

int

Detaches all links from from the given node and removes them from the graph structure.

C#
public void RemoveAllLinksFrom(TNode node)
Parameters:nodeTNode

The node.

Removes the link from the graph.

C#
public void RemoveLink(TLink link)
Parameters:linkTLink

The link.

Removes the given node from this graph.

C#
public void RemoveNode(TNode node)
Parameters:nodeTNode

The node to remove.

Assigns a new identifier to the nodes.

C#
public void RenumberNodes(int startId = 0)
Parameters:startIdint

The number to start the numbering from.

Gets the shortest path lengths between each two vertices.

C#
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.

Returns a string representation of the incidence structure of this graph.

C#
public string ToLinkListString()
Returns:

string

Returns the links structure of this graph as a list of identifier tuples.

C#
public IList<string> ToLinksList()
Returns:

IList<string>

Is a linear ordering of its vertices.

C#
public IList<int> TopologicalSort(bool forceNewIdentifier = false)
Parameters:forceNewIdentifierboolReturns:

IList<int>

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.

Returns a string that represents this instance.

C#
public override string ToString()
Returns:

string

A string that represents this instance.

Overrides: object.ToString()