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

The static graph-analysis related extensions.

Definition

Namespace:Telerik.Windows.Diagrams.Core

Assembly:Telerik.Windows.Diagrams.Core.dll

Syntax:

C#
public static class GraphExtensions

Inheritance: objectGraphExtensions

Methods

Assigns tree-levels to the nodes.

C#
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:graphGraph<TreeLayoutData, TLinkData>

The graph.

startNodeNode<TreeLayoutData, TLinkData>

The start node.

visitedDictionary<Node<TreeLayoutData, TLinkData>, bool>

The nodes which have already been visited.

offsetint

The offset.

Performs a BFT of the given graph starting at the given node and stops when the first node matching the condition is found.

C#
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:graphGraphBase<TNode, TLink>

The graph to traverse.

conditionFunc<TNode, bool>

The condition a node has to satisfy to be return and thus halt the traversal.

startNodeTNode

The start node.

Returns:

TNode

Performs a breadth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph to traverse.

actionAction<TNode>

The action acting a the visited node.

startNodeTNode

The start node.

Performs a breadth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph to traverse.

visitorIVisitor<TNode>

The visitor traversing the graph.

startNodeTNode

The start node.

Returns a shallow clone from the given collection.

C#
public static IList<Edge<TNodeData, TLinkData>> Clone<TNodeData, TLinkData>(this IEnumerable<Edge<TNodeData, TLinkData>> list) where TNodeData : new() where TLinkData : new()
Parameters:listIEnumerable<Edge<TNodeData, TLinkData>>

The collection to clone.

Returns:

IList<Edge<TNodeData, TLinkData>>

Returns an array of the specified size.

C#
public static int[,] CreateArray(int dim1, int dim2, int value)
Parameters:dim1int

The first dimension.

dim2int

The second dimension.

valueint

The Graph value of the elements.

Returns:

int[,]

Returns an array of the specified size.

C#
public static int[] CreateArray(int size, int value)
Parameters:sizeint

The size.

valueint

The Graph value of the elements in the array.

Returns:

int[]

Creates a forest of balanced trees.

C#
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedForest(int levels = 4, int siblingsCount = 2, int treeCount = 5)
Parameters:levelsint

The levels.

siblingsCountint

The siblings count.

treeCountint

The tree count.

Returns:

GraphBase<Node<object, object>, Edge<object, object>>

Creates a balanced tree.

C#
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedTree(int levels = 3, int siblingsCount = 3)
Parameters:levelsint

The levels.

siblingsCountint

The siblings count.

Returns:

GraphBase<Node<object, object>, Edge<object, object>>

Creates a bi-directional dictionary with keys equal to the (supposedly unique) identifiers and value equal to the provided initial value.

C#
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:graphGraphBase<TNode, TLink>

The graph.

valueint

The value.

Returns:

Dictionary<Tuple<TNode, TNode>, int>

Creates a random graph with a specified amounts of components.

C#
public static GraphBase<Node<object, object>, Edge<object, object>> CreateComponents(int numberOfComponent)
Parameters:numberOfComponentint

The number of component.

Returns:

GraphBase<Node<object, object>, Edge<object, object>>

Creates a dictionary with keys equal to the (supposedly unique) identifiers and value equal to the provided initial value.

C#
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:graphGraphBase<TNode, TLink>

The graph.

valueint

The value.

Returns:

Dictionary<int, int>

Creates a random connected graph.

C#
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomConnectedGraph(int nodesCount, int maxIncidence = 4, bool tree = false)
Parameters:nodesCountint

The nodes count.

maxIncidenceint

The max incidence.

treebool

If set to true the random graph will be effectively a tree.

Returns:

GraphBase<Node<object, object>, Edge<object, object>>

Creates a random graph.

C#
public static GraphBase<Node<object, object>, Edge<object, object>> CreateRandomGraph(int nodesCount = 150, int maxIncidence = 4, bool tree = false)
Parameters:nodesCountint

