Ejemplo n.º 1
0
        /// <summary>
        /// replace edges (av) and (vb) with edge (ab) on a given path
        /// </summary>
        void UpdatePath(PathOnEdge pathOnEdge, int v, MetroEdge newEdge)
        {
            LinkedListNode <MetroEdge> f = pathOnEdge.node;

            Debug.Assert(f.Value.Source() == v || f.Value.Target() == v);

            int a, b;

            a = OppositeNode(f.Value, v);

            if (f.Next != null && (b = OppositeNode(f.Next.Value, v)) != -1)
            {
                Debug.Assert((a == newEdge.Source() || a == newEdge.Target()));
                Debug.Assert((b == newEdge.Source() || b == newEdge.Target()));

                f.Value = newEdge;
                f.List.Remove(f.Next);
            }
            else if (f.Previous != null && (b = OppositeNode(f.Previous.Value, v)) != -1)
            {
                Debug.Assert((a == newEdge.Source() || a == newEdge.Target()));
                Debug.Assert((b == newEdge.Source() || b == newEdge.Target()));

                f.Value = newEdge;
                f.List.Remove(f.Previous);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 2
0
        void InitPathData()
        {
            paths = new Dictionary <int, LinkedList <MetroEdge> >();
            e2p   = new Dictionary <MetroEdge, PathList>();
            for (int mi = 0; mi < Metrolines.Count; mi++)
            {
                int[] Metroline = Metrolines[mi];
                paths.Add(mi, new LinkedList <MetroEdge>());

                for (int i = 0; i + 1 < Metroline.Length; i++)
                {
                    MetroEdge me = MetroEdge.CreateFromTwoNodes(Metroline[i], Metroline[i + 1]);

                    if (!e2p.ContainsKey(me))
                    {
                        PathList pl = new PathList();
                        pl.edge  = me;
                        pl.paths = new HashSet <PathOnEdge>();
                        e2p.Add(me, pl);
                    }

                    PathOnEdge pathOnEdge = new PathOnEdge();
                    pathOnEdge.index = mi;
                    pathOnEdge.node  = paths[mi].AddLast(me);
                    e2p[me].paths.Add(pathOnEdge);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// extract the next edge on a given path after node v
        /// </summary>
        MetroEdge FindNextEdgeOnPath(int v, PathOnEdge pathOnEdge)
        {
            if (pathOnEdge.node.Next != null)
            {
                int o = OppositeNode(pathOnEdge.node.Next.Value, v);
                if (o != -1)
                {
                    return(pathOnEdge.node.Next.Value);
                }
            }

            if (pathOnEdge.node.Previous != null)
            {
                int o = OppositeNode(pathOnEdge.node.Previous.Value, v);
                if (o != -1)
                {
                    return(pathOnEdge.node.Previous.Value);
                }
            }

            throw new NotSupportedException();
        }
        /// <summary>
        /// replace edges (av) and (vb) with edge (ab) on a given path
        /// </summary>
        void UpdatePath(PathOnEdge pathOnEdge, int v, MetroEdge newEdge) {
            LinkedListNode<MetroEdge> f = pathOnEdge.node;
            Debug.Assert(f.Value.Source() == v || f.Value.Target() == v);

            int a, b;

            a = OppositeNode(f.Value, v);

            if (f.Next != null && (b = OppositeNode(f.Next.Value, v)) != -1) {
                Debug.Assert((a == newEdge.Source() || a == newEdge.Target()));
                Debug.Assert((b == newEdge.Source() || b == newEdge.Target()));

                f.Value = newEdge;
                f.List.Remove(f.Next);
            }
            else if (f.Previous != null && (b = OppositeNode(f.Previous.Value, v)) != -1) {
                Debug.Assert((a == newEdge.Source() || a == newEdge.Target()));
                Debug.Assert((b == newEdge.Source() || b == newEdge.Target()));

                f.Value = newEdge;
                f.List.Remove(f.Previous);
            }
            else
                throw new NotSupportedException();
        }
        /// <summary>
        /// extract the next edge on a given path after node v
        /// </summary>
        MetroEdge FindNextEdgeOnPath(int v, PathOnEdge pathOnEdge) {
            if (pathOnEdge.node.Next != null) {
                int o = OppositeNode(pathOnEdge.node.Next.Value, v);
                if (o != -1) return pathOnEdge.node.Next.Value;
            }

            if (pathOnEdge.node.Previous != null) {
                int o = OppositeNode(pathOnEdge.node.Previous.Value, v);
                if (o != -1) return pathOnEdge.node.Previous.Value;
            }

            throw new NotSupportedException();
        }
        void InitPathData() {
            paths = new Dictionary<int, LinkedList<MetroEdge>>();
            e2p = new Dictionary<MetroEdge, PathList>();
            for (int mi = 0; mi < Metrolines.Count; mi++) {
                int[] Metroline = Metrolines[mi];
                paths.Add(mi, new LinkedList<MetroEdge>());

                for (int i = 0; i + 1 < Metroline.Length; i++) {
                    MetroEdge me = MetroEdge.CreateFromTwoNodes(Metroline[i], Metroline[i + 1]);

                    if (!e2p.ContainsKey(me)) {
                        PathList pl = new PathList();
                        pl.edge = me;
                        pl.paths = new HashSet<PathOnEdge>();
                        e2p.Add(me, pl);
                    }

                    PathOnEdge pathOnEdge = new PathOnEdge();
                    pathOnEdge.index = mi;
                    pathOnEdge.node = paths[mi].AddLast(me);
                    e2p[me].paths.Add(pathOnEdge);
                }
            }
        }