SUMO - Simulation of Urban MObility
IntermodalEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // The Edge definition for the Intermodal Router
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef IntermodalEdge_h
23 #define IntermodalEdge_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <algorithm>
38 #include <assert.h>
39 #include <utils/common/SUMOTime.h>
40 #include <utils/common/ToString.h>
41 #include <utils/common/Named.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 == 0) {
51  return 0;
52  }
53  const std::vector<L*>& lanes = edge->getLanes();
54  for (typename std::vector<L*>::const_iterator it = lanes.begin(); it != lanes.end(); ++it) {
55  if ((*it)->allowsVehicleClass(SVC_PEDESTRIAN)) {
56  return *it;
57  }
58  }
59  return 0;
60 }
61 
62 
63 // ===========================================================================
64 // class definitions
65 // ===========================================================================
66 
68 template<class E, class N, class V>
70 
71  IntermodalTrip(const E* _from, const E* _to, SUMOReal _departPos, SUMOReal _arrivalPos,
72  SUMOReal _speed, SUMOTime _departTime, const N* _node,
73  const V* _vehicle = 0, const SVCPermissions _modeSet = SVC_PEDESTRIAN) :
74  from(_from),
75  to(_to),
76  departPos(_departPos < 0 ? _from->getLength() + _departPos : _departPos),
77  arrivalPos(_arrivalPos < 0 ? _to->getLength() + _arrivalPos : _arrivalPos),
78  speed(_speed),
79  departTime(_departTime),
80  node(_node),
81  vehicle(_vehicle),
82  modeSet(_modeSet) {
83  }
84 
85  // exists just for debugging purposes
86  std::string getID() const {
87  return from->getID() + ":" + to->getID() + ":" + time2string(departTime);
88  }
89 
90 
91  inline SUMOVehicleClass getVClass() const {
92  return SVC_PEDESTRIAN;
93  }
94 
95  const E* const from;
96  const E* const to;
99  const SUMOReal speed;
101  const N* const node; // indicates whether only routing across this node shall be performed
102  const V* const vehicle; // indicates which vehicle may be used
104 private:
107 };
108 
109 
111 template<class E, class L, class N, class V>
112 class IntermodalEdge : public Named {
113 public:
114  IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line) :
115  Named(id),
116  myNumericalID(numericalID),
117  myEdge(edge),
118  myLine(line),
119  myLength(edge->getLength()) { }
120 
121  virtual ~IntermodalEdge() {}
122 
123  virtual bool includeInRoute(bool /* allEdges */) const {
124  return false;
125  }
126 
127  inline const std::string& getLine() const {
128  return myLine;
129  }
130 
131  inline const E* getEdge() const {
132  return myEdge;
133  }
134 
135  int getNumericalID() const {
136  return myNumericalID;
137  }
138 
140  myFollowingEdges.push_back(s);
141  }
142 
143  void setSuccessors(const std::vector<IntermodalEdge*>& edges) {
144  myFollowingEdges = edges;
145  }
146 
148  myFollowingEdges.clear();
149  }
150 
151  void removeSuccessor(const IntermodalEdge* const edge) {
152  myFollowingEdges.erase(std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge));
153  }
154 
155  virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass /*vClass*/) const {
156  // the network is already tailored for pedestrians. No need to check for permissions here
157  return myFollowingEdges;
158  }
159 
160  virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
161  return false;
162  }
163 
164  virtual SUMOReal getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, SUMOReal /* time */) const {
165  return 0;
166  }
167 
168  static SUMOReal getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, SUMOReal time) {
169  return edge->getTravelTime(trip, time);
170  }
171 
172  inline SUMOReal getLength() const {
173  return myLength;
174  }
175 
176  inline void setLength(const SUMOReal length) {
177  myLength = length;
178  }
179 
180 protected:
182  std::vector<IntermodalEdge*> myFollowingEdges;
183 
184 private:
186  const int myNumericalID;
187 
189  const E* const myEdge;
190 
192  const std::string myLine;
193 
196 
197 private:
199  IntermodalEdge(const IntermodalEdge& src);
200 
203 
204 };
205 
206 
208 template<class E, class L, class N, class V>
209 class PedestrianEdge : public IntermodalEdge<E, L, N, V> {
210 public:
211  PedestrianEdge(int numericalID, const E* edge, const L* lane, bool forward, const SUMOReal pos = -1.) :
212  IntermodalEdge<E, L, N, V>(edge->getID() + (edge->isWalkingArea() ? "" : (forward ? "_fwd" : "_bwd")) + toString(pos), numericalID, edge, "!ped"),
213  myLane(lane),
214  myForward(forward),
215  myStartPos(pos >= 0 ? pos : 0.) { }
216 
217  bool includeInRoute(bool allEdges) const {
218  return allEdges || (!this->getEdge()->isCrossing() && !this->getEdge()->isWalkingArea());
219  }
220 
221  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
222  if (trip->node == 0) {
223  // network only includes IntermodalEdges
224  return false;
225  } else {
226  // limit routing to the surroundings of the specified node
227  return (this->getEdge()->getFromJunction() != trip->node
228  && this->getEdge()->getToJunction() != trip->node);
229  }
230  }
231 
232  virtual SUMOReal getTravelTime(const IntermodalTrip<E, N, V>* const trip, SUMOReal time) const {
233  SUMOReal length = this->getLength();
234  if (this->getEdge() == trip->from && !myForward) {
235  length = trip->departPos - myStartPos;
236  }
237  if (this->getEdge() == trip->to && myForward) {
238  length = trip->arrivalPos - myStartPos;
239  }
240  if (this->getEdge() == trip->from && myForward) {
241  length -= (trip->departPos - myStartPos);
242  }
243  if (this->getEdge() == trip->to && !myForward) {
244  length -= (trip->arrivalPos - myStartPos);
245  }
246  // ensure that 'normal' edges always have a higher weight than connector edges
247  length = MAX2(length, POSITION_EPS);
248  SUMOReal tlsDelay = 0;
249  // @note pedestrian traffic lights should never have LINKSTATE_TL_REDYELLOW
250  if (this->getEdge()->isCrossing() && myLane->getIncomingLinkState() == LINKSTATE_TL_RED) {
251  // red traffic lights occurring later in the route may be green by the time we arive
252  tlsDelay += MAX2(SUMOReal(0), TL_RED_PENALTY - (time - STEPS2TIME(trip->departTime)));
253  }
254 #ifdef IntermodalRouter_DEBUG_EFFORTS
255  std::cout << " effort for " << trip->getID() << " at " << time << " edge=" << edge->getID() << " effort=" << length / trip->speed + tlsDelay << " l=" << length << " s=" << trip->speed << " tlsDelay=" << tlsDelay << "\n";
256 #endif
257  return length / trip->speed + tlsDelay;
258  }
259 
260 private:
262  const L* myLane;
263 
265  const bool myForward;
266 
269 
270 };
271 
272 
273 #endif
274 
275 /****************************************************************************/
SUMOReal myLength
adaptable length (for splitted edges)
IntermodalEdge(const std::string id, int numericalID, const E *edge, const std::string &line)
long long int SUMOTime
Definition: SUMOTime.h:43
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
int SVCPermissions
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:75
void clearSuccessors()
std::vector< IntermodalEdge * > myFollowingEdges
List of edges that may be approached from this edge.
SUMOReal getLength() const
void removeSuccessor(const IntermodalEdge *const edge)
const E * getEdge() const
const SUMOReal departPos
virtual bool prohibits(const IntermodalTrip< E, N, V > *const) const
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:65
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
const L * myLane
the original edge
#define POSITION_EPS
Definition: config.h:187
virtual ~IntermodalEdge()
IntermodalTrip(const E *_from, const E *_to, SUMOReal _departPos, SUMOReal _arrivalPos, SUMOReal _speed, SUMOTime _departTime, const N *_node, const V *_vehicle=0, const SVCPermissions _modeSet=SVC_PEDESTRIAN)
const E *const from
virtual SUMOReal getTravelTime(const IntermodalTrip< E, N, V > *const trip, SUMOReal time) const
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
Base class for objects which have an id.
Definition: Named.h:46
the base edge type that is given to the internal router (SUMOAbstractRouter)
const SUMOReal speed
const SUMOReal arrivalPos
const E *const to
The link has red light (must brake)
std::string getID() const
const SUMOReal myStartPos
the starting position for split edges
static SUMOReal getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, SUMOReal time)
#define SUMOReal
Definition: config.h:213
void setLength(const SUMOReal length)
the pedestrian edge type that is given to the internal router (SUMOAbstractRouter) ...
PedestrianEdge(int numericalID, const E *edge, const L *lane, bool forward, const SUMOReal pos=-1.)
const int myNumericalID
the index in myEdges
#define TL_RED_PENALTY
const V *const vehicle
const L * getSidewalk(const E *edge)
bool includeInRoute(bool allEdges) const
virtual SUMOReal getTravelTime(const IntermodalTrip< E, N, V > *const, SUMOReal) const