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