Class
GraphBase<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:

cs-api-definition
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

GraphBase()

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

Declaration

cs-api-definition
public GraphBase()

GraphBase(GraphBase<TNode, TLink>)

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

Declaration

cs-api-definition
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

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
public bool IsAcyclic { get; }

Property Value

bool

true if this instance is acyclic; otherwise, false.

Remarks

IsConnected

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

Declaration

cs-api-definition
public bool IsConnected { get; }

Property Value

bool

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.

Declaration

cs-api-definition
public bool IsDirected { get; set; }

Property Value

bool

IsHamiltonian

Gets whether the graph is hamiltonian.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
public bool IsHamiltonian { get; }

Property Value

bool

true if this instance is acyclic; otherwise, false.

Remarks

Gets or sets the links of this graph.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<TLink> Links { get; protected set; }

Property Value

IList<TLink>

The links collection.

Nodes

Gets or sets the nodes of this graph.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<TNode> Nodes { get; protected set; }

Property Value

IList<TNode>

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.

Declaration

cs-api-definition
public TLink AddLink(TLink link)

Parameters

link

TLink

The link to add.

Returns

TLink

The added link.

Adds a link to this graph.

Declaration

cs-api-definition
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

cs-api-definition
public void AddNode(TNode node)

Parameters

node

TNode

The node to add.

AddNodes(params TNode[])

Adds a series of nodes to the graph.

Declaration

cs-api-definition
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

cs-api-definition
public bool AreConnected(TNode node1, TNode node2, bool strict = false)

Parameters

node1

TNode

A node.

node2

TNode

Another node.

strict

bool

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.

AreConnected(int, int, bool)

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

Declaration

cs-api-definition
public bool AreConnected(int nodeId1, int nodeId2, bool strict = false)

Parameters

nodeId1

int

The id of the first node.

nodeId2

int

The id of the second node.

strict

bool

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.

AreInSameComponent(int, int)

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

Declaration

cs-api-definition
public bool AreInSameComponent(int id1, int id2)

Parameters

id1

int

The id1.

id2

int

The id2.

Returns

bool

AssignIdentifiers()

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

Declaration

cs-api-definition
public void AssignIdentifiers()

Clone()

Clones this instance.

Declaration

cs-api-definition
public GraphBase<TNode, TLink> Clone()

Returns

GraphBase<TNode, TLink>

DijkstraShortestPath(int, int)

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

Declaration

cs-api-definition
public GraphPath<TNode, TLink> DijkstraShortestPath(int sourceId, int targetId)

Parameters

sourceId

int

From id.

targetId

int

To id.

Returns

GraphPath<TNode, TLink>

EnsureUniqueIdentifiers()

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

Declaration

cs-api-definition
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.

Declaration

cs-api-definition
public TLink FindEdge(int nodeId1, int nodeId2, bool strict)

Parameters

nodeId1

int

The id of the source.

nodeId2

int

The id of the sink.

strict

bool

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

Returns

TLink

FindLongestPath()

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

Declaration

cs-api-definition
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

cs-api-definition
public TNode FindNode(int id)

Parameters

id

int

The id to look for.

Returns

TNode

FindTreeRoot()

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

Declaration

cs-api-definition
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

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public Rect GetBoundingRectangle<TNodeData, TLinkData>(bool includeLinks = false) where TNodeData : new() where TLinkData : new()

Parameters

includeLinks

bool

The include Links.

Returns

Rect

GetConnectedComponents()

Returns the connected components of this graph.

Declaration

cs-api-definition
[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.

Declaration

cs-api-definition
public int GetNextIdInNodes(int id)

Parameters

id

int

The id.

Returns

int

HaveUniqueIdentifiers()

Ensures the unique identifiers.

Declaration

cs-api-definition
public bool HaveUniqueIdentifiers()

Returns

bool

NumberOfComponents()

Returns the number of (connected) components.

Declaration

cs-api-definition
public int NumberOfComponents()

Returns

int

NumberOfComponents(out Dictionary<int, int>)

Returns the number of connected components.

Declaration

cs-api-definition
[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

int

RemoveAllLinksFrom(TNode)

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

Declaration

cs-api-definition
public void RemoveAllLinksFrom(TNode node)

Parameters

node

TNode

The node.

Removes the link from the graph.

Declaration

cs-api-definition
public void RemoveLink(TLink link)

Parameters

link

TLink

The link.

RemoveNode(TNode)

Removes the given node from this graph.

Declaration

cs-api-definition
public void RemoveNode(TNode node)

Parameters

node

TNode

The node to remove.

RenumberNodes(int)

Assigns a new identifier to the nodes.

Declaration

cs-api-definition
public void RenumberNodes(int startId = 0)

Parameters

startId

int

The number to start the numbering from.

ShortestPaths()

Gets the shortest path lengths between each two vertices.

Declaration

cs-api-definition
[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.

Declaration

cs-api-definition
public string ToLinkListString()

Returns

string

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

Declaration

cs-api-definition
public IList<string> ToLinksList()

Returns

IList<string>

ToString()

Returns a string that represents this instance.

Declaration

cs-api-definition
public override string ToString()

Returns

string

A string that represents this instance.

Overrides object.ToString()

TopologicalSort(bool)

Is a linear ordering of its vertices.

Declaration

cs-api-definition
public IList<int> TopologicalSort(bool forceNewIdentifier = false)

Parameters

forceNewIdentifier

bool

Returns

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.