Exemple #1
0
        void AddToEdges(Node n, List <Node.weightedEdge> edg)
        {
            long a, b;

            foreach (Node.weightedEdge e in edg)
            {
                a = n.id;
                b = e.neighbour.id;

                if (!edges.ContainsKey(a))
                {
                    Dictionary <long, Node.weightedEdge> aEdges
                        = new Dictionary <long, Node.weightedEdge>();
                    edges.Add(a, aEdges);
                }
                if (!edges[a].ContainsKey(b))
                {
                    if ((edges.ContainsKey(b) && edges[b].ContainsKey(a)))
                    {
                        Node.weightedEdge e2 = edges[b][a];
                        e.id = e2.id;
                    }
                    else
                    {
                        e.id = id;
                        id++;
                        eIdEdges.Add(e.id, e);
                    }
                    edges[a].Add(b, e);
                }
            }
        }
Exemple #2
0
        void ProcessEdge(Node n, Node.weightedEdge e,
                         Dictionary <double, Node.weightedEdge> leftSector,
                         Dictionary <double, Node.weightedEdge> rightSector)
        {
            Segment.Vector v0 = new Segment.Vector();
            v0.x = n.coordinates.position.longitude;
            v0.y = n.coordinates.position.latitude;
            Segment.Vector v1 = new Segment.Vector();
            v1.x = e.neighbour.coordinates.position.longitude;
            v1.y = e.neighbour.coordinates.position.latitude;
            Segment seg = new Segment(v0, v1);

            if (v0.x > v1.x)
            {
                AddToSector(leftSector, seg.directionNr, e);
            }

            else if (v0.x < v1.x)
            {
                AddToSector(rightSector, seg.directionNr, e);
            }

            else if (v0.y < v1.y)
            {
                verticalEdges[0] = e;
            }
            else
            {
                verticalEdges[1] = e;
            }
        }
        private static void Init(Graph g, Dictionary<int, int> mess)
        {
            int k = 0;
            foreach (Node n in g.nodes.Values)
                n.backList = new List<Node.weightedEdge>();
            foreach (Node n in g.nodes.Values)
            {
                List<long> nbs = new List<long>();
                List<Node.weightedEdge> nnewe = new List<Node.weightedEdge>();
                foreach (Node.weightedEdge e in n.neighbourList)
                {
                    if (nbs.Contains(e.neighbour.id))
                        e.state = 8;
                    else
                    {
                        e.id = k;
                        mess.Add(k, e.weight);
                        k++;
                        nnewe.Add(e);

                        nbs.Add(e.neighbour.id);
                    }
                }
                n.neighbourList = nnewe;

            }
            foreach (Node n in g.nodes.Values)
            {
                foreach (Node.weightedEdge e in n.neighbourList)
                {

                    Node v = e.neighbour;
                    Node.weightedEdge ed = new Node.weightedEdge(n);
                    ed.weight = e.weight;
                    ed.id = e.id;
                    v.backList.Add(ed);

                    bool newSym = true;                                 //SYM
                    foreach (Node.weightedEdge es in n.symList)
                        if (es.neighbour.id == v.id)
                            newSym = false;
                    if (newSym)
                    {
                        n.AddSym(v);

                    }

                    newSym = true;                                 //SYM
                    foreach (Node.weightedEdge es in v.symList)
                        if (es.neighbour.id == n.id)
                            newSym = false;
                    if (newSym)
                    {
                        v.AddSym(n);

                    }
                }

            }
        }
