protected GeometryGraph LoadGraph(string geometryGraphFileName, out LayoutAlgorithmSettings settings)
        {
            if (string.IsNullOrEmpty(geometryGraphFileName))
            {
                throw new ArgumentNullException("geometryGraphFileName");
            }

            GeometryGraph graph = null;

            settings = null;
            if (geometryGraphFileName.EndsWith(".geom"))
            {
                graph = GeometryGraphReader.CreateFromFile(geometryGraphFileName, out settings);
                SetupPorts(graph);
            }
            else if (geometryGraphFileName.EndsWith(".dot"))
            {
                int           line;
                string        msg;
                int           col;
                Drawing.Graph drawingGraph = Parser.Parse(geometryGraphFileName, out line, out col, out msg);
                drawingGraph.CreateGeometryGraph();
                graph    = drawingGraph.GeometryGraph;
                settings = drawingGraph.CreateLayoutSettings();
                GraphGenerator.SetRandomNodeShapes(graph, new Random(1));
            }
            else
            {
                Assert.Fail("Unknown graph format for file: " + geometryGraphFileName);
            }

            TestContext.WriteLine("Loaded graph: {0} Nodes, {1} Edges", graph.Nodes.Count, graph.Edges.Count);
            return(graph);
        }
Beispiel #2
0
        public void ConstraintWithTransformation()
        {
            Random random = new Random(999);

            GeometryGraph graph = GraphGenerator.GenerateOneSimpleGraph();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            //layer direction to be left to right
            settings.Transformation = PlaneTransformation.Rotation(Math.PI / 2);

            List <Node> nodes = graph.Nodes.ToList();

            settings.AddUpDownConstraint(nodes[0], nodes[1]);
            settings.AddLeftRightConstraint(nodes[3], nodes[4]);
            settings.AddUpDownVerticalConstraint(nodes[0], nodes[3]);
            settings.AddSameLayerNeighbors(nodes[2], nodes[4]);

            LayeredLayout layeredLayout = new LayeredLayout(graph, settings);

            layeredLayout.Run();

            ShowGraphInDebugViewer(graph);

            SugiyamaValidation.ValidateUpDownConstraint(nodes[0], nodes[1]);
            SugiyamaValidation.ValidateLeftRightConstraint(nodes[3], nodes[4]);
            SugiyamaValidation.ValidateUpDownVerticalConstraint(nodes[0], nodes[3]);
            SugiyamaValidation.ValidateNeighborConstraint(graph, nodes[2], nodes[4], settings);
        }
        public void ChainGraphDownwardConstraintTests()
        {
            GeometryGraph graph = GraphGenerator.GenerateSimpleChain(10);

            GraphGenerator.SetRandomNodeShapes(graph, random);

            LayoutAndValidate(graph, 1.5, null);
        }
        public void RandomDotFileTests()
        {
            int    line, column;
            string msg;

            string fileName = Path.Combine(this.TestContext.TestDir, "Out\\Dots\\fsm.dot");

            Drawing.Graph drawGraph = Parser.Parse(fileName, out line, out column, out msg);
            drawGraph.CreateGeometryGraph();
            GeometryGraph graph = drawGraph.GeometryGraph;

            GraphGenerator.SetRandomNodeShapes(graph, random);
            LayeredLayout layeredLayout = new LayeredLayout(graph, new SugiyamaLayoutSettings()
            {
                BrandesThreshold = 1
            });

            layeredLayout.Run();
            string[]   allFiles = Directory.GetFiles(Path.Combine(this.TestContext.TestDir, "Out\\Dots"), "*.dot");
            List <int> selected = new List <int>();

            for (int i = 0; i < 10; i++)
            {
                int next = random.Next(allFiles.Length);
                while (selected.Contains(next))
                {
                    next = random.Next(allFiles.Length);
                }
                selected.Add(next);
                WriteLine("Now handling dot file: " + allFiles[next]);
                drawGraph = Parser.Parse(allFiles[next], out line, out column, out msg);
                drawGraph.CreateGeometryGraph();
                graph = drawGraph.GeometryGraph;
                GraphGenerator.SetRandomNodeShapes(graph, random);

                LayerDirection direction = LayerDirection.None;
                switch (i % 4)
                {
                case 0:
                    direction = LayerDirection.TopToBottom;
                    break;

                case 1:
                    direction = LayerDirection.BottomToTop;
                    break;

                case 2:
                    direction = LayerDirection.LeftToRight;
                    break;

                case 3:
                    direction = LayerDirection.RightToLeft;
                    break;
                }
                LayoutAndValidate(graph, (SugiyamaLayoutSettings)drawGraph.LayoutAlgorithmSettings, direction);
            }
        }
        public void LatticeGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateSquareLattice(20);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Lattice Graph with Top to Down layer direction");
            LayoutAndValidate(graph, settings);
        }
        public void DisjointGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateGraphWithSameSubgraphs(3, 6);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Disjoint Graph with Left To Right layer direction");
            LayoutAndValidate(graph, settings, 32, 25, LayerDirection.LeftToRight);
        }
        public void CircleGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateCircle(10);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Circle Graph with Top to Down layer direction");
            LayoutAndValidate(graph, settings, 18, 10);
        }
 public override void Initialize()
 {
     EnableDebugViewer();
     base.Initialize();
     graph = GraphGenerator.GenerateOneSimpleGraph();
     GraphGenerator.SetRandomNodeShapes(graph, random);
     allNodes = graph.Nodes.ToList();
     settings = new FastIncrementalLayoutSettings();
     settings.AvoidOverlaps = true;
 }
        public void FullyConnectedGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateFullyConnectedGraph(20);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Fully Connected Graph with Bottom to Top layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.BottomToTop);
            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Fully Connected Graph with Left to Right layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.LeftToRight);
        }
        public void TreeGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateFullTree(10, 3);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Tree Graph with Right to Left layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.RightToLeft);
            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Tree Graph with Bottom to Top layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.BottomToTop);
        }
        public void SimpleGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateOneSimpleGraph();
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Simple Graph with Top to Down layer direction");
            LayoutAndValidate(graph, settings);
            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Simple Graph with Left to Right layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.LeftToRight);
        }
