Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a specific graph which has some obvious cycles and lets the graph analysis highlight them, thus confirming the cycles
        /// which can be easily found manually. The analysis goes of course beyond what the human eye can see and would find cycles in an arbitrary graph.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void Cycles(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var g = diagram.CreateDiagram(new List <string> {
                "1,2", "3,1", "2,4", "4,3", "4,5", "10,11", "11,12", "12,10"
            }, out nodeMap,
                                          out edgeMap, specs.CreateShape, specs.RandomShapeSize);
            var cycles = g.FindCycles();

            if (cycles.Count > 0)
            {
                foreach (var cycle in cycles)
                {
                    var path = new GraphPath <Node, Edge>();
                    cycle.ToList().ForEach(path.AddNode);
                    this.Highlight(path, nodeMap, edgeMap, specs.HighlightBrush);
                }
            }
            diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
            {
                TreeLayoutType       = TreeLayoutType.TreeRight,
                VerticalSeparation   = 50d,
                HorizontalSeparation = 80d
            });
        }
Beispiel #3
0
 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);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates a balanced radial forest.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        public static void BalancedRadialForest(this RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var g        = diagram.CreateDiagram(CreateBalancedForest(), out nodeMap, out edgeMap, CreateShape, specs.RandomShapeSize);
            var settings = new TreeLayoutSettings
            {
                TreeLayoutType                  = specs.TreeType,
                HorizontalSeparation            = specs.HorizontalSeparation,
                VerticalSeparation              = specs.VerticalSeparation,
                UnderneathHorizontalOffset      = specs.UnderneathHorizontalOffset,
                UnderneathVerticalSeparation    = specs.UnderneathVerticalSeparation,
                KeepComponentsInOneRadialLayout = specs.KeepComponentsInOneRadialLayout
            };
            var center = g.FindNode(1);

            settings.Roots.Add(nodeMap[center]);
            var layout = new TreeLayout();

            layout.Layout(diagram, settings);
            diagram.AutoFit();
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
 /// <summary>
 /// Creates a specific graph which has some obvious cycles and lets the graph analysis highlight them, thus confirming the cycles
 /// which can be easily found manually. The analysis goes of course beyond what the human eye can see and would find cycles in an arbitrary graph.
 /// </summary>
 /// <param name="diagram">The diagram.</param>
 /// <param name="specs">The specs.</param>
 private void Cycles(RadDiagram diagram, GraphGenerationSpecifications specs)
 {
     diagram.Clear();
     Dictionary<Node, RadDiagramShape> nodeMap;
     Dictionary<Edge, RadDiagramConnection> edgeMap;
     var g = diagram.CreateDiagram(new List<string> { "1,2", "3,1", "2,4", "4,3", "4,5", "10,11", "11,12", "12,10" }, out nodeMap,
         out edgeMap, specs.CreateShape, specs.RandomShapeSize);
     var cycles = g.FindCycles();
     if (cycles.Count > 0)
     {
         foreach (var cycle in cycles)
         {
             var path = new GraphPath<Node, Edge>();
             cycle.ToList().ForEach(path.AddNode);
             this.Highlight(path, nodeMap, edgeMap, specs.HighlightBrush);
         }
     }
     diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
                                         {
                                             TreeLayoutType = TreeLayoutType.TreeRight,
                                             VerticalSeparation = 50d,
                                             HorizontalSeparation = 80d
                                         });
 }