/// <summary> /// Creates a random connected graph and displayes a (non-unique) spanning tree using Prim's algorithm. /// </summary> /// <param name="diagram">The diagram.</param> /// <param name="specs">The specs.</param> private void Prims(RadDiagram diagram, GraphGenerationSpecifications specs) { diagram.Clear(); Dictionary <Node, RadDiagramShape> nodeMap; Dictionary <Edge, RadDiagramConnection> edgeMap; var randomConnectedGraph = GraphExtensions.CreateRandomConnectedGraph(10); var root = randomConnectedGraph.FindTreeRoot(); var g = diagram.CreateDiagram(randomConnectedGraph, out nodeMap, out edgeMap, GraphExtensions.CreateShape, specs.RandomShapeSize); // making it undirected will reach all the nodes since the random graph is connected g.IsDirected = false; var tree = g.PrimsSpanningTree(root); if (tree != null) { this.Highlight(tree, nodeMap, edgeMap, this.HighlighBrush); } var settings = new TreeLayoutSettings { TreeLayoutType = TreeLayoutType.TreeDown, VerticalSeparation = 50d, HorizontalSeparation = 80d, }; diagram.Layout(LayoutType.Tree, settings); }
public static void CreateGraph(this RadDiagram diagram, GraphGenerationSpecifications specs, CreateShapeDelegate createShape) { diagram.Clear(); if (specs.Connections) { var g = specs.Connected ? GraphExtensions.CreateRandomConnectedGraph(specs.NodeCount, 4, specs.TreeGraph) : GraphExtensions.CreateRandomGraph(specs.NodeCount, 4, specs.TreeGraph); diagram.CreateDiagram(g, GraphExtensions.CreateShape, specs.RandomShapeSize); } else { for (var i = 0; i < specs.NodeCount; i++) { var shape = createShape(new Node(i, false), specs.RandomShapeSize); diagram.AddShape(shape); } } }