Exemple #4
0
 void AddToSector(Dictionary <double, Node.weightedEdge> sector,
                  double dirNr, Node.weightedEdge e)
 {
     while (sector.ContainsKey(dirNr))     //mozna chyba
     {
         dirNr = dirNr + 0.00000001;
     }
     sector.Add(dirNr, e);
 }
 public bool IsInNeighbourList(List <Node.weightedEdge> edges, out Node.weightedEdge edge)
 {
     edge = null;
     foreach (Node.weightedEdge e in edges)
     {
         if (id == e.neighbour.id)
         {
             edge = e;
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
 private static void AddEdges(
     Graph g, Dictionary <long, Dictionary <long, int> > tmpEdges)
 {
     foreach (KeyValuePair <long, Dictionary <long, int> > pair in tmpEdges)
     {
         Node n = g.nodes[pair.Key];
         foreach (KeyValuePair <long, int> neigh in pair.Value)
         {
             Node.weightedEdge e
                      = new Node.weightedEdge(g.nodes[neigh.Key]);
             e.weight = neigh.Value;
             n.neighbourList.Add(e);
         }
     }
 }
        public void SetWeights()
        {
            foreach (Node n1 in nodes.Values)
            {
                for (int i = 0; i < n1.symList.Count; i++)

                {
                    Node.weightedEdge edge    = n1.symList[i];
                    double            weightD = n1.GetDistanceUTM(edge.neighbour) * 10000;
                    int weight = Math.Max(1, (int)weightD);
                    edge.SetWeight(weight);

                    Node b = edge.neighbour;
                }
            }
        }
        private void CreateEventsFromEdges(Node n, Node.weightedEdge e)
        {
            if (!n.inside)
            {
                return;
            }
            Segment.Vector v0 = new Segment.Vector();
            v0.x = n.coordinates.position.longitude;
            v0.y = n.coordinates.position.latitude;
            Segment.Vector v1 = new Segment.Vector();
            v1.x = e.neighbour.coordinates.position.longitude;
            v1.y = e.neighbour.coordinates.position.latitude;
            Segment      s          = new Segment(v0, v1);
            SegmentEvent eventStart = new SegmentEvent(SegmentEvent.type.Start, s.upperEnd, s);

            eventStart.nid0 = n.id;
            eventStart.nid1 = e.neighbour.id;
            if (eventStart.nid0 == eventStart.nid1)
            {
                return;
            }
            AddEvent(eventStart);
        }
        private static List <PlanarNode> OrderBoundaryNodes(
            PlanarGraph pg, Graph g, long srcId)
        {
            Dictionary <long, Node> boundaryNodes
                = new Dictionary <long, Node>();

            foreach (PlanarNode n in pg.planarNodes.Values.Where(x => !x.insideCR))
            {
                if (n.edgesIds.Count > 0)
                {
                    boundaryNodes.Add(g.nodes[n.nid].id, g.nodes[n.nid]);
                }
            }
            Graph boundaryGraph = new Graph();

            boundaryGraph.nodes = boundaryNodes;
            Node centre = new Node(-1);

            centre.coordinates = g.nodes[srcId].coordinates;
            foreach (Node n in boundaryNodes.Values)
            {
                Node.weightedEdge e = new Node.weightedEdge(n);
                e.weight = 1;
                centre.neighbourList.Add(e);
            }
            boundaryNodes.Add(centre.id, centre);
            PlanarGraph       boundaryPG = new PlanarGraph(boundaryGraph);
            PlanarNode        centrePG   = boundaryPG.planarNodes[-1];
            List <PlanarNode> result     = new List <PlanarNode>();

            foreach (int eid in centrePG.edgesIds)
            {
                result.Insert(0, boundaryPG.planarEdges[eid].GetNeigh(centrePG));
            }
            return(result);
        }
        public static void MergeEdges(Graph g, List <long> sep)
        {
            int  weigth = 0;
            Node last, next;
            Dictionary <long, Node> nodesM = new Dictionary <long, Node>();

            foreach (Node n in g.nodes.Values)
            {
                n.neighbourList = n.symList;
            }
            foreach (Node n in g.nodes.Values)
            {
                //    if (!n.inside)
                if (false)
                {
                    Node outN;
                    if (!nodesM.TryGetValue(n.id, out outN))
                    {
                        nodesM.Add(n.id, n);
                    }
                }
                else if (HasHighDegree(n, sep))
                {
                    List <Node.weightedEdge> path = new List <Node.weightedEdge>();

                    foreach (Node.weightedEdge e in n.neighbourList)
                    {
                        last = n;
                        path = new List <Node.weightedEdge>();
                        bool end = false;
                        next = e.neighbour;

                        weigth  = e.weight;
                        e.state = 1;
                        path.Add(e);
                        while ((!end))
                        {
                            if ((!HasHighDegree(next, sep)))
                            {
                                if (next.neighbourList.Count == 0)
                                {
                                    end = true;
                                    break;
                                }
                                Node.weightedEdge e2 = next.neighbourList[0];
                                if ((e2.state == 0) && (e2.neighbour.id != last.id))
                                {
                                    last = next;
                                    next = e2.neighbour;
                                }
                                else if (next.neighbourList.Count > 1) //never
                                {
                                    e2   = next.neighbourList[1];
                                    last = next;
                                    next = e2.neighbour;
                                }
                                else //pro kontrolu
                                {
                                    end = true;
                                    break;
                                }
                                path.Add(e2);
                                e2.state = 1;
                                weigth   = weigth + e2.weight;
                            }
                            else
                            {
                                end = true;
                            }
                        }
                        foreach (Node.weightedEdge e3 in path)
                        {
                            e3.state = 0;
                        }
                        Node.weightedEdge edge = new Node.weightedEdge(next);
                        edge.SetWeight(weigth);
                        n.mList.Add(edge);
                    }
                    nodesM.Add(n.id, n);
                }
            }
            double dN = 0;

            foreach (Node n in nodesM.Values)
            {
                List <Node.weightedEdge> backList2 = new List <Node.weightedEdge>();

                n.backList = backList2;

                n.symList       = new List <Node.weightedEdge>();
                n.neighbourList = n.mList;
                n.mList         = new List <Node.weightedEdge>();
                foreach (Node.weightedEdge e in n.neighbourList)
                {
                    Node.weightedEdge f = new Node.weightedEdge(n);
                    f.weight = e.weight;
                    e.neighbour.backList.Add(f);
                }
            }
            g.nodes = nodesM;
        }