GetSeparationTree(PlanarGraph pg, PlanarNode src)     //1610738   78794
        {
            pg = Triangulation.GetTriangulation(pg);
            PlanarEdge ww = pg.planarEdges[1630674];
            Dictionary <PlanarEdge, int> cyclesTriEdges
                = new Dictionary <PlanarEdge, int>();
            StreamReader r = new StreamReader("C:\\Users\\L\\Desktop\\triCycles.txt");

            while (!r.EndOfStream)
            {
                string   line = r.ReadLine();
                string[] spl  = line.Split(new char[] { ' ' },
                                           StringSplitOptions.RemoveEmptyEntries);
                cyclesTriEdges.Add(
                    pg.planarEdges[int.Parse(spl[0])], int.Parse(spl[0]));
            }
            int max = cyclesTriEdges.Values.Max();
            KeyValuePair <PlanarEdge, int> maxTriE
                = cyclesTriEdges.Where(x => x.Value == max).First();

            cyclesTriEdges.Remove(maxTriE.Key);

            SeparatorCycle    cycle = new SeparatorCycle(pg);
            List <PlanarNode> inC;
            List <PlanarNode> outC;
            List <PlanarNode> sep = cycle.SeparateByEdge(
                pg.planarEdges[1630674], pg.planarNodes.First().Value, out inC, out outC);

            return(null);
            //      DecompositionTreeItem rootIte
        }
        private void SetCycleCostUpward(ref PlanarNode n, PlanarEdge pn, PlanarEdge nch,
                                        out PlanarNode last, ref int sum0, ref int sum1)
        {
            PlanarNode par = n.parent;

            last = n;
            //       while (par!=null && par.nid!=commonAnc.nid)
            while (n != null && n.nid != commonAnc.nid)
            {
                SetCycleCostAroundN(n, pn, nch, ref sum0, ref sum1);
                nch  = pn;
                last = n;
                n    = n.parent;
                if (n.parent == null) //||(reversed&&n.parent.state==-3))
                {
                    break;
                }
                foreach (int eid in n.edgesIds)
                {
                    if (g.planarEdges.ContainsKey(eid) &&
                        g.planarEdges[eid].GetNeigh(n).nid == n.parent.nid)
                    {
                        pn = g.planarEdges[eid];
                        break;
                    }
                }
            }
        }
        public List <PlanarNode> SeparateByEdge(
            PlanarEdge f, PlanarNode src,
            out List <PlanarNode> inC, out List <PlanarNode> outC)
        {
            Bfs.Src_all_bfs(src, g.planarNodes, g.planarEdges, true);
            SetCycleCost(f);
            Bfs.Src_all_bfs(src, g.planarNodes, g.planarEdges, true);
            inC  = new List <PlanarNode>();
            outC = new List <PlanarNode>();
            List <PlanarNode> sep = new List <PlanarNode>();

            foreach (PlanarNode n in g.planarNodes.Values)
            {
                if (cycle.Contains(n.nid))
                {
                    continue;
                }
                if (n.insideCycle)
                {
                    inC.Add(n);
                    n.insideCycle = false;
                }
                else
                {
                    outC.Add(n);
                }
            }
            return(sep);
        }