Beispiel #12
0
        public void RandomGraphTests()
        {
            GeometryGraph          graph    = GraphGenerator.GenerateOneGraph(new GeometryGraph(), 30, 30, true);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Kokomo Graph with bottom to top layer direction");
            LayoutAndValidate(graph, settings, LayerDirection.BottomToTop);

            graph = GraphGenerator.GenerateOneGraph(new GeometryGraph(), 30, 40, false);
            GraphGenerator.SetRandomNodeShapes(graph, random);
            WriteLine("Trying Kokomo Graph with rigth to left layer direction");
            Microsoft.Msagl.DebugHelpers.Persistence.GeometryGraphWriter.Write(graph, "wrongLayout");
            LayoutAndValidate(graph, settings, LayerDirection.RightToLeft);
        }
        public void CircleGraphDownwardConstraintTests()
        {
            GeometryGraph graph      = GraphGenerator.GenerateCircle(6);
            ISet <Node>   avoidNodes = new HashSet <Node>(graph.Nodes);

            Node firstNode = graph.Nodes.First();
            Node lastNode  = graph.Nodes.Last();

            //add some non-cyclic nodes
            Node node1 = GraphGenerator.CreateNode(graph.Nodes.Count);
            Node node2 = GraphGenerator.CreateNode(graph.Nodes.Count + 1);

            graph.Nodes.Add(node1);
            graph.Nodes.Add(node2);
            graph.Edges.Add(GraphGenerator.CreateEdge(firstNode, node1));
            graph.Edges.Add(GraphGenerator.CreateEdge(node2, lastNode));

            GraphGenerator.SetRandomNodeShapes(graph, random);
            LayoutAndValidate(graph, 2.5, avoidNodes);
        }