ClassGraphExtensions
The static graph-analysis related extensions.
Definition
Namespace:Telerik.Windows.Diagrams.Core
Assembly:Telerik.Windows.Diagrams.Core.dll
Syntax:
public static class GraphExtensions
Inheritance: objectGraphExtensions
Methods
AssignLevel<TLinkData>(Graph<TreeLayoutData, TLinkData>, Node<TreeLayoutData, TLinkData>, Dictionary<Node<TreeLayoutData, TLinkData>, bool>, int)
Assigns tree-levels to the nodes.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")]
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
Graph<TreeLayoutData, TLinkData>
The graph.
startNode
Node<TreeLayoutData, TLinkData>
The start node.
visited
Dictionary<Node<TreeLayoutData, TLinkData>, bool>
The nodes which have already been visited.
offset
The offset.
BreadthFirstSearch<TNode, TLink>(GraphBase<TNode, TLink>, Func<TNode, bool>, 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
GraphBase<TNode, TLink>
The graph to traverse.
condition
The condition a node has to satisfy to be return and thus halt the traversal.
startNode
TNode
The start node.
Returns
TNode
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
GraphBase<TNode, TLink>
The graph to traverse.
action
Action<TNode>
The action acting a the visited node.
startNode
TNode
The start node.
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
GraphBase<TNode, TLink>
The graph to traverse.
visitor
IVisitor<TNode>
The visitor traversing the graph.
startNode
TNode
The start node.
Remarks
Clone<TNodeData, TLinkData>(IEnumerable<Edge<TNodeData, TLinkData>>)
Returns a shallow clone from the given collection.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static IList<Edge<TNodeData, TLinkData>> Clone<TNodeData, TLinkData>(this IEnumerable<Edge<TNodeData, TLinkData>> list) where TNodeData : new() where TLinkData : new()
Parameters
list
IEnumerable<Edge<TNodeData, TLinkData>>
The collection to clone.
Returns
CreateArray(int, int)
Returns an array of the specified size.
CreateArray(int, int, int)
Returns an array of the specified size.
CreateBalancedForest(int, int, int)
Creates a forest of balanced trees.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedForest(int levels = 4, int siblingsCount = 2, int treeCount = 5)
Parameters
levels
The levels.
siblingsCount
The siblings count.
treeCount
The tree count.
Returns
CreateBalancedTree(int, int)
Creates a balanced tree.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedTree(int levels = 3, int siblingsCount = 3)
Parameters
levels
The levels.
siblingsCount
The siblings count.
Returns
CreateBiDictionary<TNode, TLink>(GraphBase<TNode, TLink>, int)
Creates a bi-directional dictionary with keys equal to the (supposedly unique) identifiers and value equal to the provided initial value.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly")]
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
GraphBase<TNode, TLink>
The graph.
value
The value.
Returns
Dictionary<Tuple<TNode, TNode>, int>
CreateComponents(int)
Creates a random graph with a specified amounts of components.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateComponents(int numberOfComponent)
Parameters
numberOfComponent
The number of component.
Returns
CreateDictionary<TNode, TLink>(GraphBase<TNode, TLink>, int)
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
GraphBase<TNode, TLink>
The graph.
value
The value.
Returns
Dictionary<int, int>
CreateRandomConnectedGraph(int, int, bool)
Creates a random connected graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomConnectedGraph(int nodesCount, int maxIncidence = 4, bool tree = false)
Parameters
nodesCount
The nodes count.
maxIncidence
The max incidence.
tree
If set to true the random graph will be effectively a tree.
Returns
CreateRandomGraph(int, int, bool)
Creates a random graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomGraph(int nodesCount = 150, int maxIncidence = 4, bool tree = false)
Parameters
nodesCount
The count.
maxIncidence
The maximum incidence of each node.
tree
If set to true the generated graph will be a tree.
Returns
DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode, int>, 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
GraphBase<TNode, TLink>
The graph.
action
The action.
startNode
TNode
The start node.
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
GraphBase<TNode, TLink>
The graph.
action
Action<TNode>
The action.
startNode
TNode
The start node.
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
GraphBase<TNode, TLink>
The graph.
visitor
IDepthVisitor<TNode>
The visitor.
startNode
TNode
The start node.
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
GraphBase<TNode, TLink>
The graph to traverse.
visitor
IVisitor<TNode>
The visitor.
startNode
TNode
The start node.
Remarks
FindCycles<TNode, TLink>(GraphBase<TNode, TLink>, bool)
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
GraphBase<TNode, TLink>
The graph.
excludeSingleItems
If set to true nodes with no edges are excluded.
Returns
IList<TNode[]>
A list of of vertex arrays (paths) that form cycles in the graph.
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
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static bool HasIdenticalStructureWith(this GraphBase<Node<object, object>, Edge<object, object>> graph1, GraphBase<Node<object, object>, Edge<object, object>> graph2)
Parameters
graph1
GraphBase<Node<object, object>, Edge<object, object>>
graph2
Returns
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
GraphBase<TNode, TLink>
The graph.
Returns
GraphBase<TNode, TLink>
Remarks
Merge(GraphBase<Node<object, object>, Edge<object, object>>, GraphBase<Node<object, object>, Edge<object, object>>)
Merges the given graph into the current graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
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
GraphBase<Node<object, object>, Edge<object, object>>
The graph.
otherGraph
GraphBase<Node<object, object>, Edge<object, object>>
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
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
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
layoutGraph
GraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>>
The layout Graph.
offsetX
The horizontal offset.
offsetY
The vertical offset.
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
Edge<TNodeData, TLinkData>
The layout link.
point
Point
The delta to move.
Offset(Rect, double, double)
Offsets the given rectangle.
Parse(IEnumerable<string>)
Parses the specified list representing the incidence structure of a graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> Parse(IEnumerable<string> list)
Parameters
list
The list of link couples.
Returns
GraphBase<Node<object, object>, Edge<object, object>>
The graph corresponding to the incidence structure given.
Position(Rect)
Returns the position of the given rectangle.
Declaration
public static Point Position(this Rect rect)
Parameters
rect
Rect
The rectangle.
Returns
Point
PrimsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>, TNode, bool)
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
GraphBase<TNode, TLink>
The graph structure.
fromNode
TNode
The node to start from.
reverseWrongEdges
If set to true and the graph is not directed then the edges which do not point in the correct tree flow direction
will be reversed.
Returns
GraphBase<TNode, TLink>
Remarks
Split<TNodeData, TLinkData>(Graph<TNodeData, TLinkData>)
Splits the given, not necessarily connected, graph into its connected components.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static IEnumerable<Graph<TNodeData, TLinkData>> Split<TNodeData, TLinkData>(this Graph<TNodeData, TLinkData> graph) where TNodeData : new() where TLinkData : new()
Parameters
graph
Graph<TNodeData, TLinkData>
The graph to be split.
Returns
IEnumerable<Graph<TNodeData, TLinkData>>
TakeRandomNode(GraphBase<Node<object, object>, Edge<object, object>>, Node<object, object>, int)
Takes a random node with incidence less than specified.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
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
GraphBase<Node<object, object>, Edge<object, object>>
The graph.
node
The node which should not be returned; i.e. the random node should be in the complement of the given node.
incidenceLessThan
The incidence less than.
Returns
TakeTwoRandomNodes(GraphBase<Node<object, object>, Edge<object, object>>)
Takes two random nodes from the given graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Tuple<Node<object, object>, Node<object, object>> TakeTwoRandomNodes(this GraphBase<Node<object, object>, Edge<object, object>> graph)
Parameters
graph
GraphBase<Node<object, object>, Edge<object, object>>
The graph.
Returns
TarjansStronglyConnectedComponentsAlgorithm<TNode, TLink>(bool, TNode, IDictionary<TNode, int>, IDictionary<TNode, int>, ICollection<TNode[]>, Stack<TNode>, int)
Executes Tarjan algorithm on the graph.
Declaration
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePrefferedTerms")]
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")]
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
excludeSingleItems
If set to true single items (singletons) will not be taken into account.
node
TNode
The node to start with.
indices
IDictionary<TNode, int>
The current indices.
lowLinks
IDictionary<TNode, int>
The current low links.
connected
ICollection<TNode[]>
The connected components.
stack
Stack<TNode>
The stack.
index
The current index.
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
rect1
Rect
A rectangle.
rect2
Rect
Another rectangle.
Returns
Rect