Class
GraphExtensions

The static graph-analysis related extensions.

Definition

Namespace:Telerik.Windows.Diagrams.Core

Assembly:Telerik.Windows.Diagrams.Core.dll

Syntax:

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

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

int

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

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

Func<TNode, bool>

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

startNode

TNode

The start node.

Returns

TNode

Remarks

See http://en.wikipedia.org/wiki/Breadth-first_search.

BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode>, TNode)

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

Declaration

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

See http://en.wikipedia.org/wiki/Breadth-first_search.

BreadthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, IVisitor<TNode>, TNode)

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

Declaration

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

See http://en.wikipedia.org/wiki/Breadth-first_search.

Clone<TNodeData, TLinkData>(IEnumerable<Edge<TNodeData, TLinkData>>)

Returns a shallow clone from the given collection.

Declaration

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

IList<Edge<TNodeData, TLinkData>>

CreateArray(int, int)

Returns an array of the specified size.

Declaration

cs-api-definition
public static int[] CreateArray(int size, int value)

Parameters

size

int

The size.

value

int

The Graph value of the elements in the array.

Returns

int[]

CreateArray(int, int, int)

Returns an array of the specified size.

Declaration

cs-api-definition
public static int[,] CreateArray(int dim1, int dim2, int value)

Parameters

dim1

int

The first dimension.

dim2

int

The second dimension.

value

int

The Graph value of the elements.

Returns

int[,]

CreateBalancedForest(int, int, int)

Creates a forest of balanced trees.

Declaration

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

int

The levels.

siblingsCount

int

The siblings count.

treeCount

int

The tree count.

Returns

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

CreateBalancedTree(int, int)

Creates a balanced tree.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateBalancedTree(int levels = 3, int siblingsCount = 3)

Parameters

levels

int

The levels.

siblingsCount

int

The siblings count.

Returns

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

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

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

int

The value.

Returns

Dictionary<Tuple<TNode, TNode>, int>

CreateComponents(int)

Creates a random graph with a specified amounts of components.

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static GraphBase<Node<object, object>, Edge<object, object>> CreateComponents(int numberOfComponent)

Parameters

numberOfComponent

int

The number of component.

Returns

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

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

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

int

The value.

Returns

Dictionary<int, int>

CreateRandomConnectedGraph(int, int, bool)

Creates a random connected graph.

Declaration

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

int

The nodes count.

maxIncidence

int

The max incidence.

tree

bool

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

Returns

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

CreateRandomGraph(int, int, bool)

Creates a random graph.

Declaration

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

int

The count.

maxIncidence

int

The maximum incidence of each node.

tree

bool

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

Returns

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

DepthFirstTraversal<TNode, TLink>(GraphBase<TNode, TLink>, Action<TNode, int>, TNode)

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

Declaration

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

Action<TNode, int>

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

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

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

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

See http://en.wikipedia.org/wiki/Depth-first_search.

FindCycles<TNode, TLink>(GraphBase<TNode, TLink>, bool)

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

Declaration

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

bool

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

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

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

Returns

bool

KruskalsSpanningTree<TNode, TLink>(GraphBase<TNode, TLink>)

Kruskal algorithm.

Declaration

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

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

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

    MoveGraph<TNodeData, TLinkData>(GraphBase<Node<TNodeData, TLinkData>, Edge<TNodeData, TLinkData>>, double, double)

    Offsets the specified graph.

    Declaration

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

    double

    The horizontal offset.

    offsetY

    double

    The vertical offset.

    Moves link.

    Declaration

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

    Declaration

    cs-api-definition
    public static Rect Offset(this Rect rect, double x, double y)

    Parameters

    rect

    Rect

    The rectangle.

    x

    double

    The horizontal offset.

    y

    double

    The vertical offset.

    Returns

    Rect

    Parse(IEnumerable<string>)

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

    Declaration

    cs-api-definition
    [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
    public static GraphBase<Node<object, object>, Edge<object, object>> Parse(IEnumerable<string> list)

    Parameters

    list

    IEnumerable<string>

    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

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

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

    bool

    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

    See http://en.wikipedia.org/wiki/Prim%27s_algorithm .

    Split<TNodeData, TLinkData>(Graph<TNodeData, TLinkData>)

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

    Declaration

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

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

    Node<object, object>

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

    incidenceLessThan

    int

    The incidence less than.

    Returns

    Node<object, object>

    TakeTwoRandomNodes(GraphBase<Node<object, object>, Edge<object, object>>)

    Takes two random nodes from the given graph.

    Declaration

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

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

    TarjansStronglyConnectedComponentsAlgorithm<TNode, TLink>(bool, TNode, IDictionary<TNode, int>, IDictionary<TNode, int>, ICollection<TNode[]>, Stack<TNode>, int)

    Executes Tarjan algorithm on the graph.

    Declaration

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

    bool

    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

    int

    The current index.

    Remarks

    See http://en.wikipedia.org/wiki/Pseudoforest .

    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

    cs-api-definition
    public static Rect UnionEmptyRects(Rect rect1, Rect rect2)

    Parameters

    rect1

    Rect

    A rectangle.

    rect2

    Rect

    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)CreateArray(int, 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