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
        /// <summary>
        /// return an opposite vertex of a given edge
        /// </summary>
        int OppositeNode(MetroEdge edge, int v)
        {
            if (edge.Source() == v)
            {
                return(edge.Target());
            }
            if (edge.Target() == v)
            {
                return(edge.Source());
            }

            return(-1);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// recursively build an order on the edge
        /// </summary>
        List <int> RestoreResult(MetroEdge edge)
        {
            List <int> res = new List <int>();

            PathList pl = e2p[edge];

            if (pl.subLists == null)
            {
                foreach (PathOnEdge path in pl.paths)
                {
                    res.Add(path.index);
                }
            }
            else
            {
                foreach (PathList subList in pl.subLists)
                {
                    List <int> subResult = RestoreResult(subList.edge);
                    if (!(edge.Source() == subList.edge.Source() || edge.Target() == subList.edge.Target()))
                    {
                        subResult.Reverse();
                    }
                    res.AddRange(subResult);
                }
            }
            return(res);
        }
Ejemplo n.º 4
0
            internal static MetroEdge CreateFromTwoEdges(int v, MetroEdge e1, MetroEdge e2)
            {
                int s = e1.Source() == v?e1.Target() : e1.Source();

                int t = e2.Source() == v?e2.Target() : e2.Source();

                if (s < t)
                {
                    return(CreateFromTwoEdges(v, e1.nodes, e2.nodes));
                }
                else
                {
                    return(CreateFromTwoEdges(v, e2.nodes, e1.nodes));
                }
            }
        /// <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>
        /// return an opposite vertex of a given edge
        /// </summary>
        int OppositeNode(MetroEdge edge, int v) {
            if (edge.Source() == v) return edge.Target();
            if (edge.Target() == v) return edge.Source();

            return -1;
        }
        /// <summary>
        /// recursively build an order on the edge
        /// </summary>
        List<int> RestoreResult(MetroEdge edge) {
            List<int> res = new List<int>();

            PathList pl = e2p[edge];
            if (pl.subLists == null) {
                foreach (PathOnEdge path in pl.paths)
                    res.Add(path.index);
            }
            else {
                foreach (PathList subList in pl.subLists) {
                    List<int> subResult = RestoreResult(subList.edge);
                    if (!(edge.Source() == subList.edge.Source() || edge.Target() == subList.edge.Target()))
                        subResult.Reverse();
                    res.AddRange(subResult);
                }
            }
            return res;
        }
            internal static MetroEdge CreateFromTwoEdges(int v, MetroEdge e1, MetroEdge e2) {
                int s = e1.Source() == v ? e1.Target() : e1.Source();
                int t = e2.Source() == v ? e2.Target() : e2.Source();

                if (s < t)
                    return CreateFromTwoEdges(v, e1.nodes, e2.nodes);
                else
                    return CreateFromTwoEdges(v, e2.nodes, e1.nodes);
            }