Ejemplo n.º 1
0
        private ProximityOverlapRemoval RunOverlapRemoval(GeometryGraph graphCopy, GeometryGraph graphOriginal, HashSet <Tuple <int, int> > proximityEdges,
                                                          HashSet <Tuple <int, int, int> > proximityTriangles, List <Tuple <string, double> > statistics, OverlapRemovalSettings settings)
        {
            ProximityOverlapRemoval prism = new ProximityOverlapRemoval(graphCopy);

            prism.Settings = settings;
            Timer timer = new Timer();

            timer.Start();
            prism.RemoveOverlaps();
            timer.Stop();
            var cpuTimeSpan    = TimeSpan.FromSeconds(timer.Duration);
            var statCpuTime    = Tuple.Create("CPUTime", cpuTimeSpan.TotalSeconds);
            var statIterations = Tuple.Create("Iterations", (double)prism.LastRunIterations);

            var statEdgeLength = Statistics.Statistics.EdgeLengthDeviation(graphOriginal, graphCopy, proximityEdges);
            var statProcrustes =
                Statistics.Statistics.ProcrustesStatistics(graphOriginal.Nodes.Select(v => v.Center).ToList(),
                                                           graphCopy.Nodes.Select(v => v.Center).ToList());
            var statTriangleOrient = Statistics.Statistics.TriangleOrientation(graphOriginal, graphCopy, proximityTriangles);
            var statArea           = Statistics.Statistics.Area(graphCopy);


            statistics.Add(statCpuTime);
            statistics.Add(statIterations);
            statistics.Add(statEdgeLength);
            statistics.Add(statProcrustes);
            statistics.Add(statArea);
            statistics.Add(statTriangleOrient);
            return(prism);
        }