The count.

maxIncidenceint

The maximum incidence of each node.

treebool

If set to true the generated graph will be a tree.

Returns:

GraphBase<Node<object, object>, Edge<object, object>>

Performs a depth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph.

actionAction<TNode, int>

The action.

startNodeTNode

The start node.

Performs a depth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph.

actionAction<TNode>

The action.

startNodeTNode

The start node.

Performs a depth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph.

visitorIDepthVisitor<TNode>

The visitor.

startNodeTNode

The start node.

Performs a depth-first traversal of the graph starting at the given node.

C#
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:graphGraphBase<TNode, TLink>

The graph to traverse.

visitorIVisitor<TNode>

The visitor.

startNodeTNode

The start node.

Finds cycles in a graph using Tarjan strongly connected components algorithm.

C#
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:graphGraphBase<TNode, TLink>

The graph.

excludeSingleItemsbool

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.

Compares the two graph and assert they are identical.

C#
public static bool HasIdenticalStructureWith(this GraphBase<Node<object, object>, Edge<object, object>> graph1, GraphBase<Node<object, object>, Edge<object, object>> graph2)
Parameters:graph1GraphBase<Node<object, object>, Edge<object, object>>graph2GraphBase<Node<object, object>, Edge<object, object>>Returns:

bool

Kruskal algorithm.

C#
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:graphGraphBase<TNode, TLink>

The graph.

Returns:

GraphBase<TNode, TLink>

