Example #1
0
        public static GeometryGraph CreateSimple()
        {
            GeometryGraph graph  = new GeometryGraph();
            var           nodeA0 = new Node();

            graph.Nodes.Add(nodeA0);
            var nodeA1 = new Node();

            graph.Nodes.Add(nodeA1);

            graph.RootCluster.AddChild(nodeA0);
            var cluster = new Cluster();

            graph.RootCluster.AddChild(cluster);
            cluster.AddChild(nodeA1);

            // This is where I add the edge connecting to a cluster.
            var edgeA0cluster = new Edge(nodeA0, cluster);

            edgeA0cluster.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0cluster);
            cluster.AddInEdge(edgeA0cluster);
            graph.Edges.Add(edgeA0cluster);

            return(graph);
        }
Example #2
0
        public void DenseClusteringNoEdges()
        {
            GeometryGraph graph = new GeometryGraph();
            const double Scale = 100;
            const double Margin = 5;
            for (int i = 0; i < 9; ++i)
            {
                graph.Nodes.Add(new Node(CurveFactory.CreateRectangle(Scale, Scale, new Point())));
            }
            Cluster innerCluster = CreateCluster(graph.Nodes.Take(2), Margin);
            Cluster outerCluster = CreateCluster(graph.Nodes.Take(4).Except(innerCluster.Nodes), Margin);
            outerCluster.AddChild(innerCluster);
            graph.RootCluster = new Cluster(graph.Nodes.Except(graph.Nodes.Take(4)));
            graph.RootCluster.AddChild(outerCluster);
            var initialLayout = new InitialLayoutByCluster(
                graph, new FastIncrementalLayoutSettings { NodeSeparation = Margin, ClusterMargin = Margin / 2, PackingAspectRatio = 1 });
            initialLayout.Run();

            EnableDebugViewer();
            ShowGraphInDebugViewer(graph);

            Assert.IsTrue(
                ApproximateComparer.Close(graph.BoundingBox.LeftBottom, new Point()), "Graph origin is not 0,0");
            Assert.AreEqual(340, graph.BoundingBox.Width, 0.1, "Width is incorrect");
            Assert.AreEqual(340, graph.BoundingBox.Height, 0.1, "Height is incorrect");

        }
Example #3
0
        static void FillClustersAndSettings(FastIncrementalLayoutSettings settings, GeometryGraph geometryGraph)
        {
            settings.AvoidOverlaps = true;
            // settings.RectangularClusters = true;
            var root    = new Cluster();
            var cluster = new Cluster();

            root.AddChild(cluster);

            for (int i = 0; i < 4; i++)
            {
                var istring = i.ToString();
                cluster.AddChild(geometryGraph.Nodes.First(n => n.UserData.ToString() == istring));
            }
            cluster.BoundaryCurve = cluster.BoundingBox.Perimeter();
            cluster = new Cluster();
            root.AddChild(cluster);
            geometryGraph.RootCluster.AddChild(root);



            //make a subcluster
            var parent = cluster;

            cluster = new Cluster();
            cluster.AddChild(geometryGraph.Nodes.First(n => n.UserData.ToString() == "4"));
            cluster.AddChild(geometryGraph.Nodes.First(n => n.UserData.ToString() == "5"));
            parent.AddChild(cluster);


            cluster = new Cluster();
            for (int i = 6; i < 9; i++)
            {
                var istring = i.ToString();
                cluster.AddChild(geometryGraph.Nodes.First(n => n.UserData.ToString() == istring));
            }
            parent.AddChild(cluster);
            foreach (var cl in geometryGraph.RootCluster.AllClustersDepthFirst())
            {
                if (cl.BoundaryCurve == null)
                {
                    cl.BoundaryCurve = cl.BoundingBox.Perimeter();
                }
            }
        }
Example #4
0
        static void FillClustersAndSettings(FastIncrementalLayoutSettings settings, GeometryGraph geometryGraph)
        {
            settings.AvoidOverlaps = true;
            // settings.RectangularClusters = true;
            var root    = new Cluster();
            var cluster = new Cluster();

            root.AddChild(cluster);

            for (int i = 0; i < 4; i++)
            {
                cluster.AddChild(FindNode(geometryGraph, i));
            }
            cluster.BoundaryCurve = cluster.BoundingBox.Perimeter();
            cluster = new Cluster();
            root.AddChild(cluster);
            geometryGraph.RootCluster.AddChild(root);



            //make a subcluster
            var parent = cluster;

            cluster = new Cluster();
            cluster.AddChild(FindNode(geometryGraph, 4));
            cluster.AddChild(FindNode(geometryGraph, 5));
            parent.AddChild(cluster);


            cluster = new Cluster();
            for (int i = 6; i < 9; i++)
            {
                cluster.AddChild(FindNode(geometryGraph, i));
            }
            parent.AddChild(cluster);
            foreach (var cl in geometryGraph.RootCluster.AllClustersDepthFirst())
            {
                if (cl.BoundaryCurve == null)
                {
                    cl.BoundaryCurve = cl.BoundingBox.Perimeter();
                }
            }

            SetupDisplayNodeIds(geometryGraph);
        }
