SUMO - Simulation of Urban MObility
IntermodalEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The Edge definition for the Intermodal Router
20 /****************************************************************************/
21 #ifndef IntermodalEdge_h
22 #define IntermodalEdge_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <algorithm>
37 #include <assert.h>
38 #include <utils/common/Named.h>
39 #include <utils/common/SUMOTime.h>
40 #include <utils/common/ToString.h>
42 
43 #define TL_RED_PENALTY 20
44 
45 //#define IntermodalRouter_DEBUG_EFFORTS
46 
47 
48 template <class E, class L>
49 inline const L* getSidewalk(const E* edge) {
50  if (edge == nullptr) {
51  return nullptr;
52  }
53  // prefer lanes that are exclusive to pedestrians
54  const std::vector<L*>& lanes = edge->getLanes();
55  for (const L* const lane : lanes) {
56  if (lane->getPermissions() == SVC_PEDESTRIAN) {
57  return lane;
58  }
59  }
60  for (const L* const lane : lanes) {
61  if (lane->allowsVehicleClass(SVC_PEDESTRIAN)) {
62  return lane;
63  }
64  }
65  return nullptr;
66 }
67 
68 
69 // ===========================================================================
70 // class definitions
71 // ===========================================================================
72 
74 template<class E, class N, class V>
76 
77  IntermodalTrip(const E* _from, const E* _to, double _departPos, double _arrivalPos,
78  double _speed, SUMOTime _departTime, const N* _node,
79  const V* _vehicle = 0, const SVCPermissions _modeSet = SVC_PEDESTRIAN) :
80  from(_from),
81  to(_to),
82  departPos(_departPos < 0 ? _from->getLength() + _departPos : _departPos),
83  arrivalPos(_arrivalPos < 0 ? _to->getLength() + _arrivalPos : _arrivalPos),
84  speed(_speed),
85  departTime(_departTime),
86  node(_node),
87  vehicle(_vehicle),
88  modeSet(_modeSet) {
89  }
90 
91  // exists just for debugging purposes
92  std::string getID() const {
93  return from->getID() + ":" + to->getID() + ":" + time2string(departTime);
94  }
95 
96 
97  inline SUMOVehicleClass getVClass() const {
98  return vehicle != 0 ? vehicle->getVClass() : SVC_PEDESTRIAN;
99  }
100 
101  const E* const from;
102  const E* const to;
103  const double departPos;
104  const double arrivalPos;
105  const double speed;
107  const N* const node; // indicates whether only routing across this node shall be performed
108  const V* const vehicle; // indicates which vehicle may be used
110 private:
113 };
114 
115 
117 template<class E, class L, class N, class V>
118 class IntermodalEdge : public Named {
119 public:
120  IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line) :
121  Named(id),
122  myNumericalID(numericalID),
123  myEdge(edge),
124  myLine(line),
125  myLength(edge == nullptr ? 0. : edge->getLength()),
126  myEfforts(nullptr) { }
127 
128  virtual ~IntermodalEdge() {}
129 
130  virtual bool includeInRoute(bool /* allEdges */) const {
131  return false;
132  }
133 
134  inline const std::string& getLine() const {
135  return myLine;
136  }
137 
138  inline const E* getEdge() const {
139  return myEdge;
140  }
141 
142  int getNumericalID() const {
143  return myNumericalID;
144  }
145 
147  myFollowingEdges.push_back(s);
148  }
149 
150  void setSuccessors(const std::vector<IntermodalEdge*>& edges) {
151  myFollowingEdges = edges;
152  }
153 
155  myFollowingEdges.clear();
156  }
157 
158  void removeSuccessor(const IntermodalEdge* const edge) {
159  myFollowingEdges.erase(std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge));
160  }
161 
162  virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass /*vClass*/) const {
163  // the network is already tailored. No need to check for permissions here
164  return myFollowingEdges;
165  }
166 
167  virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
168  return false;
169  }
170 
171  virtual double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
172  return 0.;
173  }
174 
175  static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
176  return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
177  }
178 
179  virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
180  return 0.;
181  }
182 
183  static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
184  return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
185  }
186 
187  inline double getLength() const {
188  return myLength;
189  }
190 
191  inline void setLength(const double length) {
192  myLength = length;
193  }
194 
195  virtual bool hasEffort() {
196  return myEfforts != nullptr;
197  }
198 
199 protected:
201  std::vector<IntermodalEdge*> myFollowingEdges;
202 
203 private:
205  const int myNumericalID;
206 
208  const E* const myEdge;
209 
211  const std::string myLine;
212 
214  double myLength;
215 
218 
219 private:
221  IntermodalEdge(const IntermodalEdge& src);
222 
225 
226 };
227 
228 
230 template<class E, class L, class N, class V>
231 class PedestrianEdge : public IntermodalEdge<E, L, N, V> {
232 public:
233  PedestrianEdge(int numericalID, const E* edge, const L* lane, bool forward, const double pos = -1.) :
234  IntermodalEdge<E, L, N, V>(edge->getID() + (edge->isWalkingArea() ? "" : (forward ? "_fwd" : "_bwd")) + toString(pos), numericalID, edge, "!ped"),
235  myLane(lane),
236  myForward(forward),
237  myStartPos(pos >= 0 ? pos : (forward ? 0. : edge->getLength())) { }
238 
239  bool includeInRoute(bool allEdges) const {
240  return allEdges || (!this->getEdge()->isCrossing() && !this->getEdge()->isWalkingArea());
241  }
242 
243  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
244  if (trip->node == 0) {
245  // network only includes IntermodalEdges
246  return false;
247  } else {
248  // limit routing to the surroundings of the specified node
249  return (this->getEdge()->getFromJunction() != trip->node
250  && this->getEdge()->getToJunction() != trip->node);
251  }
252  }
253 
254  virtual double getTravelTime(const IntermodalTrip<E, N, V>* const trip, double time) const {
255  double length = this->getLength();
256  if (this->getEdge() == trip->from && !myForward && trip->departPos < myStartPos) {
257  length = trip->departPos - (myStartPos - this->getLength());
258  }
259  if (this->getEdge() == trip->to && myForward && trip->arrivalPos < myStartPos + this->getLength()) {
260  length = trip->arrivalPos - myStartPos;
261  }
262  if (this->getEdge() == trip->from && myForward && trip->departPos > myStartPos) {
263  length -= (trip->departPos - myStartPos);
264  }
265  if (this->getEdge() == trip->to && !myForward && trip->arrivalPos > myStartPos - this->getLength()) {
266  length -= (trip->arrivalPos - (myStartPos - this->getLength()));
267  }
268  // ensure that 'normal' edges always have a higher weight than connector edges
269  length = MAX2(length, NUMERICAL_EPS);
270  double tlsDelay = 0;
271  // @note pedestrian traffic lights should never have LINKSTATE_TL_REDYELLOW
272  if (this->getEdge()->isCrossing() && myLane->getIncomingLinkState() == LINKSTATE_TL_RED) {
273  // red traffic lights occurring later in the route may be green by the time we arrive
274  tlsDelay += MAX2(double(0), TL_RED_PENALTY - (time - STEPS2TIME(trip->departTime)));
275  }
276 #ifdef IntermodalRouter_DEBUG_EFFORTS
277  std::cout << " effort for " << trip->getID() << " at " << time << " edge=" << edge->getID() << " effort=" << length / trip->speed + tlsDelay << " l=" << length << " s=" << trip->speed << " tlsDelay=" << tlsDelay << "\n";
278 #endif
279  return length / trip->speed + tlsDelay;
280  }
281 
282 private:
284  const L* myLane;
285 
287  const bool myForward;
288 
290  const double myStartPos;
291 
292 };
293 
294 
295 #endif
296 
297 /****************************************************************************/
virtual double getTravelTime(const IntermodalTrip< E, N, V > *const trip, double time) const
IntermodalEdge(const std::string id, int numericalID, const E *edge, const std::string &line)
static double getEffortStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
is a pedestrian
const E *const myEdge
the original edge
const std::string & getLine() const
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const std::string myLine
public transport line or ped vs car
virtual const std::vector< IntermodalEdge * > & getSuccessors(SUMOVehicleClass) const
const N *const node
virtual bool includeInRoute(bool) const
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
IntermodalTrip(const E *_from, const E *_to, double _departPos, double _arrivalPos, double _speed, SUMOTime _departTime, const N *_node, const V *_vehicle=0, const SVCPermissions _modeSet=SVC_PEDESTRIAN)
void addSuccessor(IntermodalEdge *s)
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
int getNumericalID() const
T MAX2(T a, T b)
Definition: StdDefs.h:73
void clearSuccessors()
std::vector< IntermodalEdge * > myFollowingEdges
List of edges that may be approached from this edge.
const double myStartPos
the starting position for split edges
void removeSuccessor(const IntermodalEdge *const edge)
const E * getEdge() const
virtual bool prohibits(const IntermodalTrip< E, N, V > *const) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
SUMOVehicleClass getVClass() const
const SVCPermissions modeSet
const bool myForward
the direction of this edge
void setSuccessors(const std::vector< IntermodalEdge *> &edges)
const SUMOTime departTime
IntermodalTrip & operator=(const IntermodalTrip &)
Invalidated assignment operator.
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
const L * myLane
the original edge
virtual ~IntermodalEdge()
const E *const from
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
Base class for objects which have an id.
Definition: Named.h:45
the base edge type that is given to the internal router (SUMOAbstractRouter)
virtual double getEffort(const IntermodalTrip< E, N, V > *const, double) const
const double speed
const double arrivalPos
const double departPos
const E *const to
The link has red light (must brake)
double myLength
adaptable length (for splitted edges)
std::string getID() const
double getLength() const
the pedestrian edge type that is given to the internal router (SUMOAbstractRouter) ...
long long int SUMOTime
Definition: TraCIDefs.h:51
#define NUMERICAL_EPS
Definition: config.h:151
PedestrianEdge(int numericalID, const E *edge, const L *lane, bool forward, const double pos=-1.)
const int myNumericalID
the index in myEdges
#define TL_RED_PENALTY
ValueTimeLine< double > * myEfforts
Container for passing effort varying over time for the edge.
virtual bool hasEffort()
const V *const vehicle
const L * getSidewalk(const E *edge)
bool includeInRoute(bool allEdges) const
virtual double getTravelTime(const IntermodalTrip< E, N, V > *const, double) const
void setLength(const double length)