Class GraphExtensions
The static graph-analysis related extensions.
Inheritance
Namespace: Telerik.Windows.Diagrams.Core
Assembly: Telerik.Windows.Diagrams.Core.dll
Syntax
public static class GraphExtensions : Object
Methods
AssignLevel<TLinkData>(Graph<TreeLayoutData, TLinkData>, Node<TreeLayoutData, TLinkData>, Dictionary<Node<TreeLayoutData, TLinkData>, Boolean>, Int32)
Assigns tree-levels to the nodes.
Declaration
public static void AssignLevel<TLinkData>(this Graph<TreeLayoutData, TLinkData> graph, Node<TreeLayoutData, TLinkData> startNode, Dictionary<Node<TreeLayoutData, TLinkData>, bool> visited = null, int offset = 0)
where TLinkData : new()
Parameters
Graph<Tree The graph. |
Node<Tree The start node. |
System. The nodes which have already been visited. |
System. The offset. |
Type Parameters
TLinkData
The type of the link data. |
BreadthFirstSearch<TNode, TLink>(GraphBase<TNode, TLink>, Func<TNode, Boolean>, TNode)
Performs a BFT of the given graph starting at the given node and stops when the first node matching the condition is found.
Declaration
public static TNode BreadthFirstSearch<TNode, TLink>(this GraphBase<TNode, TLink> graph, Func<TNode, bool> condition, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph to traverse. |
System. The condition a node has to satisfy to be return and thus halt the traversal. |
TNode
startNode
The start node. |
Returns
TNode
|
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode>, TNode)
Performs a breadth-first traversal of the graph starting at the given node.
Declaration
public static void BreadthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, Action<TNode> action, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph to traverse. |
System. The action acting a the visited node. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IVisitor<TNode>, TNode)
Performs a breadth-first traversal of the graph starting at the given node.
Declaration
public static void BreadthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, IVisitor<TNode> visitor, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph to traverse. |
IVisitor<TNode>
visitor
The visitor traversing the graph. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
Clone<TNodeData, TLinkData>(IEnumerable<Edge<TNodeData, TLinkData>>)
Returns a shallow clone from the given collection.
Declaration
public static IList<Edge<TNodeData, TLinkData>> Clone<TNodeData, TLinkData>(this IEnumerable<Edge<TNodeData, TLinkData>> list)
where TNodeData : new()
where TLinkData : new()
Parameters
System. The collection to clone. |
Returns
System.
|
Type Parameters
TNodeData
The node data type. |
TLinkData
The link data type. |
CreateArray(Int32, Int32)
Returns an array of the specified size.
Declaration
public static int[] CreateArray(int size, int value)
Parameters
System. The size. |
System. The Graph value of the elements in the array. |
Returns
System.
|
CreateArray(Int32, Int32, Int32)
Returns an array of the specified size.
Declaration
public static int[, ] CreateArray(int dim1, int dim2, int value)
Parameters
System. The first dimension. |
System. The second dimension. |
System. The Graph value of the elements. |
Returns
System.
|
CreateBalancedForest(Int32, Int32, Int32)
Creates a forest of balanced trees.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedForest(int levels = 4, int siblingsCount = 2, int treeCount = 5)
Parameters
System. The levels. |
System. The siblings count. |
System. The tree count. |
Returns
CreateBalancedTree(Int32, Int32)
Creates a balanced tree.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedTree(int levels = 3, int siblingsCount = 3)
Parameters
System. The levels. |
System. The siblings count. |
Returns
CreateBiDictionary<TNode, TLink>(GraphBase<TNode, TLink>, Int32)
Creates a bi-directional dictionary with keys equal to the (supposedly unique) identifiers and value equal to the provided initial value.
Declaration
public static Dictionary<Tuple<TNode, TNode>, int> CreateBiDictionary<TNode, TLink>(this GraphBase<TNode, TLink> graph, int value)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
System. The value. |
Returns
System.
|
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
CreateComponents(Int32)
Creates a random graph with a specified amounts of components.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> CreateComponents(int numberOfComponent)
Parameters
System. The number of component. |
Returns
CreateDictionary<TNode, TLink>(GraphBase<TNode, TLink>, Int32)
Creates a dictionary with keys equal to the (supposedly unique) identifiers and value equal to the provided initial value.
Declaration
public static Dictionary<int, int> CreateDictionary<TNode, TLink>(this GraphBase<TNode, TLink> graph, int value)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
System. The value. |
Returns
System.
|
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
CreateRandomConnectedGraph(Int32, Int32, Boolean)
Creates a random connected graph.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomConnectedGraph(int nodesCount, int maxIncidence = 4, bool tree = false)
Parameters
System. The nodes count. |
System. The max incidence. |
System. If set to |
Returns
CreateRandomGraph(Int32, Int32, Boolean)
Creates a random graph.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomGraph(int nodesCount = 150, int maxIncidence = 4, bool tree = false)
Parameters
System. The count. |
System. The maximum incidence of each node. |
System. If set to |
Returns
DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode, Int32>, TNode)
Performs a depth-first traversal of the graph starting at the given node.
Declaration
public static void DepthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, Action<TNode, int> action, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
System. The action. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode>, TNode)
Performs a depth-first traversal of the graph starting at the given node.
Declaration
public static void DepthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, Action<TNode> action, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
System. The action. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IDepthVisitor<TNode>, TNode)
Performs a depth-first traversal of the graph starting at the given node.
Declaration
public static void DepthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, IDepthVisitor<TNode> visitor, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
IDepth The visitor. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IVisitor<TNode>, TNode)
Performs a depth-first traversal of the graph starting at the given node.
Declaration
public static void DepthFirstTraversal<TNode, TLink>(this GraphBase<TNode, TLink> graph, IVisitor<TNode> visitor, TNode startNode)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph to traverse. |
IVisitor<TNode>
visitor
The visitor. |
TNode
startNode
The start node. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
FindCycles<TNode, TLink>(GraphBase<TNode, TLink>, Boolean)
Finds cycles in a graph using Tarjan strongly connected components algorithm.
Declaration
public static IList<TNode[]> FindCycles<TNode, TLink>(this GraphBase<TNode, TLink> graph, bool excludeSingleItems = true)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
System. If set to |
Returns
System. A list of of vertex arrays (paths) that form cycles in the graph. |
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
HasIdenticalStructureWith(GraphBase<Node<Object, Object>, Edge<Object, Object>>, GraphBase<Node<Object, Object>, Edge<Object, Object>>)
Compares the two graph and assert they are identical.
Declaration
public static bool HasIdenticalStructureWith(this GraphBase<Node<object, object>, Edge<object, object>> graph1, GraphBase<Node<object, object>, Edge<object, object>> graph2)
Parameters
Graph
|
Graph
|
Returns
System.
|
KruskalsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>)
Kruskal algorithm.
Declaration
public static GraphBase<TNode, TLink> KruskalsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink> graph)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph. |
Returns
Graph
|
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
See Also
Merge(GraphBase<Node<Object, Object>, Edge<Object, Object>>, GraphBase<Node<Object, Object>, Edge<Object, Object>>)
Merges the given graph into the current graph.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> Merge(this GraphBase<Node<object, object>, Edge<object, object>> graph, GraphBase<Node<object, object>, Edge<object, object>> otherGraph)
Parameters
Graph The graph. |
Graph The graph to merge into the current one. |
Returns
MoveGraph<TNodeData, TLinkData>(GraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>>, Double, Double)
Offsets the specified graph.
Declaration
public static void MoveGraph<TNodeData, TLinkData>(this GraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>> layoutGraph, double offsetX, double offsetY)
where TNodeData : new()
where TLinkData : new()
Parameters
Graph The layout Graph. |
System. The horizontal offset. |
System. The vertical offset. |
Type Parameters
TNodeData
The node data type. |
TLinkData
The link data type. |
MoveLink<TNodeData, TLinkData>(Edge<TNodeData, TLinkData>, Point)
Moves link.
Declaration
public static void MoveLink<TNodeData, TLinkData>(this Edge<TNodeData, TLinkData> edge, Point point)
where TNodeData : new()
where TLinkData : new()
Parameters
Edge<TNodeData, TLinkData>
edge
The layout link. |
System. The delta to move. |
Type Parameters
TNodeData
The node data type. |
TLinkData
The link data type. |
Offset(Rect, Double, Double)
Offsets the given rectangle.
Declaration
public static Rect Offset(this Rect rect, double x, double y)
Parameters
System. The rectangle. |
System. The horizontal offset. |
System. The vertical offset. |
Returns
System.
|
Parse(IEnumerable<String>)
Parses the specified list representing the incidence structure of a graph.
Declaration
public static GraphBase<Node<object, object>, Edge<object, object>> Parse(IEnumerable<string> list)
Parameters
System. The list of link couples. |
Returns
Position(Rect)
Returns the position of the given rectangle.
Declaration
public static Point Position(this Rect rect)
Parameters
System. The rectangle. |
Returns
System.
|
PrimsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>, TNode, Boolean)
Prim's algorithm finds a minimum-cost spanning tree of an edge-weighted, connected, undirected graph.
Declaration
public static GraphBase<TNode, TLink> PrimsSpanningTree<TNode, TLink>(this GraphBase<TNode, TLink> graph, TNode fromNode, bool reverseWrongEdges = false)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
Graph The graph structure. |
TNode
fromNode
The node to start from. |
System. If set to |
Returns
Graph
|
Type Parameters
TNode
The type of the node. |
TLink
The type of the link. |
Remarks
Split<TNodeData, TLinkData>(Graph<TNodeData, TLinkData>)
Splits the given, not necessarily connected, graph into its connected components.
Declaration
public static IEnumerable<Graph<TNodeData, TLinkData>> Split<TNodeData, TLinkData>(this Graph<TNodeData, TLinkData> graph)
where TNodeData : new()
where TLinkData : new()
Parameters
Graph<TNodeData, TLinkData>
graph
The graph to be split. |
Returns
System.
|
Type Parameters
TNodeData
The node data type. |
TLinkData
The link data type. |
TakeRandomNode(GraphBase<Node<Object, Object>, Edge<Object, Object>>, Node<Object, Object>, Int32)
Takes a random node with incidence less than specified.
Declaration
public static Node<object, object> TakeRandomNode(this GraphBase<Node<object, object>, Edge<object, object>> graph, Node<object, object> node = null, int incidenceLessThan = 4)
Parameters
Graph The graph. |
Node<System. The node which should not be returned; i.e. the random node should be in the complement of the given node. |
System. The incidence less than. |
Returns
Node<System.
|
TakeTwoRandomNodes(GraphBase<Node<Object, Object>, Edge<Object, Object>>)
Takes two random nodes from the given graph.
Declaration
public static Tuple<Node<object, object>, Node<object, object>> TakeTwoRandomNodes(this GraphBase<Node<object, object>, Edge<object, object>> graph)
Parameters
Returns
TarjansStronglyConnectedComponentsAlgorithm<TNode, TLink>(Boolean, TNode, IDictionary<TNode, Int32>, IDictionary<TNode, Int32>, ICollection<TNode[]>, Stack<TNode>, Int32)
Executes Tarjan algorithm on the graph.
Declaration
public static void TarjansStronglyConnectedComponentsAlgorithm<TNode, TLink>(bool excludeSingleItems, TNode node, IDictionary<TNode, int> indices, IDictionary<TNode, int> lowLinks, ICollection<TNode[]> connected, Stack<TNode> stack, int index)
where TNode : class, INode<TNode, TLink>, new()
where TLink : class, IEdge<TNode, TLink>, new()
Parameters
System. If set to |
TNode
node
The node to start with. |
System. The current indices. |
System. The current low links. |
System. The connected components. |
System. The stack. |
System. The current index. |
Type Parameters
TNode
The node data type. |
TLink
The link data type. |
Remarks
UnionEmptyRects(Rect, Rect)
If the first supplied rectangle has width or height zero the second rectangle will be returned. Otherwise the standard union of two rectangles will be used.
Declaration
public static Rect UnionEmptyRects(Rect rect1, Rect rect2)
Parameters
System. A rectangle. |
System. Another rectangle. |
Returns
System.
|