1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    IntermodalEdge.h
11 /// @author  Jakob Erdmann
12 /// @author  Michael Behrisch
13 /// @author  Robert Hilbrich
14 /// @date    Mon, 03 March 2014
15 /// @version $Id$
16 ///
17 // The Edge definition for the Intermodal Router
18 /****************************************************************************/
19 #ifndef IntermodalEdge_h
20 #define IntermodalEdge_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <utils/common/ValueTimeLine.h>
31 #include <utils/common/RandHelper.h>
32 #include "IntermodalTrip.h"
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
38 /// @brief the base edge type that is given to the internal router (SUMOAbstractRouter)
39 template<class E, class L, class N, class V>
40 class IntermodalEdge : public Named {
41 public:
42     IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = 0.) :
Named(id)43         Named(id),
44         myNumericalID(numericalID),
45         myEdge(edge),
46         myLine(line),
47         myLength(edge == nullptr || length > 0. ? length : edge->getLength()),
48         myEfforts(nullptr) { }
49 
~IntermodalEdge()50     virtual ~IntermodalEdge() {}
51 
includeInRoute(bool)52     virtual bool includeInRoute(bool /* allEdges */) const {
53         return false;
54     }
55 
getLine()56     inline const std::string& getLine() const {
57         return myLine;
58     }
59 
getEdge()60     inline const E* getEdge() const {
61         return myEdge;
62     }
63 
getNumericalID()64     int getNumericalID() const {
65         return myNumericalID;
66     }
67 
68     void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
69         myFollowingEdges.push_back(s);
70         myFollowingViaEdges.push_back(std::make_pair(s, via));
71     }
72 
transferSuccessors(IntermodalEdge * to)73     void transferSuccessors(IntermodalEdge* to) {
74         to->myFollowingEdges = myFollowingEdges;
75         to->myFollowingViaEdges = myFollowingViaEdges;
76         myFollowingEdges.clear();
77         myFollowingViaEdges.clear();
78     }
79 
removeSuccessor(const IntermodalEdge * const edge)80     void removeSuccessor(const IntermodalEdge* const edge) {
81         myFollowingEdges.erase(std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge));
82         for (auto it = myFollowingViaEdges.begin(); it != myFollowingViaEdges.end();) {
83             if (it->first == edge) {
84                 it = myFollowingViaEdges.erase(it);
85             } else {
86                 ++it;
87             }
88         }
89     }
90 
91     virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
92         UNUSED_PARAMETER(vClass);
93         // the network is already tailored. No need to check for permissions here
94         return myFollowingEdges;
95     }
96 
97     virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
98         UNUSED_PARAMETER(vClass);
99         // the network is already tailored. No need to check for permissions here
100         return myFollowingViaEdges;
101     }
102 
prohibits(const IntermodalTrip<E,N,V> * const)103     virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
104         return false;
105     }
106 
getTravelTime(const IntermodalTrip<E,N,V> * const,double)107     virtual double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
108         return 0.;
109     }
110 
111     /// @brief get intended vehicle id and departure time of next public transport ride
getIntended(const double,std::string &)112     virtual double getIntended(const double /* time */, std::string& /* intended */) const {
113         return 0.;
114     }
115 
getTravelTimeStatic(const IntermodalEdge * const edge,const IntermodalTrip<E,N,V> * const trip,double time)116     static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
117         return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
118     }
119 
getTravelTimeStaticRandomized(const IntermodalEdge * const edge,const IntermodalTrip<E,N,V> * const trip,double time)120     static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
121         return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);;
122     }
123 
getEffort(const IntermodalTrip<E,N,V> * const,double)124     virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
125         return 0.;
126     }
127 
getEffortStatic(const IntermodalEdge * const edge,const IntermodalTrip<E,N,V> * const trip,double time)128     static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
129         return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
130     }
131 
getLength()132     inline double getLength() const {
133         return myLength;
134     }
135 
setLength(const double length)136     inline void setLength(const double length) {
137         myLength = length;
138     }
139 
isInternal()140     inline bool isInternal() const {
141         return myEdge != nullptr && myEdge->isInternal();
142     }
143 
hasEffort()144     virtual bool hasEffort() const {
145         return myEfforts != nullptr;
146     }
147 
getStartPos()148     virtual double getStartPos() const {
149         return 0.;
150     }
151 
getEndPos()152     virtual double getEndPos() const {
153         return myLength;
154     }
155 
156     // only used by AStar
getSpeedLimit()157     inline double getSpeedLimit() const {
158         return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
159     }
160 
161     // only used by AStar
getLengthGeometryFactor()162     inline double getLengthGeometryFactor() const {
163         return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
164     }
165 
166     // only used by AStar
getDistanceTo(const IntermodalEdge * other)167     inline double getDistanceTo(const IntermodalEdge* other) const {
168         return myEdge != nullptr && other->myEdge != nullptr ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
169     }
170 
171     // only used by AStar
getMinimumTravelTime(const IntermodalTrip<E,N,V> * const trip)172     inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
173         return myLength / trip->getMaxSpeed();
174     }
175 
176 protected:
177     /// @brief List of edges that may be approached from this edge
178     std::vector<IntermodalEdge*> myFollowingEdges;
179 
180     /// @brief List of edges that may be approached from this edge with optional internal vias
181     std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
182 
183 private:
184     /// @brief the index in myEdges
185     const int myNumericalID;
186 
187     /// @brief  the original edge
188     const E* const myEdge;
189 
190     /// @brief public transport line or ped vs car
191     const std::string myLine;
192 
193     /// @brief adaptable length (for splitted edges)
194     double myLength;
195 
196     /// @brief Container for passing effort varying over time for the edge
197     ValueTimeLine<double>* myEfforts;
198 
199 private:
200     /// @brief Invalidated copy constructor
201     IntermodalEdge(const IntermodalEdge& src);
202 
203     /// @brief Invalidated assignment operator
204     IntermodalEdge& operator=(const IntermodalEdge& src);
205 
206 };
207 
208 
209 #endif
210 
211 /****************************************************************************/
212