/*
 *      bool OkToCreateOrOverwriteMsaglFile(string fileName) {
 *          string msaglFileName = CreateMsaglFileNameFromDotName(fileName);
 *          Console.WriteLine(msaglFileName);
 *          if (File.Exists(msaglFileName)) {
 *              string message = String.Format("Do you want to overwrite {0}?", msaglFileName);
 *              MessageBoxResult result = MessageBox.Show(message, "confirm overwrite", MessageBoxButton.YesNo);
 *              if (result == MessageBoxResult.Yes) {
 *                  return true;
 *              }
 *              if (result == MessageBoxResult.No) {
 *                  return false;
 *              }
 *              return false;
 *          }
 *          return true;
 *      }
 */

        void PassGraphToGraphViewer(Graph gwgraph, string fileName)
        {
            CreateTileDirectoryName(fileName);
            FixRoundCorners(gwgraph);
            SetLayoutSettings(gwgraph);
            if (_argsParser.OptionIsUsed(RunRemoveOverlapsOption))
            {
                var compGraph = gwgraph.GeometryGraph;
                switch (new MdsLayoutSettings().OverlapRemovalMethod)
                {
                case OverlapRemovalMethod.Prism:
                    ProximityOverlapRemoval.RemoveOverlaps(compGraph, gwgraph.LayoutAlgorithmSettings.NodeSeparation);
                    break;

                case OverlapRemovalMethod.MinimalSpanningTree:
                    GTreeOverlapRemoval.RemoveOverlaps(compGraph.Nodes.ToArray(),
                                                       gwgraph.LayoutAlgorithmSettings.NodeSeparation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            _graphViewer.Graph = gwgraph;
        }
        /// <summary>
        /// Removes the overlaps for the given graph.
        /// </summary>
        public void RemoveOverlaps()
        {
            if (_nodes.Length < 3)
            {
                RemoveOverlapsOnTinyGraph();
                return;
            }

            Point[] nodePositions;
            Size[]  nodeSizes;
            ProximityOverlapRemoval.InitNodePositionsAndBoxes(_settings, _nodes
                                                              , out nodePositions, out nodeSizes);
            if (_overlapForLayers)
            {
                nodeSizes = _sizes;
            }

            lastRunNumberIterations = 0;
            while (OneIteration(nodePositions, nodeSizes, false))
            {
                lastRunNumberIterations++;
            }
            while (OneIteration(nodePositions, nodeSizes, true))
            {
                lastRunNumberIterations++;
            }


            for (int i = 0; i < _nodes.Length; i++)
            {
                _nodes[i].Center = nodePositions[i];
            }
        }
Ejemplo n.º 4
0
 private static void RandomizeNodes(Graph graph, Point[] nodePositions)
 {
     ProximityOverlapRemoval.RandomizePoints(nodePositions, new Random(100), 0.01, true);
     for (int k = 0; k < nodePositions.Length; k++)
     {
         graph.GeometryGraph.Nodes[k].Center = nodePositions[k];
     }
 }
        void LayoutConnectedGraphWithMds(GeometryGraph compGraph)
        {
            Console.WriteLine("LayoutConnectedGraphWithMds: nodes {0} edges {1}", compGraph.Nodes.Count(), compGraph.Edges.Count());

            double[] x, y;

            LayoutGraphWithMds(compGraph, settings, out x, out y);
            if (settings.RotationAngle != 0)
            {
                Transform.Rotate(x, y, settings.RotationAngle);
            }

            double scaleX = settings.ScaleX;
            double scaleY = settings.ScaleY;
            int    index  = 0;

            foreach (Node node in compGraph.Nodes)
            {
                node.Center = new Point(x[index] * scaleX, y[index] * scaleY);
                index++;
                if ((index % 100) == 0)
                {
                    ProgressStep();
                }
            }
            if (settings.AdjustScale)
            {
                AdjustScale(compGraph.Nodes);
            }

            if (settings.RemoveOverlaps)
            {
                switch (settings.OverlapRemovalMethod)
                {
                case OverlapRemovalMethod.Prism:
                    ProximityOverlapRemoval.RemoveOverlaps(compGraph, settings.NodeSeparation);
                    break;

                case OverlapRemovalMethod.Pmst:
                    OverlapRemoval.RemoveOverlaps(compGraph, settings.NodeSeparation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            compGraph.BoundingBox = compGraph.PumpTheBoxToTheGraphWithMargins();
        }
        /// <summary>
        /// Removes the overlaps for the given graph.
        /// </summary>
        public void RemoveOverlaps()
        {
            if (_nodes.Length < 3)
            {
                RemoveOverlapsOnTinyGraph();
                return;
            }

            Point[] nodePositions;
            Size[]  nodeSizes;
            ProximityOverlapRemoval.InitNodePositionsAndBoxes(_settings, _nodes
                                                              , out nodePositions, out nodeSizes);
            if (_overlapForLayers)
            {
                nodeSizes = _sizes;
            }
            if (_settings.InitialScaling != InitialScaling.None)
            {
                DoInitialScaling(_nodes, nodePositions, nodeSizes, InitialScaling.Inch72Pixel);
            }

            lastRunNumberIterations = 0;
            while (OneIteration(nodePositions, nodeSizes, false))
            {
                lastRunNumberIterations++;
//                if (lastRunNumberIterations%10 == 0)
//                    Console.Write("removing overlaps with cdt only {0},", lastRunNumberIterations);
            }
            //        Console.WriteLine();
            while (OneIteration(nodePositions, nodeSizes, true))
            {
                lastRunNumberIterations++;
//                Console.Write("iterations with sweeping line {0},", lastRunNumberIterations);
            }

            Console.WriteLine();

            for (int i = 0; i < _nodes.Length; i++)
            {
                _nodes[i].Center = nodePositions[i];
            }
        }
Ejemplo n.º 7
0
        void GiveGraphToControl(Graph gwgraph)
        {
            if (argsParser.OptionIsUsed(RoundedCornersOption))
            {
                foreach (var n in gwgraph.Nodes)
                {
                    n.Attr.Shape   = Shape.Box;
                    n.Attr.XRadius = n.Attr.YRadius = 3;
                }
            }



            SetLayoutSettings(gwgraph);
            if (argsParser.OptionIsUsed(RunRemoveOverlapsOption))
            {
                var compGraph = gwgraph.GeometryGraph;
                switch (new MdsLayoutSettings().OverlapRemovalMethod)
                {
                case OverlapRemovalMethod.Prism:
                    ProximityOverlapRemoval.RemoveOverlaps(compGraph, gwgraph.LayoutAlgorithmSettings.NodeSeparation);
                    break;

                case OverlapRemovalMethod.Pmst:
                    OverlapRemoval.RemoveOverlaps(compGraph, gwgraph.LayoutAlgorithmSettings.NodeSeparation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                if (graphViewer.MsaglFileToSave != null)
                {
                    gwgraph.Write(graphViewer.MsaglFileToSave);
                    Console.WriteLine("saved into {0}", graphViewer.MsaglFileToSave);
                    Environment.Exit(0);
                }
            }


            graphViewer.Graph = gwgraph;
        }
        /// <summary>
        /// Removes the overlap for the given graph.
        /// </summary>
        /// <param name="graph"></param>
        public void RemoveOverlap(GeometryGraph graph)
        {
            if (graph.Nodes.Count < 3)
            {
                RemoveOverlapsOnTinyGraph(graph);
                return;
            }

            Point[] nodePositions;
            Size[]  nodeSizes;
            ProximityOverlapRemoval.InitNodePositionsAndBoxes(Settings,
                                                              graph, out nodePositions,
                                                              out nodeSizes);
            if (Settings.InitialScaling != InitialScaling.None)
            {
                DoInitialScaling(graph, nodePositions, nodeSizes, InitialScaling.Inch72Pixel);
            }

            lastRunNumberIterations = 0;
            while (OneIteration(nodePositions, nodeSizes, false))
            {
                lastRunNumberIterations++;
//                if (lastRunNumberIterations%10 == 0)
//                    Console.Write("removing overlaps with cdt only {0},", lastRunNumberIterations);
            }
            //        Console.WriteLine();
            while (OneIteration(nodePositions, nodeSizes, true))
            {
                lastRunNumberIterations++;
//                Console.Write("iterations with sweeping line {0},", lastRunNumberIterations);
            }

            Console.WriteLine();

            for (int i = 0; i < graph.Nodes.Count; i++)
            {
                graph.Nodes[i].Center = nodePositions[i];
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="graphFilename"></param>
        public void RunOverlapRemoval(String graphFilename)
        {
            String graphName = Path.GetFileNameWithoutExtension(graphFilename);
            Graph  graph     = DotLoader.LoadGraphFile(graphFilename);

            Point[] initPositions = graph.GeometryGraph.Nodes.Select(v => v.Center).ToArray();
            if (graph == null || graph.GeometryGraph == null)
            {
                Console.WriteLine("Failed to load graph: {0}", graphName);
                return;
            }

            for (int i = 0; i < layoutMethods.Count(); i++)
            {
                var layoutMethod = layoutMethods[i];
                layoutMethod.Item2.Invoke(graph.GeometryGraph); //do initial layout
                //randomize cooincident points
                Point[] nodePositions = graph.GeometryGraph.Nodes.Select(v => v.Center).ToArray();

//                LayoutAlgorithmSettings.ShowDebugCurves(
//                    nodePositions.Select(p => new DebugCurve(220, 0.01, "green", CurveFactory.CreateOctagon(2, 2, p)))
//                                 .ToArray());

                ProximityOverlapRemoval.RandomizePoints(nodePositions, new Random(100), 0.01, true);
                for (int k = 0; k < nodePositions.Length; k++)
                {
                    graph.GeometryGraph.Nodes[k].Center = nodePositions[k];
                }

                DoInitialScaling(graph.GeometryGraph, InitialScaling.Inch72Pixel);
                RefreshAndCleanGraph(graph);
                SvgGraphWriter.Write(graph, graphName + "-" + i.ToString() + "-" + layoutMethod.Item1 + ".svg");

//                HashSet<Point> pointSet=new HashSet<Point>();
//                foreach (Point p in nodePositions) {
//                    Console.WriteLine(p);
//                    if (pointSet.Contains(p)) {
//                        Console.WriteLine("Coincident points.");
//                    }
//                    else pointSet.Add(p);
//                }

                HashSet <Tuple <int, int, int> > proximityTriangles;
                HashSet <Tuple <int, int> >      proximityEdges;
                GetProximityRelations(graph.GeometryGraph, out proximityEdges, out proximityTriangles);

                for (int j = 0; j < overlapMethods.Count; j++)
                {
                    var overlapMethod = overlapMethods[j];
                    TestOverlapRemovalOnGraph(graphName, graph, proximityEdges, proximityTriangles, layoutMethod, i, overlapMethod, j);

                    SetOldPositions(nodePositions, graph);
                }
                SetOldPositions(initPositions, graph);
            }



//#if DEBUG
//            //write the number of crossings per iteration
//            String convergenceFilename = graphName + "-crossPerIterat.csv";
//            List<int> crossings1 = prism1.crossingsOverTime;
//            List<int> crossings2 = prism2.crossingsOverTime;
//
//            int maxIter = Math.Max(crossings1.Count, crossings2.Count);
//            List<String> lines=new List<string>();
//            lines.Add("iteration,crossingsPRISM,crossingsGridBoost");
//            for (int i = 0; i < maxIter; i++) {
//                String l = i.ToString();
//                if (i < crossings1.Count)
//                    l += "," + crossings1[i];
//                else l += ",0";
//                if (i < crossings2.Count)
//                    l += "," + crossings2[i];
//                else l += ",0";
//                lines.Add(l);
//            }
//            File.WriteAllLines(convergenceFilename,
//                lines.ToArray(),Encoding.UTF8);
//#endif
        }