Remarks:

    .

    Merges the given graph into the current graph.

    C#
    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:graphGraphBase<Node<object, object>, Edge<object, object>>

    The graph.

    otherGraphGraphBase<Node<object, object>, Edge<object, object>>

    The graph to merge into the current one.

    Returns:

    GraphBase<Node<object, object>, Edge<object, object>>

    Offsets the specified graph.

    C#
    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:layoutGraphGraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>>

    The layout Graph.

    offsetXdouble

    The horizontal offset.

    offsetYdouble

    The vertical offset.

    Moves link.

    C#
    public static void MoveLink<TNodeData, TLinkData>(this Edge<TNodeData, TLinkData> edge, Point point) where TNodeData : new() where TLinkData : new()
    Parameters:edgeEdge<TNodeData, TLinkData>

    The layout link.

    pointPoint

    The delta to move.

    Offsets the given rectangle.

    C#
    public static Rect Offset(this Rect rect, double x, double y)
    Parameters:rectRect

    The rectangle.

    xdouble

    The horizontal offset.

    ydouble

    The vertical offset.

    Returns:

    Rect

    Parses the specified list representing the incidence structure of a graph.

    C#
    public static GraphBase<Node<object, object>, Edge<object, object>> Parse(IEnumerable<string> list)
    Parameters:listIEnumerable<string>

    The list of link couples.

    Returns:

    GraphBase<Node<object, object>, Edge<object, object>>

    The graph corresponding to the incidence structure given.

    Returns the position of the given rectangle.

    C#
    public static Point Position(this Rect rect)
    Parameters:rectRect

    The rectangle.

    Returns:

    Point

    Prim's algorithm finds a minimum-cost spanning tree of an edge-weighted, connected, undirected graph.

    C#
    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:graphGraphBase<TNode, TLink>

    The graph structure.

    fromNodeTNode

    The node to start from.

    reverseWrongEdgesbool

    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>

    Splits the given, not necessarily connected, graph into its connected components.

    C#
    public static IEnumerable<Graph<TNodeData, TLinkData>> Split<TNodeData, TLinkData>(this Graph<TNodeData, TLinkData> graph) where TNodeData : new() where TLinkData : new()
    Parameters:graphGraph<TNodeData, TLinkData>

    The graph to be split.

    Returns:

    IEnumerable<Graph<TNodeData, TLinkData>>

    Takes a random node with incidence less than specified.

    C#
    public static Node<object, object> TakeRandomNode(this GraphBase<Node<object, object>, Edge<object, object>> graph, Node<object, object> node = null, int incidenceLessThan = 4)
    Parameters:graphGraphBase<Node<object, object>, Edge<object, object>>

    The graph.

    nodeNode<object, object>

    The node which should not be returned; i.e. the random node should be in the complement of the given node.

    incidenceLessThanint

    The incidence less than.

    Returns:

    Node<object, object>

    Takes two random nodes from the given graph.

    C#
    public static Tuple<Node<object, object>, Node<object, object>> TakeTwoRandomNodes(this GraphBase<Node<object, object>, Edge<object, object>> graph)
    Parameters:graphGraphBase<Node<object, object>, Edge<object, object>>

    The graph.

    Returns:

    Tuple<Node<object, object>, Node<object, object>>

    Executes Tarjan algorithm on the graph.

    C#
    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:excludeSingleItemsbool

    If set to true single items (singletons) will not be taken into account.

    nodeTNode

    The node to start with.

    indicesIDictionary<TNode, int>

    The current indices.

    lowLinksIDictionary<TNode, int>

    The current low links.

    connectedICollection<TNode[]>

    The connected components.

    stackStack<TNode>

    The stack.

    indexint

    The current index.

    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.

    C#
    public static Rect UnionEmptyRects(Rect rect1, Rect rect2)
    Parameters:rect1Rect

    A rectangle.

    rect2Rect

    Another rectangle.

    Returns:

    Rect

    In this article
    DefinitionMethodsAssignLevel<TLinkData>(Graph<TreeLayoutData, TLinkData>, Node<TreeLayoutData, TLinkData>, Dictionary<Node<TreeLayoutData, TLinkData>, bool>, int)BreadthFirstSearch<TNode, TLink>(GraphBase<TNode, TLink>, Func<TNode, bool>, TNode)BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode>, TNode)BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IVisitor<TNode>, TNode)Clone<TNodeData, TLinkData>(IEnumerable<Edge<TNodeData, TLinkData>>)CreateArray(int, int, int)CreateArray(int, int)CreateBalancedForest(int, int, int)CreateBalancedTree(int, int)CreateBiDictionary<TNode, TLink>(GraphBase<TNode, TLink>, int)CreateComponents(int)CreateDictionary<TNode, TLink>(GraphBase<TNode, TLink>, int)CreateRandomConnectedGraph(int, int, bool)CreateRandomGraph(int, int, bool)DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode, int>, TNode)DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode>, TNode)DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IDepthVisitor<TNode>, TNode)DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IVisitor<TNode>, TNode)FindCycles<TNode, TLink>(GraphBase<TNode, TLink>, bool)HasIdenticalStructureWith(GraphBase<Node<object, object>, Edge<object, object>>, GraphBase<Node<object, object>, Edge<object, object>>)KruskalsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>)Merge(GraphBase<Node<object, object>, Edge<object, object>>, GraphBase<Node<object, object>, Edge<object, object>>)MoveGraph<TNodeData, TLinkData>(GraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>>, double, double)MoveLink<TNodeData, TLinkData>(Edge<TNodeData, TLinkData>, Point)Offset(Rect, double, double)Parse(IEnumerable<string>)Position(Rect)PrimsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>, TNode, bool)Split<TNodeData, TLinkData>(Graph<TNodeData, TLinkData>)TakeRandomNode(GraphBase<Node<object, object>, Edge<object, object>>, Node<object, object>, int)TakeTwoRandomNodes(GraphBase<Node<object, object>, Edge<object, object>>)TarjansStronglyConnectedComponentsAlgorithm<TNode, TLink>(bool, TNode, IDictionary<TNode, int>, IDictionary<TNode, int>, ICollection<TNode[]>, Stack<TNode>, int)UnionEmptyRects(Rect, Rect)
    Not finding the help you need?
    Contact Support