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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // A person as used by router
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <string>
25 #include <iostream>
26 #include <utils/common/StdDefs.h>
27 #include <utils/common/SUMOTime.h>
30 #include "RORoutable.h"
31 #include "RORouteDef.h"
32 #include "ROVehicle.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class OutputDevice;
39 class ROEdge;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
49 class ROPerson : public RORoutable {
50 
51 public:
57  ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
58 
60  virtual ~ROPerson();
61 
62  void addTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
63  const std::string& vTypes, const double departPos, const double arrivalPos,
64  const std::string& busStop, double walkFactor, const std::string& group);
65 
66  void addRide(const ROEdge* const from, const ROEdge* const to, const std::string& lines,
67  double arrivalPos, const std::string& destStop, const std::string& group);
68 
69  void addWalk(const ConstROEdgeVector& edges, const double duration, const double speed,
70  const double departPos, const double arrivalPos, const std::string& busStop);
71 
72  void addStop(const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
73 
74  class TripItem;
79  class PlanItem {
80  public:
82  virtual ~PlanItem() {}
83 
84  virtual PlanItem* clone() const = 0;
85 
86  virtual void addTripItem(TripItem* /* tripIt */) {
87  throw ProcessError();
88  }
89  virtual const ROEdge* getOrigin() const = 0;
90  virtual const ROEdge* getDestination() const = 0;
91  virtual double getDestinationPos() const = 0;
92  virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
93  virtual void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, const bool writeGeoTrip) const = 0;
94  virtual bool isStop() const {
95  return false;
96  }
97  virtual bool needsRouting() const {
98  return false;
99  }
100 
101  virtual SUMOTime getDuration() const = 0;
102  };
103 
108  class Stop : public PlanItem {
109  public:
110  Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
111  : stopDesc(stop), edge(stopEdge) {}
112 
113  PlanItem* clone() const {
114  return new Stop(stopDesc, edge);
115  }
116 
117  const ROEdge* getOrigin() const {
118  return edge;
119  }
120  const ROEdge* getDestination() const {
121  return edge;
122  }
123  double getDestinationPos() const {
124  return (stopDesc.startPos + stopDesc.endPos) / 2;
125  }
126  void saveAsXML(OutputDevice& os, const bool /* extended */, const bool /*asTrip*/, const bool /*writeGeoTrip*/) const {
127  stopDesc.write(os);
128  }
129  bool isStop() const {
130  return true;
131  }
133  return stopDesc.duration;
134  }
135 
136  private:
138  const ROEdge* const edge;
139 
140  private:
142  Stop& operator=(const Stop& src);
143 
144  };
145 
150  class TripItem {
151  public:
152  TripItem(const double _cost)
153  : cost(_cost) {}
154 
156  virtual ~TripItem() {}
157 
158  virtual TripItem* clone() const = 0;
159 
160  virtual const ROEdge* getOrigin() const = 0;
161  virtual const ROEdge* getDestination() const = 0;
162  virtual double getDestinationPos() const = 0;
163  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
165  return TIME2STEPS(cost);
166  }
167 
168  double getCost() const {
169  return cost;
170  }
171  protected:
172  double cost;
173  };
174 
179  class Ride : public TripItem {
180  public:
181  Ride(const ROEdge* const _from, const ROEdge* const _to,
182  const std::string& _lines, const std::string& _group, const double _cost, const double arrivalPos,
183  const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
184  TripItem(_cost),
185  from(_from), to(_to),
186  lines(_lines),
187  group(_group),
188  destStop(_destStop),
189  intended(_intended),
190  depart(_depart),
191  arr(arrivalPos) {
192  }
193 
194  TripItem* clone() const {
195  return new Ride(from, to, lines, group, cost, arr, destStop, intended, depart);
196  }
197 
198  const ROEdge* getOrigin() const {
199  return from;
200  }
201  const ROEdge* getDestination() const {
202  return to;
203  }
204  double getDestinationPos() const {
205  return arr == std::numeric_limits<double>::infinity() ? -NUMERICAL_EPS : arr;
206  }
207  void saveAsXML(OutputDevice& os, const bool extended) const;
208 
209  private:
210  const ROEdge* const from;
211  const ROEdge* const to;
212  const std::string lines;
213  const std::string group;
214  const std::string destStop;
215  const std::string intended;
217  const double arr;
218 
219  private:
221  Ride& operator=(const Ride& src);
222 
223  };
224 
229  class Walk : public TripItem {
230  public:
231  Walk(const ConstROEdgeVector& _edges, const double _cost,
232  double departPos = std::numeric_limits<double>::infinity(),
233  double arrivalPos = std::numeric_limits<double>::infinity(),
234  const std::string& _destStop = "")
235  : TripItem(_cost), edges(_edges), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
236  Walk(const ConstROEdgeVector& edges, const double _cost, const double duration, const double speed,
237  const double departPos, const double arrivalPos, const std::string& _destStop)
238  : TripItem(_cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
239 
240  TripItem* clone() const {
241  return new Walk(edges, cost, dep, arr, destStop);
242  }
243 
244  const ROEdge* getOrigin() const {
245  return edges.front();
246  }
247  const ROEdge* getDestination() const {
248  return edges.back();
249  }
250  double getDestinationPos() const {
251  return arr == std::numeric_limits<double>::infinity() ? 0 : arr;
252  }
253  void saveAsXML(OutputDevice& os, const bool extended) const;
254 
255  private:
257  const double dur, v, dep, arr;
258  const std::string destStop;
259 
260  private:
262  Walk& operator=(const Walk& src);
263 
264  };
265 
270  class PersonTrip : public PlanItem {
271  public:
273  : from(0), to(0), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(""), walkFactor(1.0) {}
274  PersonTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
275  const double departPos, const double arrivalPos, const std::string& _stopDest, double _walkFactor, const std::string& _group)
276  : from(from), to(to), modes(modeSet), dep(departPos), arr(arrivalPos), stopDest(_stopDest), walkFactor(_walkFactor), group(_group) {}
278  virtual ~PersonTrip() {
279  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
280  delete *it;
281  }
282  for (std::vector<ROVehicle*>::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
283  delete (*it)->getRouteDefinition();
284  delete *it;
285  }
286  }
287 
288  PlanItem* clone() const;
289 
290  virtual void addTripItem(TripItem* tripIt) {
291  myTripItems.push_back(tripIt);
292  }
293  void addVehicle(ROVehicle* veh) {
294  myVehicles.push_back(veh);
295  }
296  std::vector<ROVehicle*>& getVehicles() {
297  return myVehicles;
298  }
299  const ROEdge* getOrigin() const {
300  return from != 0 ? from : myTripItems.front()->getOrigin();
301  }
302  const ROEdge* getDestination() const {
303  return to;
304  }
305  double getDestinationPos() const {
306  if (myTripItems.empty()) {
307  return getArrivalPos(true);
308  } else {
309  return myTripItems.back()->getDestinationPos();
310  }
311  }
312  double getDepartPos(bool replaceDefault = true) const {
313  return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
314  }
315  double getArrivalPos(bool replaceDefault = true) const {
316  return arr == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : arr;
317  }
319  return modes;
320  }
321  void updateMOdes(SVCPermissions additionalModes) {
322  modes |= additionalModes;
323  }
324 
325  const std::string& getGroup() const {
326  return group;
327  }
328 
329  const std::string& getStopDest() const {
330  return stopDest;
331  }
332  virtual bool needsRouting() const {
333  return myTripItems.empty();
334  }
335  void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
336  void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, const bool writeGeoTrip) const;
337 
338  double getWalkFactor() const {
339  return walkFactor;
340  }
341 
343  SUMOTime getDuration() const;
344 
345  private:
346  const ROEdge* from;
347  const ROEdge* to;
349  const double dep, arr;
350  const std::string stopDest;
352  std::vector<TripItem*> myTripItems;
354  std::vector<ROVehicle*> myVehicles;
356  double walkFactor;
358  const std::string group;
359 
360  private:
363 
364  };
365 
366 
371  const ROEdge* getDepartEdge() const {
372  return myPlan.front()->getOrigin();
373  }
374 
375 
376  void computeRoute(const RORouterProvider& provider,
377  const bool removeLoops, MsgHandler* errorHandler);
378 
379 
390  void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
391 
392  std::vector<PlanItem*>& getPlan() {
393  return myPlan;
394  }
395 
396 private:
397  bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
398  PersonTrip* const trip, const ROVehicle* const veh, MsgHandler* const errorHandler);
399 
400 private:
404  std::vector<PlanItem*> myPlan;
405 
406 
407 private:
409  ROPerson(const ROPerson& src);
410 
413 
414 };
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:54
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:31
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
A basic edge for routing applications.
Definition: ROEdge.h:70
A planItem can be a Trip which contains multiple tripItems.
Definition: ROPerson.h:270
double getDepartPos(bool replaceDefault=true) const
Definition: ROPerson.h:312
void saveVehicles(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
Definition: ROPerson.cpp:208
double getDestinationPos() const
Definition: ROPerson.h:305
const std::string stopDest
Definition: ROPerson.h:350
SVCPermissions getModes() const
Definition: ROPerson.h:318
virtual ~PersonTrip()
Destructor.
Definition: ROPerson.h:278
void updateMOdes(SVCPermissions additionalModes)
Definition: ROPerson.h:321
PersonTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const double departPos, const double arrivalPos, const std::string &_stopDest, double _walkFactor, const std::string &_group)
Definition: ROPerson.h:274
double walkFactor
walking speed factor
Definition: ROPerson.h:356
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, const bool writeGeoTrip) const
Definition: ROPerson.cpp:217
const std::string & getStopDest() const
Definition: ROPerson.h:329
double getWalkFactor() const
Definition: ROPerson.h:338
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition: ROPerson.h:354
const ROEdge * from
Definition: ROPerson.h:346
SUMOTime getDuration() const
return duration sum of all trip items
Definition: ROPerson.cpp:292
double getArrivalPos(bool replaceDefault=true) const
Definition: ROPerson.h:315
const double dep
Definition: ROPerson.h:349
const ROEdge * getDestination() const
Definition: ROPerson.h:302
const double arr
Definition: ROPerson.h:349
virtual void addTripItem(TripItem *tripIt)
Definition: ROPerson.h:290
std::vector< ROVehicle * > & getVehicles()
Definition: ROPerson.h:296
const std::string group
group id for travelling in groups
Definition: ROPerson.h:358
virtual bool needsRouting() const
Definition: ROPerson.h:332
PlanItem * clone() const
Definition: ROPerson.cpp:199
const ROEdge * to
Definition: ROPerson.h:347
SVCPermissions modes
Definition: ROPerson.h:348
const std::string & getGroup() const
Definition: ROPerson.h:325
std::vector< TripItem * > myTripItems
the fully specified trips
Definition: ROPerson.h:352
void addVehicle(ROVehicle *veh)
Definition: ROPerson.h:293
PersonTrip & operator=(const PersonTrip &src)
Invalidated assignment operator.
const ROEdge * getOrigin() const
Definition: ROPerson.h:299
Every person has a plan comprising of multiple planItems.
Definition: ROPerson.h:79
virtual double getDestinationPos() const =0
virtual ~PlanItem()
Destructor.
Definition: ROPerson.h:82
virtual bool isStop() const
Definition: ROPerson.h:94
virtual void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, const bool writeGeoTrip) const =0
virtual bool needsRouting() const
Definition: ROPerson.h:97
virtual const ROEdge * getDestination() const =0
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition: ROPerson.h:92
virtual SUMOTime getDuration() const =0
virtual PlanItem * clone() const =0
virtual const ROEdge * getOrigin() const =0
virtual void addTripItem(TripItem *)
Definition: ROPerson.h:86
A ride is part of a trip, e.g., go from here to here by car or bus.
Definition: ROPerson.h:179
Ride & operator=(const Ride &src)
Invalidated assignment operator.
double getDestinationPos() const
Definition: ROPerson.h:204
const std::string lines
Definition: ROPerson.h:212
const std::string destStop
Definition: ROPerson.h:214
const std::string group
Definition: ROPerson.h:213
const double arr
Definition: ROPerson.h:217
const std::string intended
Definition: ROPerson.h:215
void saveAsXML(OutputDevice &os, const bool extended) const
Definition: ROPerson.cpp:137
const SUMOTime depart
Definition: ROPerson.h:216
Ride(const ROEdge *const _from, const ROEdge *const _to, const std::string &_lines, const std::string &_group, const double _cost, const double arrivalPos, const std::string &_destStop="", const std::string &_intended="", const SUMOTime _depart=-1)
Definition: ROPerson.h:181
const ROEdge * getDestination() const
Definition: ROPerson.h:201
const ROEdge *const to
Definition: ROPerson.h:211
TripItem * clone() const
Definition: ROPerson.h:194
const ROEdge *const from
Definition: ROPerson.h:210
const ROEdge * getOrigin() const
Definition: ROPerson.h:198
A planItem can be a Stop.
Definition: ROPerson.h:108
const ROEdge * getDestination() const
Definition: ROPerson.h:120
bool isStop() const
Definition: ROPerson.h:129
const ROEdge * getOrigin() const
Definition: ROPerson.h:117
SUMOTime getDuration() const
Definition: ROPerson.h:132
Stop & operator=(const Stop &src)
Invalidated assignment operator.
double getDestinationPos() const
Definition: ROPerson.h:123
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition: ROPerson.h:110
const ROEdge *const edge
Definition: ROPerson.h:138
void saveAsXML(OutputDevice &os, const bool, const bool, const bool) const
Definition: ROPerson.h:126
PlanItem * clone() const
Definition: ROPerson.h:113
SUMOVehicleParameter::Stop stopDesc
Definition: ROPerson.h:137
A TripItem is part of a trip, e.g., go from here to here by car.
Definition: ROPerson.h:150
virtual TripItem * clone() const =0
double getCost() const
Definition: ROPerson.h:168
virtual const ROEdge * getDestination() const =0
virtual void saveAsXML(OutputDevice &os, const bool extended) const =0
SUMOTime getDuration() const
Definition: ROPerson.h:164
virtual const ROEdge * getOrigin() const =0
TripItem(const double _cost)
Definition: ROPerson.h:152
virtual double getDestinationPos() const =0
virtual ~TripItem()
Destructor.
Definition: ROPerson.h:156
A walk is part of a trip, e.g., go from here to here by foot.
Definition: ROPerson.h:229
const double v
Definition: ROPerson.h:257
const ConstROEdgeVector edges
Definition: ROPerson.h:256
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:231
const double dur
Definition: ROPerson.h:257
const double arr
Definition: ROPerson.h:257
const ROEdge * getOrigin() const
Definition: ROPerson.h:244
void saveAsXML(OutputDevice &os, const bool extended) const
Definition: ROPerson.cpp:173
const ROEdge * getDestination() const
Definition: ROPerson.h:247
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:236
Walk & operator=(const Walk &src)
Invalidated assignment operator.
double getDestinationPos() const
Definition: ROPerson.h:250
const double dep
Definition: ROPerson.h:257
const std::string destStop
Definition: ROPerson.h:258
TripItem * clone() const
Definition: ROPerson.h:240
A person as used by router.
Definition: ROPerson.h:49
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, double arrivalPos, const std::string &destStop, const std::string &group)
Definition: ROPerson.cpp:112
ROPerson & operator=(const ROPerson &src)
Invalidated assignment operator.
virtual ~ROPerson()
Destructor.
Definition: ROPerson.cpp:52
ROPerson(const SUMOVehicleParameter &pars, const SUMOVTypeParameter *type)
Constructor.
Definition: ROPerson.cpp:47
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, const std::string &group)
Definition: ROPerson.cpp:60
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition: ROPerson.h:371
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:392
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition: ROPerson.cpp:358
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:122
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition: ROPerson.cpp:131
ROPerson(const ROPerson &src)
Invalidated copy constructor.
bool computeIntermodal(SUMOTime time, const RORouterProvider &provider, PersonTrip *const trip, const ROVehicle *const veh, MsgHandler *const errorHandler)
Definition: ROPerson.cpp:301
void saveAsXML(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
Saves the complete person description.
Definition: ROPerson.cpp:384
std::vector< PlanItem * > myPlan
The plan of the person.
Definition: ROPerson.h:404
A routable thing such as a vehicle or person.
Definition: RORoutable.h:52
A vehicle as used by router.
Definition: ROVehicle.h:50
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
void write(OutputDevice &dev, bool close=true) const
Writes the stop as XML.
double startPos
The stopping position start.
double endPos
The stopping position end.
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.