Example #5
0
        public void IsDescendantOf_BasicTest()
        {
            Cluster cluster = new Cluster();
            Node    node    = new Node();
            Node    node2   = new Node();

            cluster.AddChild(node);

            Assert.IsTrue(node.IsDescendantOf(cluster), "Node is a descendant of cluster but IsDescendantOf returns false.");
            Assert.IsFalse(node2.IsDescendantOf(cluster), "Node2 is not a descendant of cluster but IsDescendantOf returns true.");
            Assert.IsFalse(cluster.IsDescendantOf(cluster), "A cluster should not be considered a descendant of itself.");
        }
Example #6
0
        public void IsDescendantOf_ManyParents()
        {
            Cluster grandMother = new Cluster();
            Cluster grandFather = new Cluster();
            Cluster parent      = new Cluster();
            Cluster uncle       = new Cluster();

            grandMother.AddChild(parent);
            grandMother.AddChild(uncle);
            grandFather.AddChild(parent);
            grandFather.AddChild(uncle);

            Node child = new Node();

            parent.AddChild(child);

            Assert.IsTrue(child.IsDescendantOf(parent), "The child node should be considered a descendant of its parent.");
            Assert.IsTrue(child.IsDescendantOf(grandMother), "The child node should be considered a descendant of its grandmother.");
            Assert.IsTrue(child.IsDescendantOf(grandFather), "The child node should be considered a descendant of its grandfather.");
            Assert.IsFalse(child.IsDescendantOf(uncle), "The child node should not be considered a descendant of its uncle.");
        }
        private static Cluster AddCluster(double padding, GeometryGraph g, Cluster parent, params string[] vs)
        {
            var c = new Cluster(from v in vs select g.FindNodeByUserData(v))
            {
                UserData            = string.Concat(vs),
                RectangularBoundary =
                    new RectangularClusterBoundary {
                    LeftMargin = padding, RightMargin = padding, BottomMargin = padding, TopMargin = padding
                },
                BoundaryCurve = CurveFactory.CreateRectangle(30, 30, new Point(15, 15))
            };

            parent.AddChild(c);
            return(c);
        }
        public void RoutingWithThreeGroups()
        {
            var graph = LoadGraph("abstract.msagl.geom");
            var root  = graph.RootCluster;
            var a     = new Cluster {
                UserData = "a"
            };

            foreach (string id in new[] { "17", "39", "13", "19", "28", "12" })
            {
                a.AddChild(graph.FindNodeByUserData(id));
            }

            var b = new Cluster {
                UserData = "b"
            };

            b.AddChild(a);
            b.AddChild(graph.FindNodeByUserData("18"));
            root.AddChild(b);

            var c = new Cluster {
                UserData = "c"
            };

            foreach (string id in new[] { "30", "5", "6", "7", "8" })
            {
                c.AddChild(graph.FindNodeByUserData(id));
            }
            root.AddChild(c);

            var clusterNodes = new Set <Node>(root.AllClustersDepthFirst().SelectMany(cl => cl.Nodes));

            foreach (var node in graph.Nodes.Where(n => clusterNodes.Contains(n) == false))
            {
                root.AddChild(node);
            }

            FixClusterBoundariesWithNoRectBoundaries(root, 5);
            var defaultSettings = new FastIncrementalLayoutSettings();
            var rootSettings    = new FastIncrementalLayoutSettings()
            {
                AvoidOverlaps = true
            };

            var initialLayout = new InitialLayoutByCluster(graph, new[] { graph.RootCluster }, cl => cl == root ? rootSettings : defaultSettings);

            initialLayout.Run();

            const double Padding = 5;

            SplineRouter splineRouter = new SplineRouter(graph, Padding / 3, Padding, Math.PI / 6);

            splineRouter.Run();
#if TEST_MSAGL
            if (!DontShowTheDebugViewer())
            {
                graph.UpdateBoundingBox();
                DisplayGeometryGraph.ShowGraph(graph);
            }
#endif
        }
