Esempio n. 1
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];
     }
 }
Esempio n. 2
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
        }