SUMO - Simulation of Urban MObility
ROPerson.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-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 /****************************************************************************/
18 // A person as used by router
19 /****************************************************************************/
20 #ifndef ROPerson_h
21 #define ROPerson_h
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 #include <string>
33 #include <iostream>
34 #include <utils/common/StdDefs.h>
35 #include <utils/common/SUMOTime.h>
38 #include "RORoutable.h"
39 #include "RORouteDef.h"
40 #include "ROVehicle.h"
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class OutputDevice;
47 class ROEdge;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
57 class ROPerson : public RORoutable {
58 
59 public:
65  ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
66 
68  virtual ~ROPerson();
69 
70  void addTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
71  const std::string& vTypes, const double departPos, const double arrivalPos, const std::string& busStop,
72  double walkFactor);
73 
74  void addRide(const ROEdge* const from, const ROEdge* const to, const std::string& lines, const std::string& destStop);
75 
76  void addWalk(const ConstROEdgeVector& edges, const double duration, const double speed,
77  const double departPos, const double arrivalPos, const std::string& busStop);
78 
79  void addStop(const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
80 
81  class TripItem;
86  class PlanItem {
87  public:
89  virtual ~PlanItem() {}
90 
91  virtual void addTripItem(TripItem* /* tripIt */) {
92  throw ProcessError();
93  }
94  virtual const ROEdge* getOrigin() const = 0;
95  virtual const ROEdge* getDestination() const = 0;
96  virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
97  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
98  virtual bool isStop() const {
99  return false;
100  }
101  virtual bool needsRouting() const {
102  return false;
103  }
104  };
105 
110  class Stop : public PlanItem {
111  public:
112  Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
113  : stopDesc(stop), edge(stopEdge) {}
114  const ROEdge* getOrigin() const {
115  return edge;
116  }
117  const ROEdge* getDestination() const {
118  return edge;
119  }
120  void saveAsXML(OutputDevice& os, const bool /* extended */) const {
121  stopDesc.write(os);
122  }
123  bool isStop() const {
124  return true;
125  }
126 
127  private:
129  const ROEdge* const edge;
130 
131  private:
133  Stop& operator=(const Stop& src);
134 
135  };
136 
141  class TripItem {
142  public:
143  TripItem(const double _cost)
144  : cost(_cost) {}
145 
147  virtual ~TripItem() {}
148 
149  virtual const ROEdge* getOrigin() const = 0;
150  virtual const ROEdge* getDestination() const = 0;
151  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
152  protected:
153  double cost;
154  };
155 
160  class Ride : public TripItem {
161  public:
162  Ride(const ROEdge* const _from, const ROEdge* const _to,
163  const std::string& _lines, const double _cost, const std::string& _destStop = "")
164  : TripItem(_cost), from(_from), to(_to), lines(_lines), destStop(_destStop) {}
165 
166  const ROEdge* getOrigin() const {
167  return from;
168  }
169  const ROEdge* getDestination() const {
170  return to;
171  }
172  void saveAsXML(OutputDevice& os, const bool extended) const;
173 
174  private:
175  const ROEdge* const from;
176  const ROEdge* const to;
177  const std::string lines;
178  const std::string destStop;
179 
180  private:
182  Ride& operator=(const Ride& src);
183 
184  };
185 
190  class Walk : public TripItem {
191  public:
192  Walk(const ConstROEdgeVector& _edges, const double _cost,
193  double departPos = std::numeric_limits<double>::infinity(),
194  double arrivalPos = std::numeric_limits<double>::infinity(),
195  const std::string& _destStop = "")
196  : TripItem(_cost), edges(_edges), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
197  Walk(const ConstROEdgeVector& edges, const double _cost, const double duration, const double speed,
198  const double departPos, const double arrivalPos, const std::string& _destStop)
199  : TripItem(_cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
200  const ROEdge* getOrigin() const {
201  return edges.front();
202  }
203  const ROEdge* getDestination() const {
204  return edges.back();
205  }
206  void saveAsXML(OutputDevice& os, const bool extended) const;
207 
208  private:
210  const double dur, v, dep, arr;
211  const std::string destStop;
212 
213  private:
215  Walk& operator=(const Walk& src);
216 
217  };
218 
223  class PersonTrip : public PlanItem {
224  public:
226  : from(0), to(0), modes(SVC_PEDESTRIAN), dep(0), arr(0), busStop(""), walkFactor(1.0) {}
227  PersonTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
228  const double departPos, const double arrivalPos, const std::string& busStop, double _walkFactor)
229  : from(from), to(to), modes(modeSet), dep(departPos), arr(arrivalPos), busStop(busStop), walkFactor(_walkFactor) {}
231  virtual ~PersonTrip() {
232  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
233  delete *it;
234  }
235  for (std::vector<ROVehicle*>::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
236  delete(*it)->getRouteDefinition();
237  delete *it;
238  }
239  }
240 
241  virtual void addTripItem(TripItem* tripIt) {
242  myTripItems.push_back(tripIt);
243  }
244  void addVehicle(ROVehicle* veh) {
245  myVehicles.push_back(veh);
246  }
247  std::vector<ROVehicle*>& getVehicles() {
248  return myVehicles;
249  }
250  const ROEdge* getOrigin() const {
251  return from != 0 ? from : myTripItems.front()->getOrigin();
252  }
253  const ROEdge* getDestination() const {
254  return to != 0 ? to : myTripItems.back()->getDestination();
255  }
256  double getDepartPos(bool replaceDefault = true) const {
257  return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
258  }
259  double getArrivalPos(bool replaceDefault = true) const {
260  return arr == std::numeric_limits<double>::infinity() && replaceDefault ? -POSITION_EPS : arr;
261  }
263  return modes;
264  }
265  bool hasBusStopDest() const {
266  return busStop != "";
267  }
268  virtual bool needsRouting() const {
269  return myTripItems.empty();
270  }
271  void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
272  void saveAsXML(OutputDevice& os, const bool extended) const {
273  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
274  (*it)->saveAsXML(os, extended);
275  }
276  }
277  double getWalkFactor() const {
278  return walkFactor;
279  }
280 
281  private:
282  const ROEdge* from;
283  const ROEdge* to;
285  const double dep, arr;
286  const std::string busStop;
288  std::vector<TripItem*> myTripItems;
290  std::vector<ROVehicle*> myVehicles;
292  double walkFactor;
293 
294  private:
296  PersonTrip& operator=(const PersonTrip& src);
297 
298  };
299 
300 
305  const ROEdge* getDepartEdge() const {
306  return myPlan.front()->getOrigin();
307  }
308 
309 
310  void computeRoute(const RORouterProvider& provider,
311  const bool removeLoops, MsgHandler* errorHandler);
312 
313 
324  void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
325 
326  std::vector<PlanItem*>& getPlan() {
327  return myPlan;
328  }
329 
330 private:
331  bool computeIntermodal(const RORouterProvider& provider, PersonTrip* const trip, const ROVehicle* const veh, MsgHandler* const errorHandler);
332 
333 private:
337  std::vector<PlanItem*> myPlan;
338 
339 
340 private:
342  ROPerson(const ROPerson& src);
343 
345  ROPerson& operator=(const ROPerson& src);
346 
347 };
348 
349 #endif
350 
351 /****************************************************************************/
352 
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, const std::string &destStop)
Definition: ROPerson.cpp:93
is a pedestrian
const std::string lines
Definition: ROPerson.h:177
SVCPermissions getModes() const
Definition: ROPerson.h:262
const ROEdge *const edge
Definition: ROPerson.h:129
bool hasBusStopDest() const
Definition: ROPerson.h:265
void addVehicle(ROVehicle *veh)
Definition: ROPerson.h:244
Structure representing possible vehicle parameter.
const SVCPermissions modes
Definition: ROPerson.h:284
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
A planItem can be a Stop.
Definition: ROPerson.h:110
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition: ROPerson.h:290
const ROEdge *const from
Definition: ROPerson.h:175
bool computeIntermodal(const RORouterProvider &provider, PersonTrip *const trip, const ROVehicle *const veh, MsgHandler *const errorHandler)
Definition: ROPerson.cpp:171
PersonTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const double departPos, const double arrivalPos, const std::string &busStop, double _walkFactor)
Definition: ROPerson.h:227
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
const ROEdge * getOrigin() const
Definition: ROPerson.h:114
Every person has a plan comprising of multiple planItems.
Definition: ROPerson.h:86
A planItem can be a Trip which contains multiple tripItems.
Definition: ROPerson.h:223
virtual ~PlanItem()
Destructor.
Definition: ROPerson.h:89
Walk(const ConstROEdgeVector &edges, const double _cost, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &_destStop)
Definition: ROPerson.h:197
const ROEdge * getOrigin() const
Definition: ROPerson.h:166
A routable thing such as a vehicle or person.
Definition: RORoutable.h:61
const ROEdge * getDestination() const
Definition: ROPerson.h:203
A ride is part of a trip, e.g., go from here to here by car or bus.
Definition: ROPerson.h:160
A vehicle as used by router.
Definition: ROVehicle.h:59
ROPerson & operator=(const ROPerson &src)
Invalidated assignment operator.
const ROEdge * getOrigin() const
Definition: ROPerson.h:200
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition: ROPerson.h:96
const ROEdge * from
Definition: ROPerson.h:282
std::vector< PlanItem * > myPlan
The plan of the person.
Definition: ROPerson.h:337
bool isStop() const
Definition: ROPerson.h:123
SUMOVehicleParameter::Stop stopDesc
Definition: ROPerson.h:128
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:326
TripItem(const double _cost)
Definition: ROPerson.h:143
virtual bool needsRouting() const
Definition: ROPerson.h:101
virtual void addTripItem(TripItem *)
Definition: ROPerson.h:91
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition: ROPerson.cpp:111
void saveAsXML(OutputDevice &os, const bool extended) const
Definition: ROPerson.h:272
const ROEdge * getDestination() const
Definition: ROPerson.h:169
A person as used by router.
Definition: ROPerson.h:57
#define POSITION_EPS
Definition: config.h:175
const double dep
Definition: ROPerson.h:285
A TripItem is part of a trip, e.g., go from here to here by car.
Definition: ROPerson.h:141
A walk is part of a trip, e.g., go from here to here by foot.
Definition: ROPerson.h:190
A basic edge for routing applications.
Definition: ROEdge.h:77
virtual const ROEdge * getDestination() const =0
virtual ~ROPerson()
Destructor.
Definition: ROPerson.cpp:58
std::vector< TripItem * > myTripItems
the fully specified trips
Definition: ROPerson.h:288
void addTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const double departPos, const double arrivalPos, const std::string &busStop, double walkFactor)
Definition: ROPerson.cpp:66
ROPerson(const SUMOVehicleParameter &pars, const SUMOVTypeParameter *type)
Constructor.
Definition: ROPerson.cpp:53
const double v
Definition: ROPerson.h:210
virtual ~PersonTrip()
Destructor.
Definition: ROPerson.h:231
double getWalkFactor() const
Definition: ROPerson.h:277
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition: ROPerson.cpp:202
Structure representing possible vehicle parameter.
const std::string destStop
Definition: ROPerson.h:211
double getArrivalPos(bool replaceDefault=true) const
Definition: ROPerson.h:259
virtual bool needsRouting() const
Definition: ROPerson.h:268
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:102
Walk(const ConstROEdgeVector &_edges, const double _cost, double departPos=std::numeric_limits< double >::infinity(), double arrivalPos=std::numeric_limits< double >::infinity(), const std::string &_destStop="")
Definition: ROPerson.h:192
Definition of vehicle stop (position and duration)
A storage for options typed value containers)
Definition: OptionsCont.h:98
const std::string destStop
Definition: ROPerson.h:178
const ROEdge * to
Definition: ROPerson.h:283
double getDepartPos(bool replaceDefault=true) const
Definition: ROPerson.h:256
const ROEdge * getDestination() const
Definition: ROPerson.h:117
Ride(const ROEdge *const _from, const ROEdge *const _to, const std::string &_lines, const double _cost, const std::string &_destStop="")
Definition: ROPerson.h:162
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
const ConstROEdgeVector edges
Definition: ROPerson.h:209
std::vector< ROVehicle * > & getVehicles()
Definition: ROPerson.h:247
virtual void addTripItem(TripItem *tripIt)
Definition: ROPerson.h:241
void saveAsXML(OutputDevice &os, const bool) const
Definition: ROPerson.h:120
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition: ROPerson.h:112
virtual const ROEdge * getOrigin() const =0
virtual void saveAsXML(OutputDevice &os, const bool extended) const =0
double walkFactor
walking speed factor
Definition: ROPerson.h:292
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition: ROPerson.h:305
const ROEdge * getOrigin() const
Definition: ROPerson.h:250
const ROEdge *const to
Definition: ROPerson.h:176
virtual bool isStop() const
Definition: ROPerson.h:98
virtual ~TripItem()
Destructor.
Definition: ROPerson.h:147
const std::string busStop
Definition: ROPerson.h:286
const ROEdge * getDestination() const
Definition: ROPerson.h:253