Example #9
0
        void WardMethod_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            clusterList.Clear();
            Normalize();
            foreach (var item in inputDataList)
            {
                Cluster c = new Cluster();
                c.Datas.Add(item);
                c.Layer = 0;

                clusterList.Add(c);
            }
            int layer = 1;
            while (clusterList.Count > 1)
            {
                List<Pair> pairList = new List<Pair>();
                int i = 1;
                foreach (var item in clusterList.Take(clusterList.Count() - 1))
                {
                    foreach (var item2 in clusterList.Skip(i))
                    {
                        var pair = new Pair()
                        {
                            ClusterA = item2,
                            ClusterB = item
                        };
                        pairList.Add(pair);
                    }
                    i++;
                }
                System.Threading.Tasks.Parallel.ForEach(pairList, (n) =>
                {
                    n.Value = n.ClusterA.GetWardValue(n.ClusterB);
                });

                var min = pairList.Min(n => n.Value);
                List<List<Cluster>> cList = new List<List<Cluster>>();
                foreach (var item in pairList.Where(n => n.Value == min))
                {
                    bool flag = true;
                    foreach (var item2 in cList)
                    {
                        if (item2.Any(n => n == item.ClusterA || n == item.ClusterB))
                        {
                            item2.Add(item.ClusterA);
                            item2.Add(item.ClusterB);
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        cList.Add(new List<Cluster> { item.ClusterA, item.ClusterB });
                    }
                }

                foreach (var item in cList)
                {
                    var nCluster = new Cluster() { Layer = layer };
                    foreach (var item2 in item.Distinct())
                    {
                        clusterList.Remove(item2);
                        nCluster.AddChild(item2);
                    }
                    nCluster.SetDatas();
                    clusterList.Add(nCluster);

                }
                layer++;
                ReportProgress(100 - clusterList.Count * 100 / inputDataList.Count);
            }
            ReportProgress(100);
        }
Example #10
0
        public static GeometryGraph Create()
        {
            GeometryGraph graph  = new GeometryGraph();
            var           nodeA0 = new Node();

            graph.Nodes.Add(nodeA0);
            var nodeA1 = new Node();

            graph.Nodes.Add(nodeA1);
            var nodeA2 = new Node();

            graph.Nodes.Add(nodeA2);
            var nodeA3 = new Node();

            graph.Nodes.Add(nodeA3);
            var edgeA0A1 = new Edge(nodeA0, nodeA1);

            edgeA0A1.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0A1);
            nodeA1.AddInEdge(edgeA0A1);
            graph.Edges.Add(edgeA0A1);
            var edgeA0A2 = new Edge(nodeA0, nodeA2);

            edgeA0A2.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0A2);
            nodeA2.AddInEdge(edgeA0A2);
            graph.Edges.Add(edgeA0A2);
            var edgeA2A1 = new Edge(nodeA2, nodeA1);

            edgeA2A1.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA2.AddOutEdge(edgeA2A1);
            nodeA1.AddInEdge(edgeA2A1);
            graph.Edges.Add(edgeA2A1);
            var edgeA0A3 = new Edge(nodeA0, nodeA3);

            edgeA0A3.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0A3);
            nodeA3.AddInEdge(edgeA0A3);
            graph.Edges.Add(edgeA0A3);

            graph.RootCluster.AddChild(nodeA0);
            graph.RootCluster.AddChild(nodeA3);
            var cluster = new Cluster();

            graph.RootCluster.AddChild(cluster);
            cluster.AddChild(nodeA1);
            cluster.AddChild(nodeA2);

            // This is where I add the edge connecting to a cluster.
            var edgeA0cluster = new Edge(nodeA0, cluster);

            edgeA0cluster.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0cluster);
            cluster.AddInEdge(edgeA0cluster);
            graph.Edges.Add(edgeA0cluster);

            var nodeA01 = new Node();

            graph.Nodes.Add(nodeA01);
            graph.RootCluster.AddChild(nodeA01);
            var nodeA02 = new Node();

            graph.Nodes.Add(nodeA02);
            graph.RootCluster.AddChild(nodeA02);
            var nodeA03 = new Node();

            graph.Nodes.Add(nodeA03);
            graph.RootCluster.AddChild(nodeA03);
            var edgeA0A01 = new Edge(nodeA0, nodeA01);

            edgeA0A01.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA0.AddOutEdge(edgeA0A01);
            nodeA01.AddInEdge(edgeA0A01);
            graph.Edges.Add(edgeA0A01);
            var edgeA01A02 = new Edge(nodeA01, nodeA02);

            edgeA01A02.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA01.AddOutEdge(edgeA01A02);
            nodeA02.AddInEdge(edgeA01A02);
            graph.Edges.Add(edgeA01A02);
            var edgeA02A03 = new Edge(nodeA02, nodeA03);

            edgeA02A03.EdgeGeometry = new EdgeGeometry()
            {
                TargetArrowhead = new Arrowhead()
            };
            nodeA02.AddOutEdge(edgeA02A03);
            nodeA03.AddInEdge(edgeA02A03);
            graph.Edges.Add(edgeA02A03);

            return(graph);
        }