SUMO - Simulation of Urban MObility
CarEdge.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 /****************************************************************************/
17 // The CarEdge is a special intermodal edge representing the SUMO network edge
18 /****************************************************************************/
19 #ifndef CarEdge_h
20 #define CarEdge_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_FOX
33 #include <fx.h>
34 #endif
35 #include "IntermodalEdge.h"
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
42 template<class E, class L, class N, class V>
43 class CarEdge : public IntermodalEdge<E, L, N, V> {
44 private:
46 
47 public:
48  CarEdge(int numericalID, const E* edge, const double pos = -1.) :
49  _IntermodalEdge(edge->getID() + "_car" + toString(pos), numericalID, edge, "!car"),
50  myStartPos(pos >= 0 ? pos : 0.) { }
51 
52  bool includeInRoute(bool /* allEdges */) const {
53  return true;
54  }
55 
56  const std::vector<_IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass) const {
57  if (vClass == SVC_IGNORING) {
58  return this->myFollowingEdges;
59  }
60 #ifdef HAVE_FOX
61  FXMutexLock locker(myLock);
62 #endif
63  typename std::map<SUMOVehicleClass, std::vector<_IntermodalEdge*> >::const_iterator i = myClassesSuccessorMap.find(vClass);
64  if (i != myClassesSuccessorMap.end()) {
65  // can use cached value
66  return i->second;
67  } else {
68  // this vClass is requested for the first time. rebuild all successors
69  const std::set<const E*> classedCarFollowers = std::set<const E*>(this->getEdge()->getSuccessors(vClass).begin(), this->getEdge()->getSuccessors(vClass).end());
70  for (_IntermodalEdge* const e : this->myFollowingEdges) {
71  if (!e->includeInRoute(false) || e->getEdge() == this->getEdge() || classedCarFollowers.count(e->getEdge()) > 0) {
72  myClassesSuccessorMap[vClass].push_back(e);
73  }
74  }
75  return myClassesSuccessorMap[vClass];
76  }
77 
78  }
79 
80 
81  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
82  return trip->vehicle == 0 || this->getEdge()->prohibits(trip->vehicle);
83  }
84 
85  double getTravelTime(const IntermodalTrip<E, N, V>* const trip, double time) const {
86  const double travelTime = E::getTravelTimeStatic(this->getEdge(), trip->vehicle, time);
87  double distTravelled = this->getLength();
88  // checking arrivalPos first to have it correct for identical depart and arrival edge
89  if (this->getEdge() == trip->to) {
90  distTravelled = trip->arrivalPos - myStartPos;
91  }
92  if (this->getEdge() == trip->from) {
93  distTravelled -= trip->departPos - myStartPos;
94  }
95  return travelTime * distTravelled / this->getEdge()->getLength();
96  }
97 
98 private:
100  const double myStartPos;
101 
103  mutable std::map<SUMOVehicleClass, std::vector<_IntermodalEdge*> > myClassesSuccessorMap;
104 
105 #ifdef HAVE_FOX
106  mutable FXMutex myLock;
108 #endif
109 };
110 
111 
113 template<class E, class L, class N, class V>
114 class StopEdge : public IntermodalEdge<E, L, N, V> {
115 public:
116  StopEdge(const std::string id, int numericalID, const E* edge) :
117  IntermodalEdge<E, L, N, V>(id, numericalID, edge, "!stop") { }
118 
119  bool includeInRoute(bool /* allEdges */) const {
120  return true;
121  }
122 
123  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
124  return (trip->modeSet & SVC_BUS) == 0;
125  }
126 };
127 
128 
130 template<class E, class L, class N, class V>
131 class PublicTransportEdge : public IntermodalEdge<E, L, N, V> {
132 private:
133  struct Schedule {
134  Schedule(const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)
135  : begin(_begin), end(_end), period(_period), travelTimeSec(_travelTimeSec) {}
137  const SUMOTime end;
139  const double travelTimeSec;
140  private:
142  Schedule& operator=(const Schedule& src);
143  };
144 
145 public:
146  PublicTransportEdge(const std::string id, int numericalID, const IntermodalEdge<E, L, N, V>* entryStop, const E* endEdge, const std::string& line) :
147  IntermodalEdge<E, L, N, V>(line + ":" + (id != "" ? id : endEdge->getID()), numericalID, endEdge, line), myEntryStop(entryStop) { }
148 
149  bool includeInRoute(bool /* allEdges */) const {
150  return true;
151  }
152 
154  return myEntryStop;
155  }
156 
157  void addSchedule(const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec) {
158  //std::cout << " edge=" << myEntryStop->getID() << "->" << this->getID() << " beg=" << STEPS2TIME(begin) << " end=" << STEPS2TIME(end)
159  // << " period=" << STEPS2TIME(period)
160  // << " travelTime=" << travelTimeSec << "\n";
161  mySchedules.insert(std::make_pair(STEPS2TIME(begin), Schedule(begin, end, period, travelTimeSec)));
162  }
163 
164  double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double time) const {
165  double minArrivalSec = std::numeric_limits<double>::max();
166  for (typename std::multimap<double, Schedule>::const_iterator it = mySchedules.begin(); it != mySchedules.end(); ++it) {
167  if (it->first > minArrivalSec) {
168  break;
169  }
170  if (time < STEPS2TIME(it->second.end)) {
171  const int running = MAX2(0, (int)ceil((time - STEPS2TIME(it->second.begin)) / STEPS2TIME(it->second.period)));
172  const SUMOTime nextDepart = it->second.begin + running * it->second.period;
173  minArrivalSec = MIN2(STEPS2TIME(nextDepart) + it->second.travelTimeSec, minArrivalSec);
174  //std::cout << " edge=" << myEntryStop->getID() << "->" << this->getID() << " beg=" << STEPS2TIME(it->second.begin) << " end=" << STEPS2TIME(it->second.end)
175  // << " atTime=" << time
176  // << " running=" << running << " nextDepart=" << nextDepart
177  // << " minASec=" << minArrivalSec << " travelTime=" << minArrivalSec - time << "\n";
178  }
179  }
180  return minArrivalSec - time;
181  }
182 
183 private:
184  std::multimap<double, Schedule> mySchedules;
186 
187 };
188 
189 
191 template<class E, class L, class N, class V>
192 class AccessEdge : public IntermodalEdge<E, L, N, V> {
193 private:
195 
196 public:
197  AccessEdge(int numericalID, const _IntermodalEdge* inEdge, const _IntermodalEdge* outEdge,
198  const double transferTime = NUMERICAL_EPS) :
199  _IntermodalEdge(inEdge->getID() + ":" + outEdge->getID(), numericalID, outEdge->getEdge(), "!access"),
200  myTransferTime(transferTime) { }
201 
202  double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
203  return myTransferTime;
204  }
205 
206 private:
207  const double myTransferTime;
208 
209 };
210 
211 
212 #endif
213 
214 /****************************************************************************/
StopEdge(const std::string id, int numericalID, const E *edge)
Definition: CarEdge.h:116
CarEdge(int numericalID, const E *edge, const double pos=-1.)
Definition: CarEdge.h:48
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
Definition: CarEdge.h:81
const std::vector< _IntermodalEdge * > & getSuccessors(SUMOVehicleClass vClass) const
Definition: CarEdge.h:56
double getTravelTime(const IntermodalTrip< E, N, V > *const, double time) const
Definition: CarEdge.h:164
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool includeInRoute(bool) const
Definition: CarEdge.h:52
AccessEdge(int numericalID, const _IntermodalEdge *inEdge, const _IntermodalEdge *outEdge, const double transferTime=NUMERICAL_EPS)
Definition: CarEdge.h:197
IntermodalEdge & operator=(const IntermodalEdge &src)
Invalidated assignment operator.
IntermodalEdge< E, L, N, V > _IntermodalEdge
Definition: CarEdge.h:194
the car edge type that is given to the internal router (SUMOAbstractRouter)
Definition: CarEdge.h:43
T MAX2(T a, T b)
Definition: StdDefs.h:73
const double myTransferTime
Definition: CarEdge.h:207
void addSchedule(const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec)
Definition: CarEdge.h:157
std::vector< IntermodalEdge * > myFollowingEdges
List of edges that may be approached from this edge.
const IntermodalEdge< E, L, N, V > * getEntryStop() const
Definition: CarEdge.h:153
const std::string & getID() const
Returns the id.
Definition: Named.h:65
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
Definition: CarEdge.h:123
const IntermodalEdge< E, L, N, V > *const myEntryStop
Definition: CarEdge.h:185
std::multimap< double, Schedule > mySchedules
Definition: CarEdge.h:184
const E * getEdge() const
std::map< SUMOVehicleClass, std::vector< _IntermodalEdge * > > myClassesSuccessorMap
The successors available for a given vClass.
Definition: CarEdge.h:103
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
const SVCPermissions modeSet
IntermodalEdge< E, L, N, V > _IntermodalEdge
Definition: CarEdge.h:45
bool includeInRoute(bool) const
Definition: CarEdge.h:119
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
const double myStartPos
the starting position for split edges
Definition: CarEdge.h:100
T MIN2(T a, T b)
Definition: StdDefs.h:67
const E *const from
the base edge type that is given to the internal router (SUMOAbstractRouter)
vehicle is a bus
const double arrivalPos
Schedule(const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)
Definition: CarEdge.h:134
PublicTransportEdge(const std::string id, int numericalID, const IntermodalEdge< E, L, N, V > *entryStop, const E *endEdge, const std::string &line)
Definition: CarEdge.h:146
const double departPos
double getTravelTime(const IntermodalTrip< E, N, V > *const trip, double time) const
Definition: CarEdge.h:85
const E *const to
the public transport edge type connecting the stop edges
Definition: CarEdge.h:131
bool includeInRoute(bool) const
Definition: CarEdge.h:149
double getTravelTime(const IntermodalTrip< E, N, V > *const, double) const
Definition: CarEdge.h:202
double getLength() const
long long int SUMOTime
Definition: TraCIDefs.h:51
#define NUMERICAL_EPS
Definition: config.h:151
the stop edge type representing bus and train stops
Definition: CarEdge.h:114
const V *const vehicle
const double travelTimeSec
Definition: CarEdge.h:139
vehicles ignoring classes
the access edge connecting different modes that is given to the internal router (SUMOAbstractRouter) ...
Definition: CarEdge.h:192