Eclipse 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-2019 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 /****************************************************************************/
16 // A person as used by router
17 /****************************************************************************/
18 #ifndef ROPerson_h
19 #define ROPerson_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <iostream>
28 #include <utils/common/StdDefs.h>
29 #include <utils/common/SUMOTime.h>
32 #include "RORoutable.h"
33 #include "RORouteDef.h"
34 #include "ROVehicle.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class OutputDevice;
41 class ROEdge;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
51 class ROPerson : public RORoutable {
52 
53 public:
59  ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
60 
62  virtual ~ROPerson();
63 
64  void addTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
65  const std::string& vTypes, const double departPos, const double arrivalPos, const std::string& busStop,
66  double walkFactor);
67 
68  void addRide(const ROEdge* const from, const ROEdge* const to, const std::string& lines, double arrivalPos, const std::string& destStop);
69 
70  void addWalk(const ConstROEdgeVector& edges, const double duration, const double speed,
71  const double departPos, const double arrivalPos, const std::string& busStop);
72 
73  void addStop(const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
74 
75  class TripItem;
80  class PlanItem {
81  public:
83  virtual ~PlanItem() {}
84 
85  virtual PlanItem* clone() const = 0;
86 
87  virtual void addTripItem(TripItem* /* tripIt */) {
88  throw ProcessError();
89  }
90  virtual const ROEdge* getOrigin() const = 0;
91  virtual const ROEdge* getDestination() const = 0;
92  virtual double getDestinationPos() const = 0;
93  virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
94  virtual void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, const bool writeGeoTrip) const = 0;
95  virtual bool isStop() const {
96  return false;
97  }
98  virtual bool needsRouting() const {
99  return false;
100  }
101 
102  virtual SUMOTime getDuration() const = 0;
103  };
104 
109  class Stop : public PlanItem {
110  public:
111  Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
112  : stopDesc(stop), edge(stopEdge) {}
113 
114  PlanItem* clone() const {
115  return new Stop(stopDesc, edge);
116  }
117 
118  const ROEdge* getOrigin() const {
119  return edge;
120  }
121  const ROEdge* getDestination() const {
122  return edge;
123  }
124  double getDestinationPos() const {
125  return (stopDesc.startPos + stopDesc.endPos) / 2;
126  }
127  void saveAsXML(OutputDevice& os, const bool /* extended */, const bool /*asTrip*/, const bool /*writeGeoTrip*/) const {
128  stopDesc.write(os);
129  }
130  bool isStop() const {
131  return true;
132  }
134  return stopDesc.duration;
135  }
136 
137  private:
139  const ROEdge* const edge;
140 
141  private:
143  Stop& operator=(const Stop& src);
144 
145  };
146 
151  class TripItem {
152  public:
153  TripItem(const double _cost)
154  : cost(_cost) {}
155 
157  virtual ~TripItem() {}
158 
159  virtual TripItem* clone() const = 0;
160 
161  virtual const ROEdge* getOrigin() const = 0;
162  virtual const ROEdge* getDestination() const = 0;
163  virtual double getDestinationPos() const = 0;
164  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
166  return TIME2STEPS(cost);
167  }
168  protected:
169  double cost;
170  };
171 
176  class Ride : public TripItem {
177  public:
178  Ride(const ROEdge* const _from, const ROEdge* const _to,
179  const std::string& _lines, const double _cost, const double arrivalPos,
180  const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
181  TripItem(_cost),
182  from(_from), to(_to),
183  lines(_lines),
184  destStop(_destStop),
185  intended(_intended),
186  depart(_depart),
187  arr(arrivalPos) {
188  }
189 
190  TripItem* clone() const {
191  return new Ride(from, to, lines, cost, arr, destStop, intended, depart);
192  }
193 
194  const ROEdge* getOrigin() const {
195  return from;
196  }
197  const ROEdge* getDestination() const {
198  return to;
199  }
200  double getDestinationPos() const {
201  return arr;
202  }
203  void saveAsXML(OutputDevice& os, const bool extended) const;
204 
205  private:
206  const ROEdge* const from;
207  const ROEdge* const to;
208  const std::string lines;
209  const std::string destStop;
210  const std::string intended;
212  const double arr;
213 
214  private:
216  Ride& operator=(const Ride& src);
217 
218  };
219 
224  class Walk : public TripItem {
225  public:
226  Walk(const ConstROEdgeVector& _edges, const double _cost,
227  double departPos = std::numeric_limits<double>::infinity(),
228  double arrivalPos = std::numeric_limits<double>::infinity(),
229  const std::string& _destStop = "")
230  : TripItem(_cost), edges(_edges), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
231  Walk(const ConstROEdgeVector& edges, const double _cost, const double duration, const double speed,
232  const double departPos, const double arrivalPos, const std::string& _destStop)
233  : TripItem(_cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
234 
235  TripItem* clone() const {
236  return new Walk(edges, cost, dep, arr, destStop);
237  }
238 
239  const ROEdge* getOrigin() const {
240  return edges.front();
241  }
242  const ROEdge* getDestination() const {
243  return edges.back();
244  }
245  double getDestinationPos() const {
246  return arr;
247  }
248  void saveAsXML(OutputDevice& os, const bool extended) const;
249 
250  private:
252  const double dur, v, dep, arr;
253  const std::string destStop;
254 
255  private:
257  Walk& operator=(const Walk& src);
258 
259  };
260 
265  class PersonTrip : public PlanItem {
266  public:
268  : from(0), to(0), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(""), walkFactor(1.0) {}
269  PersonTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
270  const double departPos, const double arrivalPos, const std::string& _stopDest, double _walkFactor)
271  : from(from), to(to), modes(modeSet), dep(departPos), arr(arrivalPos), stopDest(_stopDest), walkFactor(_walkFactor) {}
273  virtual ~PersonTrip() {
274  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
275  delete *it;
276  }
277  for (std::vector<ROVehicle*>::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
278  delete (*it)->getRouteDefinition();
279  delete *it;
280  }
281  }
282 
283  PlanItem* clone() const;
284 
285  virtual void addTripItem(TripItem* tripIt) {
286  myTripItems.push_back(tripIt);
287  }
288  void addVehicle(ROVehicle* veh) {
289  myVehicles.push_back(veh);
290  }
291  std::vector<ROVehicle*>& getVehicles() {
292  return myVehicles;
293  }
294  const ROEdge* getOrigin() const {
295  return from != 0 ? from : myTripItems.front()->getOrigin();
296  }
297  const ROEdge* getDestination() const {
298  return to;
299  }
300  double getDestinationPos() const {
301  if (myTripItems.empty()) {
302  return getArrivalPos(true);
303  } else {
304  return myTripItems.back()->getDestinationPos();
305  }
306  }
307  double getDepartPos(bool replaceDefault = true) const {
308  return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
309  }
310  double getArrivalPos(bool replaceDefault = true) const {
311  return arr == std::numeric_limits<double>::infinity() && replaceDefault ? -POSITION_EPS : arr;
312  }
314  return modes;
315  }
316  const std::string& getStopDest() const {
317  return stopDest;
318  }
319  virtual bool needsRouting() const {
320  return myTripItems.empty();
321  }
322  void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
323  void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, const bool writeGeoTrip) const;
324 
325  double getWalkFactor() const {
326  return walkFactor;
327  }
328 
330  SUMOTime getDuration() const;
331 
332  private:
333  const ROEdge* from;
334  const ROEdge* to;
336  const double dep, arr;
337  const std::string stopDest;
339  std::vector<TripItem*> myTripItems;
341  std::vector<ROVehicle*> myVehicles;
343  double walkFactor;
344 
345  private:
347  PersonTrip& operator=(const PersonTrip& src);
348 
349  };
350 
351 
356  const ROEdge* getDepartEdge() const {
357  return myPlan.front()->getOrigin();
358  }
359 
360 
361  void computeRoute(const RORouterProvider& provider,
362  const bool removeLoops, MsgHandler* errorHandler);
363 
364 
375  void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
376 
377  std::vector<PlanItem*>& getPlan() {
378  return myPlan;
379  }
380 
381 private:
382  bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
383  PersonTrip* const trip, const ROVehicle* const veh, MsgHandler* const errorHandler);
384 
385 private:
389  std::vector<PlanItem*> myPlan;
390 
391 
392 private:
394  ROPerson(const ROPerson& src);
395 
397  ROPerson& operator=(const ROPerson& src);
398 
399 };
400 
401 #endif
402 
403 /****************************************************************************/
404 
long long int SUMOTime
Definition: SUMOTime.h:35
PlanItem * clone() const
Definition: ROPerson.h:114
const std::string lines
Definition: ROPerson.h:208
SVCPermissions getModes() const
Definition: ROPerson.h:313
virtual double getDestinationPos() const =0
SUMOTime getDuration() const
Definition: ROPerson.h:133
const ROEdge *const edge
Definition: ROPerson.h:139
Ride(const ROEdge *const _from, const ROEdge *const _to, const std::string &_lines, const double _cost, const double arrivalPos, const std::string &_destStop="", const std::string &_intended="", const SUMOTime _depart=-1)
Definition: ROPerson.h:178
void addVehicle(ROVehicle *veh)
Definition: ROPerson.h:288
Structure representing possible vehicle parameter.
const std::string stopDest
Definition: ROPerson.h:337
const SVCPermissions modes
Definition: ROPerson.h:335
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:109
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition: ROPerson.h:341
const ROEdge *const from
Definition: ROPerson.h:206
double getDestinationPos() const
Definition: ROPerson.h:245
const SUMOTime depart
Definition: ROPerson.h:211
SUMOTime getDuration() const
Definition: ROPerson.h:165
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:57
#define TIME2STEPS(x)
Definition: SUMOTime.h:59
void saveAsXML(OutputDevice &os, const bool, const bool, const bool) const
Definition: ROPerson.h:127
const ROEdge * getOrigin() const
Definition: ROPerson.h:118
Every person has a plan comprising of multiple planItems.
Definition: ROPerson.h:80
A planItem can be a Trip which contains multiple tripItems.
Definition: ROPerson.h:265
virtual ~PlanItem()
Destructor.
Definition: ROPerson.h:83
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:231
const ROEdge * getOrigin() const
Definition: ROPerson.h:194
A routable thing such as a vehicle or person.
Definition: RORoutable.h:55
TripItem * clone() const
Definition: ROPerson.h:235
const ROEdge * getDestination() const
Definition: ROPerson.h:242
A ride is part of a trip, e.g., go from here to here by car or bus.
Definition: ROPerson.h:176
A vehicle as used by router.
Definition: ROVehicle.h:53
ROPerson & operator=(const ROPerson &src)
Invalidated assignment operator.
const ROEdge * getOrigin() const
Definition: ROPerson.h:239
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition: ROPerson.h:93
const ROEdge * from
Definition: ROPerson.h:333
TripItem * clone() const
Definition: ROPerson.h:190
std::vector< PlanItem * > myPlan
The plan of the person.
Definition: ROPerson.h:389
bool isStop() const
Definition: ROPerson.h:130
SUMOVehicleParameter::Stop stopDesc
Definition: ROPerson.h:138
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:377
TripItem(const double _cost)
Definition: ROPerson.h:153
virtual bool needsRouting() const
Definition: ROPerson.h:98
virtual void addTripItem(TripItem *)
Definition: ROPerson.h:87
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition: ROPerson.cpp:119
const ROEdge * getDestination() const
Definition: ROPerson.h:197
A person as used by router.
Definition: ROPerson.h:51
#define POSITION_EPS
Definition: config.h:169
const double dep
Definition: ROPerson.h:336
A TripItem is part of a trip, e.g., go from here to here by car.
Definition: ROPerson.h:151
A walk is part of a trip, e.g., go from here to here by foot.
Definition: ROPerson.h:224
A basic edge for routing applications.
Definition: ROEdge.h:73
virtual const ROEdge * getDestination() const =0
const std::string & getStopDest() const
Definition: ROPerson.h:316
virtual ~ROPerson()
Destructor.
Definition: ROPerson.cpp:54
std::vector< TripItem * > myTripItems
the fully specified trips
Definition: ROPerson.h:339
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:62
Definition of vehicle stop (position and duration)
ROPerson(const SUMOVehicleParameter &pars, const SUMOVTypeParameter *type)
Constructor.
Definition: ROPerson.cpp:49
const double v
Definition: ROPerson.h:252
virtual ~PersonTrip()
Destructor.
Definition: ROPerson.h:273
double getWalkFactor() const
Definition: ROPerson.h:325
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition: ROPerson.cpp:308
double getDestinationPos() const
Definition: ROPerson.h:200
Structure representing possible vehicle parameter.
virtual SUMOTime getDuration() const =0
const std::string destStop
Definition: ROPerson.h:253
double getArrivalPos(bool replaceDefault=true) const
Definition: ROPerson.h:310
virtual bool needsRouting() const
Definition: ROPerson.h:319
const std::string intended
Definition: ROPerson.h:210
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:110
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:226
A storage for options typed value containers)
Definition: OptionsCont.h:90
const std::string destStop
Definition: ROPerson.h:209
const ROEdge * to
Definition: ROPerson.h:334
double getDestinationPos() const
Definition: ROPerson.h:300
double getDepartPos(bool replaceDefault=true) const
Definition: ROPerson.h:307
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, double arrivalPos, const std::string &destStop)
Definition: ROPerson.cpp:101
virtual PlanItem * clone() const =0
const ROEdge * getDestination() const
Definition: ROPerson.h:121
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
const ConstROEdgeVector edges
Definition: ROPerson.h:251
std::vector< ROVehicle * > & getVehicles()
Definition: ROPerson.h:291
virtual void addTripItem(TripItem *tripIt)
Definition: ROPerson.h:285
double getDestinationPos() const
Definition: ROPerson.h:124
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition: ROPerson.h:111
virtual const ROEdge * getOrigin() const =0
const double arr
Definition: ROPerson.h:212
double walkFactor
walking speed factor
Definition: ROPerson.h:343
bool computeIntermodal(SUMOTime time, const RORouterProvider &provider, PersonTrip *const trip, const ROVehicle *const veh, MsgHandler *const errorHandler)
Definition: ROPerson.cpp:276
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition: ROPerson.h:356
const ROEdge * getOrigin() const
Definition: ROPerson.h:294
const ROEdge *const to
Definition: ROPerson.h:207
virtual bool isStop() const
Definition: ROPerson.h:95
PersonTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const double departPos, const double arrivalPos, const std::string &_stopDest, double _walkFactor)
Definition: ROPerson.h:269
virtual void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, const bool writeGeoTrip) const =0
virtual ~TripItem()
Destructor.
Definition: ROPerson.h:157
const ROEdge * getDestination() const
Definition: ROPerson.h:297