private static bool RemoveLongestEdge(Tiling gPlanar, List <Vertex> face)
        {
            double longestLength = -1, length;
            Vertex initialVertex = null, oldVertex = null;
            Vertex removeA = null, removeB = null;

            foreach (Vertex boundaryVertex in face)
            {
                if (oldVertex == null)
                {
                    initialVertex = oldVertex = boundaryVertex;
                    continue;
                }
                length = gPlanar.GetEucledianDist(boundaryVertex.Id, oldVertex.Id);
                if (longestLength < length)
                {
                    removeA       = oldVertex;
                    removeB       = boundaryVertex;
                    longestLength = length;
                }
                oldVertex = boundaryVertex;
            }
            length = gPlanar.GetEucledianDist(oldVertex.Id, initialVertex.Id);
            if (longestLength < length)
            {
                removeA       = initialVertex;
                removeB       = oldVertex;
                longestLength = length;
            }
            //Console.WriteLine("Removing an edge of length "+ longestLength);
            //remove the longest edge
            return(gPlanar.RemoveEdge(removeA.Id, removeB.Id));
        }
Ejemplo n.º 2
0
        public static void MsaglShortcutShortEdges(Tiling g, Dictionary <int, Node> idToNodes,
                                                   LgLayoutSettings _lgLayoutSettings)
        {
            int unit = (int)_lgLayoutSettings.NodeSeparation;

            int shortcutcount = 1;
            int iteration     = 10;

            //Console.WriteLine();
            //Console.WriteLine("Minimize the number of railes for quick interaction? (Y/N)");
            //string input = Console.ReadLine();
            if (_lgLayoutSettings.hugeGraph)
            {
                iteration = 1;
                unit     *= 5;
            }

            while (shortcutcount > 0 && iteration > 0)
            {
                iteration--;
                //for all vertices that are not real vertices
                for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
                {
                    //current vertex is w
                    Vertex w = g.VList[index];

                    //for each neighbor of w
                    for (int k = 0; k < g.DegList[w.Id]; k++)
                    {
                        Vertex neighbor = g.VList[g.EList[w.Id, k].NodeId];

                        //if neighbor is a real vertex then continue
                        if (neighbor.Id < g.N)
                        {
                            continue;
                        }

                        //else check whether the edge is short
                        double l = g.GetEucledianDist(w.Id, neighbor.Id);

                        //if the length is short engough then short-cut
                        if (l < unit)
                        {
                            //shortcut this edge
                            //take all the neighbors of the 'neighbor' into the modification list
                            List <int> modificationList = new List <int>();
                            for (int j = 0; j < g.DegList[neighbor.Id]; j++)
                            {
                                int id = g.EList[neighbor.Id, j].NodeId;

                                if (id != w.Id)
                                {
                                    modificationList.Add(id);
                                }
                            }
                            //check whether it is safe to modify the graph
                            bool safetomodify = true;
                            if (g.DegList[w.Id] + modificationList.Count >= g.maxDeg)
                            {
                                continue;
                            }
                            foreach (var x in modificationList)
                            {
                                if (g.DegList[x] + 1 >= g.maxDeg)
                                {
                                    safetomodify = false;
                                }
                            }

                            foreach (var x in modificationList)
                            {
                                if (g.Crossings(w.Id, x))
                                {
                                    safetomodify = false;
                                }
                            }

                            if (!safetomodify)
                            {
                                continue;
                            }

                            //add edges between w and the neighbor's neighbor
                            foreach (var x in modificationList)
                            {
                                g.AddEdge(w.Id, x);
                            }

                            g.RemoveEdge(w.Id, neighbor.Id);
                            shortcutcount++;
                        }
                    }
                }
                unit *= 2;
            }
            Console.WriteLine("Shortcut made for " + shortcutcount + " edges");
        }