SUMO - Simulation of Urban MObility
PublicTransportEdge.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-2018 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 /****************************************************************************/
15 // The PublicTransportEdge is a special intermodal edge connecting the stop edges with scheduled traffic
16 /****************************************************************************/
17 #ifndef PublicTransportEdge_h
18 #define PublicTransportEdge_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "IntermodalEdge.h"
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
33 template<class E, class L, class N, class V>
34 class PublicTransportEdge : public IntermodalEdge<E, L, N, V> {
35 private:
36  struct Schedule {
37  Schedule(const std::string& _id, const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)
38  : id(_id), begin(STEPS2TIME(_begin)), end(STEPS2TIME(_end)), period(STEPS2TIME(_period)), travelTimeSec(_travelTimeSec) {}
39  // the id of the vehicle or flow from which this schedule is generated
40  const std::string id;
41  const double begin;
42  const double end;
43  // the repetition period for a flow or -1 for a vehicle
44  const double period;
45  const double travelTimeSec;
46  private:
48  Schedule& operator=(const Schedule& src);
49  };
50 
51 public:
52  PublicTransportEdge(const std::string id, int numericalID, const IntermodalEdge<E, L, N, V>* entryStop, const E* endEdge, const std::string& line) :
53  IntermodalEdge<E, L, N, V>(line + ":" + (id != "" ? id : endEdge->getID()), numericalID, endEdge, line), myEntryStop(entryStop) { }
54 
55  bool includeInRoute(bool /* allEdges */) const {
56  return true;
57  }
58 
59  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
60  return (trip->modeSet & SVC_BUS) == 0;
61  }
62 
64  return myEntryStop;
65  }
66 
67  void addSchedule(const std::string id, const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec) {
68  //std::cout << " edge=" << myEntryStop->getID() << "->" << this->getID() << " beg=" << STEPS2TIME(begin) << " end=" << STEPS2TIME(end)
69  // << " period=" << STEPS2TIME(period)
70  // << " travelTime=" << travelTimeSec << "\n";
71  mySchedules.insert(std::make_pair(STEPS2TIME(begin), Schedule(id, begin, end, period, travelTimeSec)));
72  }
73 
74  double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double time) const {
75  double minArrivalSec = std::numeric_limits<double>::max();
76  for (typename std::multimap<double, Schedule>::const_iterator it = mySchedules.begin(); it != mySchedules.end(); ++it) {
77  const Schedule& s = it->second;
78  if (it->first > minArrivalSec) {
79  break;
80  }
81  if (time < s.end) {
82  int running;
83  if (s.period <= 0 || time < s.begin) {
84  // single vehicle or flow begin
85  running = 0;
86  } else {
87  // subsequent flow
88  running = (int)ceil((time - s.begin) / s.period);
89  }
90  const double nextDepart = s.begin + running * s.period;
91  minArrivalSec = MIN2(nextDepart + s.travelTimeSec, minArrivalSec);
92  //std::cout << " edge=" << myEntryStop->getID() << "->" << this->getID() << " beg=" << s.begin << " end=" << s.end
93  // << " atTime=" << time
94  // << " running=" << running << " nextDepart=" << nextDepart
95  // << " minASec=" << minArrivalSec << " travelTime=" << minArrivalSec - time << "\n";
96  }
97  }
98  return minArrivalSec - time;
99  }
100 
101  double getIntended(const double time, std::string& intended) const {
103  double minArrivalSec = std::numeric_limits<double>::max();
104  double bestDepartTime = std::numeric_limits<double>::max();
105  for (typename std::multimap<double, Schedule>::const_iterator it = mySchedules.begin(); it != mySchedules.end(); ++it) {
106  const Schedule& s = it->second;
107  if (it->first > minArrivalSec) {
108  break;
109  }
110  if (time < s.end) {
111  int running;
112  if (s.period <= 0 || time < s.begin) {
113  // single vehicle or flow begin
114  running = 0;
115  } else {
116  // subsequent flow
117  running = (int)ceil((time - s.begin) / s.period);
118  }
119  const double nextDepart = s.begin + running * s.period;
120  if (nextDepart + s.travelTimeSec < minArrivalSec) {
121  minArrivalSec = nextDepart + s.travelTimeSec;
122  bestDepartTime = nextDepart;
123  // see naming scheme inMSInsertionControl::determineCandidates()
124  intended = s.period <= 0 ? s.id : s.id + "." + toString(running);
125  }
126  }
127  }
128  return bestDepartTime;
129  }
130 
131 private:
132  std::multimap<double, Schedule> mySchedules;
134 
135 };
136 
137 
138 #endif
139 
140 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:36
double getTravelTime(const IntermodalTrip< E, N, V > *const, double time) const
const IntermodalEdge< E, L, N, V > * getEntryStop() const
const std::string & getID() const
Returns the id.
Definition: Named.h:69
const IntermodalEdge< E, L, N, V > *const myEntryStop
std::multimap< double, Schedule > mySchedules
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
T MIN2(T a, T b)
Definition: StdDefs.h:62
the base edge type that is given to the internal router (SUMOAbstractRouter)
Schedule & operator=(const Schedule &src)
Invalidated assignment operator.
vehicle is a bus
const SVCPermissions modeSet
PublicTransportEdge(const std::string id, int numericalID, const IntermodalEdge< E, L, N, V > *entryStop, const E *endEdge, const std::string &line)
the public transport edge type connecting the stop edges
double getIntended(const double time, std::string &intended) const
get intended vehicle id and departure time of next public transport ride
bool includeInRoute(bool) const
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
void addSchedule(const std::string id, const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec)
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
Schedule(const std::string &_id, const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)