Ejemplo n.º 4
0
 public PlanarEdge(PlanarEdge e, PlanarNode oldNeigh, PlanarNode newNeigh)
 {
     new PlanarEdge(e);
     UpdateNeighbour(oldNeigh, newNeigh);
     newNeigh.edgesIds.Add(eid);
     w = oldNeigh.dist + e.w;
 }
        private void SetCycleCostAroundAnc(PlanarNode anc, PlanarNode last, ref int sum0, ref int sum1)
        {
            // return;
            PlanarEdge pn  = null;
            PlanarEdge nch = null;

            foreach (int eid in anc.edgesIds)
            {
                if (g.planarEdges[eid].GetNeigh(anc).state == -3)  //count=2
                {
                    if (g.planarEdges[eid].GetNeigh(anc).nid == last.nid)
                    {
                        nch = g.planarEdges[eid];
                        if (pn == null)
                        {
                            pn = nch; //src muze mit jen jednu hr.
                        }
                    }
                    else
                    {
                        pn = g.planarEdges[eid];
                    }
                }
            }
            ;
            SetCycleCostAroundN(anc, pn, nch, ref sum0, ref sum1);
        }
        private bool Has_left_yz_path(PlanarNode z, PlanarNode zchild)
        {
            int lastEid = -1;

            foreach (int eid in z.edgesIds)
            {
                if (g.planarEdges[eid].GetNeigh(z).nid == zchild.nid)
                {
                    lastEid = eid;
                    break;
                }
            }
            PlanarEdge e = g.planarEdges[g.planarEdges[lastEid].GetNextEdgeId(z)];
            PlanarNode u = e.GetNeigh(z);

            while (u.state > -2)
            {
                e = g.planarEdges[e.GetNextEdgeId(z)];

                u = e.GetNeigh(z);
            }
            if (u.parent.nid == z.nid)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 public PlanarEdgeRepre(PlanarNode n0, PlanarNode n1, PlanarEdge n0e)
 {
     arr[0] = n0;
     arr[1] = n1;
     arr[2] = n0e;
     //arr[4] = -1;
     //arr[5] = -1;
 }
        private static bool FindSeparator(PlanarNode src,
                                          List <PlanarNode> orderNodes, PlanarGraph pg,
                                          SeparatorCycle sepCycle, out PlanarEdge f)
        {
            List <PlanarNode> insideBoundaryNodes =
                orderNodes
                .Where(y => pg.planarNodes.ContainsKey(y.nid)).ToList();

            for (int i = 0; i < insideBoundaryNodes.Count - 1; i = i + 1)
            {
                for (int j = i + 1; j < insideBoundaryNodes.Count; j = j + 1)
                {
                    PlanarNode src2 = pg.planarNodes[srcId];
                    Bfs.Src_all_bfs(src2, pg.planarNodes, pg.planarEdges, true);
                    PlanarNode u = pg.planarNodes[insideBoundaryNodes[i].nid];
                    PlanarNode v = pg.planarNodes[insideBoundaryNodes[j].nid];
                    f      = new PlanarEdge(u, v);
                    f.eid  = -pg.planarEdges.Count - 1;
                    f.trgl = true;
                    pg.planarEdges.Add(f.eid, f);
                    u.edgesIds.Add(f.eid);
                    v.edgesIds.Add(f.eid);
                    //   SeparatorCycle sepCycle = new SeparatorCycle();
                    sepCycle.GetBoundaryCycle(pg, src2, f);

                    int max = (int)(c * pg.planarNodes.Count);
                    if (sepCycle.inC.Count < max &&
                        sepCycle.outC.Count < max)
                    {
                        Console.WriteLine(gc + "  " + sepCycle.inC.Count + " " + u.nid + " " + v.nid);
                        //  ResetGraph(pg);
                        return(true);
                    }

                    else
                    {
                        u.edgesIds.Remove(f.eid);
                        v.edgesIds.Remove(f.eid);
                    }
                    ResetGraph(pg);
                    //          break;
                }
            }
            f = null;
            if (c == 4f / 5)
            {
                c = 19f / 20;
                return(FindSeparator(src, orderNodes, pg, sepCycle, out f));
            }
            else

            {
                //   c = 4f / 5;
                Console.WriteLine("not: " + gc + "  " + pg.planarNodes.Count);
                return(FindSeparatorOnTriangulation(src, pg, sepCycle));
            }
        }
 private int GetInsideDescCostFromXToZAroundY(PlanarNode y,
                                              PlanarNode z, PlanarEdge xy, out PlanarEdge yz, bool leftpath)
 {
     if (leftpath)
     {
         return(GetDescCostFromZToXAroundY(y, z, xy, out yz));
     }
     return(GetDescCostFromXToZAroundY(y, z, xy, out yz));
 }
Ejemplo n.º 10
0
        private static void GetTriangulationFromTo(Dictionary <long, List <long> > tri,
                                                   PlanarGraph g,
                                                   PlanarNode n1, int eid0, int eid1)
        {
            try
            {
                if (!(g.planarEdges.ContainsKey(eid0) &&
                      g.planarEdges.ContainsKey(eid1)))
                {
                    return;
                }
                PlanarEdge e0 = g.planarEdges[eid0];

                PlanarEdge e1 = g.planarEdges[eid1];
                PlanarNode n0 = e0.GetNeigh(n1);
                PlanarNode n2 = e1.GetNeigh(n1);
                if (!n2.edgesIds.Contains(e1.eid))
                {
                    return;
                }
                int fid = e1.GetNextEdgeId(n2);
                if (!(g.planarEdges.ContainsKey(fid)))
                {
                    return;
                }
                PlanarEdge f  = g.planarEdges[fid];
                PlanarNode n3 = f.GetNeigh(n2);
                if (n0.nid == n3.nid)
                {
                    return;        //triangle
                }
                if (tri.ContainsKey(n0.nid) && tri[n0.nid].Contains(n2.nid))
                {
                    return;
                }
                if (!tri.ContainsKey(n0.nid) ||
                    (!tri.ContainsKey(n1.nid)) || (!tri.ContainsKey(n2.nid)))
                {
                    return;
                }
                tri[n0.nid].Add(n2.nid);
                tri[n2.nid].Add(n0.nid);
                PlanarEdge te = new PlanarEdge(n0, n2, 0, 0, 0);
                te.trgl = true;
                te.eid  = newId;
                newId++;
                InsertAsFirst(n0, eid0, te.eid);
                InsertAsSecond(n2, eid1, te.eid);
                g.planarEdges.Add(te.eid, te);
                triEdges.Add(te);
                //tri.Add(te.eid);
            }
            catch (Exception ex)
            {
                return;
            }
        }
Ejemplo n.º 11
0
        public PlanarEdge(PlanarEdge e)
        {
            PlanarEdgeRepre repre = new PlanarEdgeRepre(
                (PlanarNode)e.neighboursAdjEdges[0], (PlanarNode)e.neighboursAdjEdges[1]);

            neighboursAdjEdges = repre.arr;
            w      = e.w;
            trgl   = e.trgl;
            inTree = e.inTree;
            eid    = e.eid;
        }
        //step 6
        private PlanarGraph CreateShrinkedGraph(Dictionary <int, List <long> > levels,
                                                PlanarGraph pg, long srcNid)
        {
            Dictionary <long, PlanarNode> originalNodes
                = new Dictionary <long, PlanarNode>(pg.planarNodes);
            Dictionary <long, PlanarNode> shrNodes = new Dictionary <long, PlanarNode>();

            foreach (int key in levels.Keys)
            {
                if (key >= lev0)// && key <= lev2)
                {
                    foreach (long nid in levels[key])
                    {
                        PlanarNode n = pg.planarNodes[nid];
                        shrNodes.Add(n.nid, n);
                    }
                }
            }
            PlanarNode src2 = originalNodes[srcNid];

            shrNodes.Add(src2.nid, src2);
            foreach (PlanarNode n in shrNodes.Values)
            {
                break;
                List <int> newEdgesIds = new List <int>();
                foreach (int eid in n.edgesIds)
                {
                    PlanarEdge e     = pg.planarEdges[eid];
                    PlanarNode neigh = e.GetNeigh(n);
                    if (shrNodes.ContainsKey(neigh.nid))
                    {
                        newEdgesIds.Add(eid);
                    }
                }
                n.edgesIds = newEdgesIds;
            }
            Dictionary <int, PlanarEdge> shrEdges = new Dictionary <int, PlanarEdge>();

            foreach (PlanarEdge e in pg.planarEdges.Values)
            {
                break;
                if (shrNodes.ContainsKey(
                        ((PlanarNode)e.neighboursAdjEdges[0]).nid)
                    &&
                    shrNodes.ContainsKey(
                        ((PlanarNode)e.neighboursAdjEdges[1]).nid))
                {
                    shrEdges.Add(e.eid, e);
                }
            }
            GoAroundBnfTree(pg.planarNodes, levels, src2);
            return(new PlanarGraph(shrNodes, shrEdges));
        }
Ejemplo n.º 13
0
        private static void CheckNextEdges(PlanarGraph g, PlanarEdge e)
        {
            PlanarEdge ne = (PlanarEdge)e.neighboursAdjEdges[2];

            if (!g.planarEdges.Keys.Contains(ne.eid))
            {
                e.neighboursAdjEdges[2] = FindAndSetNewNextEdge(g, (PlanarNode)e.neighboursAdjEdges[0], ne);
            }
            //          ne = (PlanarEdge)e.neighboursAdjEdges[4];
            //          if (!g.planarEdges.Keys.Contains(ne.eid))
            //              e.neighboursAdjEdges[4] = FindAndSetNewNextEdge(g, (PlanarNode)e.neighboursAdjEdges[1], ne);
        }
        private PlanarEdge ExpandCycleWithTriangle(PlanarNode y,
                                                   PlanarEdge yx, PlanarEdge treeEdge)
        {
            y.state = -3;
            PlanarEdge next = g.planarEdges[yx.GetNextEdgeId(y)];
            //     int yDescCost = GetInsideDescCostForNextTwoEdges(y,next, yx);
            int yDescCost = GetDescCost(y, next.GetNeigh(y));

            insideDescCost  = insideDescCost - yDescCost;
            outsideDescCost = outsideDescCost + yDescCost;
            return(next);
        }
        bool Check(PlanarEdge e, PlanarNode n, PlanarNode src2, Dictionary <long, bool> table)
        {
            PlanarNode neigh = e.GetNeigh(n);

            if (table[neigh.nid])
            {
                return(false);
            }
            table[neigh.nid] = true;
            e.UpdateNeighbour(n, src2);
            //
            src2.edgesIds.Add(e.eid);
            return(true);
        }
        private static void Close(PriorityQueue <PlanarNode> opened,
                                  Dictionary <int, PlanarEdge> planarEdges, bool parentUpdate)
        {
            PlanarNode n = opened.RemoveMin();

            //     opened.RemoveAt(0);
            n.state = 2;
            foreach (int eid in n.edgesIds)
            {
                if (!planarEdges.ContainsKey(eid))
                {
                    continue;
                }
                PlanarEdge e = planarEdges[eid];
                if (e.trgl)
                {
                    continue;
                }
                PlanarNode neigh = e.GetNeigh(n);
                if (neigh == null)
                {
                    continue;
                }
                if (neigh.dist > n.dist + e.w)
                {
                    e.parent = n;
                    e.inTree = true;
                    if (parentUpdate)
                    {
                        neigh.parent = n;
                        if (!neigh.insideCycle)
                        {
                            neigh.insideCycle = neigh.parent.insideCycle;
                        }


                        //  n.children.Add(neigh);
                    }

                    else
                    {
                        part0.Add(n.nid);
                    }
                    neigh.dist  = n.dist + e.w;
                    neigh.state = 1;
                    opened.Add(neigh.dist, neigh);
                }
            }
        }
Ejemplo n.º 17
0
 private static void UpdateNextEdges(PlanarNode src, PlanarEdge e, PlanarEdge nextE)
 {
     if (src == e.neighboursAdjEdges[0])
     {
         e.neighboursAdjEdges[2] = nextE;
     }
     else if (src == e.neighboursAdjEdges[1])
     {
         e.neighboursAdjEdges[3] = nextE;
     }
     else
     {
         throw new Exception();
     }
 }
 private void SetCycleCostAroundN(PlanarNode n, PlanarEdge pn, PlanarEdge nch,
                                  ref int sum0, ref int sum1)
 {
     int[] sums = SplitEdges(n.edgesIds, pn, nch, n);
     if (!reversed)
     {
         sum0 = sum0 + sums[0];
         sum1 = sum1 + sums[1];
     }
     else
     {
         sum0 = sum0 + sums[1];
         sum1 = sum1 + sums[0];
     }
 }
Ejemplo n.º 19
0
        private static PlanarEdge FindAndSetNewNextEdge(PlanarGraph g, PlanarNode n, PlanarEdge ne)
        {
            int ind  = n.edgesIds.FindIndex(x => x == ne.eid);
            int neid = ne.eid;

            while (!g.planarEdges.ContainsKey(neid))
            {
                n.edgesIds.Remove(neid);
                if (ind == n.edgesIds.Count)
                {
                    ind = n.edgesIds.Count() - 1;
                }
                neid = n.edgesIds.ElementAt(ind);
            }
            ne = g.planarEdges[neid];
            return(ne);
        }
        public bool GetBoundaryCycle(PlanarGraph graph, PlanarNode src,
                                     PlanarEdge f) //step 8
        {
            g = graph;

            allCostSum = g.planarNodes.Count; //cost=1
            int index = allCostSum / 2;

            SetCycleCost(f);
            src.insideCycle = false;
            Bfs.Src_all_bfs(src, g.planarNodes, g.planarEdges, true);
            inC  = new List <PlanarNode>();
            outC = new List <PlanarNode>();
            order++;
            foreach (PlanarNode n in g.planarNodes.Values)
            {
                if (cycle.Contains(n.nid))
                {
                    continue;
                }
                if (n.insideCycle)
                {
                    inC.Add(n);
                    n.insideCycle = false;
                }

                else// if (!cycle.Contains(n.nid))
                {
                    outC.Add(n);
                };                //vc sep
            }

            List <PlanarNode> min;

            if (inC.Count > outC.Count)
            {
                min = outC;
            }
            else
            {
                min = inC;
            }
            // if (!cyclesNodes.ContainsKey(f.eid))
            //      cyclesNodes.Add(f.eid, min);
            return(min.Count > (g.planarNodes.Count) / 3);
        }
        private int GetDescCostFromXToZAroundY(PlanarNode y,   //rigth path
                                               PlanarNode z, PlanarEdge xy, out PlanarEdge yz)
        {
            int descCost = 0;

            yz = xy;
            PlanarNode w = yz.GetNeigh(y);

            while (w.nid != z.nid)
            {
                yz = g.planarEdges[yz.GetNextEdgeId(y)];

                w        = yz.GetNeigh(y);
                descCost = descCost + GetDescCost(y, w);
            }
            return(descCost);
        }
        private int[] SplitEdges(List <int> eids, PlanarEdge pn, PlanarEdge nch, PlanarNode n)
        {
            int        ipn    = eids.IndexOf(pn.eid);
            int        inch   = eids.IndexOf(nch.eid);
            List <int> pn_nch = new List <int>();
            List <int> nch_pn = new List <int>();

            int[] result = new int[] { 0, 0 };
            if (ipn < inch)
            {
                pn_nch = eids.GetRange(ipn + 1, inch - (ipn + 1));
                nch_pn = eids.GetRange(0, ipn);
                nch_pn.AddRange(eids.GetRange(inch + 1, eids.Count - (inch + 1)));
            }
            else if (ipn > inch)
            {
                nch_pn = eids.GetRange(inch + 1, ipn - (inch + 1));
                pn_nch = eids.GetRange(0, inch);
                pn_nch.AddRange(eids.GetRange(ipn + 1, eids.Count - (ipn + 1)));
            }
            else
            {
                pn_nch = new List <int>(eids);
                pn_nch.Remove(pn.eid);
            }

            foreach (int eid in pn_nch.Where(ei => g.planarEdges.ContainsKey(ei)))
            {
                result[0] = result[0] + GetDescCost(n, g.planarEdges[eid].GetNeigh(n));
                if (!reversed)
                {
                    g.planarEdges[eid].GetNeigh(n).insideCycle = true;
                }
            }

            foreach (int eid in nch_pn.Where(ei => g.planarEdges.ContainsKey(ei)))
            {
                result[1] = result[1] + GetDescCost(n, g.planarEdges[eid].GetNeigh(n));
                if (reversed)
                {
                    g.planarEdges[eid].GetNeigh(n).insideCycle = true;
                }
            }

            return(result);
        }
        private PlanarEdge ExpandCycleWithNewCycle(PlanarNode y,
                                                   PlanarEdge yv, PlanarEdge yw)
        {
            PlanarNode z             = y;
            PlanarNode zchild        = y;
            int        totalPathCost = 0;

            while (z.parent != null && z.parent.state > -2)
            {
                z.state       = -3;
                totalPathCost = totalPathCost + z.cost;
                zchild        = z;
                z             = z.parent;
            }
            PlanarNode v = yv.GetNeigh(y);
            PlanarNode w = yw.GetNeigh(y);
            ///
            bool left_yz_path = Has_left_yz_path(z, zchild);
            //
            PlanarEdge result_y_e;

            int[] insideCycleCost = ScanBothNewCycles(
                left_yz_path, v, w, y, yv, yw, out result_y_e);
            int        yvInsideCycleCost = insideCycleCost[0];
            int        ywInsideCycleCost = insideCycleCost[1];
            int        insideCostOfSmallCycle;
            PlanarNode smallCycleLeave, bigCycleLeave;

            if (result_y_e.GetNeigh(y).nid == v.nid)
            {
                smallCycleLeave        = v;
                bigCycleLeave          = w;
                insideCostOfSmallCycle = yvInsideCycleCost;
            }
            else
            {
                smallCycleLeave        = w;
                bigCycleLeave          = v;
                insideCostOfSmallCycle = ywInsideCycleCost;
            }
            int costOfBigCycle =
                GetInsideCostOfBigCycle(insideCostOfSmallCycle, insideDescCost, totalPathCost);

            return(result_y_e);
        }
        private int GetDescCostFromZToXAroundY(PlanarNode y,   // left path
                                               PlanarNode z, PlanarEdge xy, out PlanarEdge yz)
        {
            yz = xy;
            PlanarNode w = yz.GetNeigh(y);

            while (w.nid != z.nid)
            {
                yz = g.planarEdges[yz.GetNextEdgeId(y)];

                w = yz.GetNeigh(y);
            }
            PlanarEdge e = yz;
            PlanarEdge e0;
            int        descCost = GetDescCostFromXToZAroundY(y, xy.GetNeigh(y), e, out e0);

            return(descCost);
        }
        private void GetDistDiff(PlanarNode u, PlanarNode v, PlanarEdge e, int lev0)
        {
            if (u.dist == int.MaxValue || v.dist == int.MaxValue)
            {
                return;
            }
            if (u.dist < lev0 && v.dist < lev0)
            {
                return;
            }
            int sz = Math.Abs(u.dist - v.dist);

            if (!cyclesSizes.ContainsKey(sz))
            {
                cyclesSizes.Add(sz, new List <PlanarEdge>());
            }
            cyclesSizes[sz].Add(e);
        }
        private void GetCycle(PlanarNode u, PlanarNode v, PlanarEdge e)
        {
            cycle = new List <long>();
            PlanarNode x     = u;
            int        state = -3;

            while (x.parent != null)
            {
                cycle.Add(x.nid);
                x.state = state;//cycle
                x       = x.parent;
            }
            cycle.Add(x.nid);
            x.state   = state;
            commonAnc = x;
            x         = v;
            int size = 1;

            while (x.parent != null)
            {
                cycle.Add(x.nid);
                size++;
                x.state = state;
                if (x.parent.state == -3 && state == -3)
                {
                    commonAnc = x.parent;
                    break;
                }

                x = x.parent;
            }
            return;

            x     = u;
            state = 0;

            while (x.parent != null)
            {
                x.state = state;//cycle
                x       = x.parent;
            }
            //    if (!cyclesSizes.ContainsKey(size))
            //        cyclesSizes.Add(size, e);
        }
        private int GetInsideDescCostForNextTwoEdges(PlanarNode y,   //smazat/test
                                                     PlanarEdge e, PlanarEdge f)
        {
            int descCost = 0;

            foreach (int eid in y.edgesIds)
            {
                if (eid == e.eid || eid == f.eid)
                {
                    continue;
                }
                PlanarEdge ye = g.planarEdges[eid];
                if (ye.inTree)
                {
                    descCost = descCost + GetDescCost(y, ye.GetNeigh(y));
                }
            }
            return(descCost);
        }
        void CloseEdge(PlanarNode n, int dist, List <PlanarEdge> opened)
        {
            PlanarEdge e = opened[0];

            opened.RemoveAt(0);
            e.state = 2;

            PlanarNode neigh0, neigh1, neigh;
            PlanarEdge e2 = e.GetNextEdge(e.parent, out neigh0);

            if (e2.state == 0)
            {
                neigh = e2.GetNeigh(e.parent);

                e2.state = 1;
                e2.dist  = e.parent.dist + e2.w;
                if (neigh.dist == 0)
                {
                    neigh.dist   = e2.dist;
                    e2.parent    = e.parent;
                    neigh.parent = e2.parent;
                    opened.Add(e2);
                    CloseEdge(null, 0, opened);
                }
            }
            PlanarEdge f2 = e.GetNextEdge(neigh0, out neigh1);

            if (f2.state == 0)
            {
                neigh1 = f2.GetNeigh(neigh0);

                f2.state = 1;
                f2.dist  = e.dist + f2.w;
                if (neigh1.dist == 0)
                {
                    neigh1.dist   = f2.dist;
                    f2.parent     = neigh0;
                    neigh1.parent = f2.parent;
                    opened.Add(f2);
                }
            }
        }
        private PlanarEdge ExpandCycle(PlanarNode v, PlanarNode w, PlanarEdge e)
        {
            PlanarNode y, n;
            PlanarEdge yv, yw, next;

            if (isSum0inside)
            {
                //  yv =g.planarEdges[ e.GetNextEdgeId(v)];
                yw = g.planarEdges[e.GetNextEdgeId(w)];
                y  = yw.GetNeigh(w);
                yv = g.planarEdges[yw.GetNextEdgeId(y)];
            }
            else
            {
                yv = g.planarEdges[e.GetNextEdgeId(v)];
                //  yw = g.planarEdges[e.GetNextEdgeId(w)];
                y  = yv.GetNeigh(v);
                yw = g.planarEdges[yv.GetNextEdgeId(w)];
            }
            if (yv.inTree)
            {
                next = ExpandCycleWithTriangle(y, yw, yv);
                cycle.Add(next.GetNeigh(y).nid);
                //  next = yw;
            }
            else if (yw.inTree)
            {
                ExpandCycleWithTriangle(y, yv, yw);
                next = yv;
            }
            else
            {
                SetCycleCost(yv);
                return(yv);
                // int sum0_v = sum0_v;
                //  SetCycleCost()
                // next = ExpandCycleWithNewCycle(y, yv, yw);

                //  dopocitat a dosadit inscost outscost
            }
            return(next);
        }
Ejemplo n.º 30
0
        public static void RemoveEdges(PlanarGraph g, PlanarNode src, int minLevel, int maxLevel)  //jde udelat ryz=chleji primo v alg.sep.
        {
            foreach (PlanarNode n in g.planarNodes.Values)
            {
                if (n.parent != null && !g.planarNodes.ContainsKey(n.parent.nid))
                {
                    n.parent = src;
                }
            }

            List <int> keys = new List <int>(g.planarEdges.Keys);

            foreach (int key in keys)
            {
                PlanarEdge e  = g.planarEdges[key];
                PlanarNode n0 = (PlanarNode)e.neighboursAdjEdges[0];
                PlanarNode n1 = (PlanarNode)e.neighboursAdjEdges[1];
                if (IsOutsideLevels(n0.dist, n1.dist, minLevel, maxLevel))
                {
                    g.planarEdges.Remove(key);
                }
                else
                {
                    if (!g.planarNodes.ContainsKey(n0.nid))
                    {
                        g.planarNodes.Add(n0.nid, n0);
                    }
                    if (!g.planarNodes.ContainsKey(n1.nid))
                    {
                        g.planarNodes.Add(n1.nid, n1);
                    }
                }
            }
            foreach (PlanarEdge e in g.planarEdges.Values)
            {
                CheckNextEdges(g, e);  //smazat
            }
            foreach (PlanarNode n in g.planarNodes.Values)
            {
                CheckEdgesIds(g, n);
            }
        }