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-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 /****************************************************************************/
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 void addTripItem(TripItem* /* tripIt */) {
86  throw ProcessError();
87  }
88  virtual const ROEdge* getOrigin() const = 0;
89  virtual const ROEdge* getDestination() const = 0;
90  virtual double getDestinationPos() const = 0;
91  virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
92  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
93  virtual bool isStop() const {
94  return false;
95  }
96  virtual bool needsRouting() const {
97  return false;
98  }
99  };
100 
105  class Stop : public PlanItem {
106  public:
107  Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
108  : stopDesc(stop), edge(stopEdge) {}
109  const ROEdge* getOrigin() const {
110  return edge;
111  }
112  const ROEdge* getDestination() const {
113  return edge;
114  }
115  double getDestinationPos() const {
116  return stopDesc.endPos;
117  }
118  void saveAsXML(OutputDevice& os, const bool /* extended */) const {
119  stopDesc.write(os);
120  }
121  bool isStop() const {
122  return true;
123  }
124 
125  private:
127  const ROEdge* const edge;
128 
129  private:
131  Stop& operator=(const Stop& src);
132 
133  };
134 
139  class TripItem {
140  public:
141  TripItem(const double _cost)
142  : cost(_cost) {}
143 
145  virtual ~TripItem() {}
146 
147  virtual const ROEdge* getOrigin() const = 0;
148  virtual const ROEdge* getDestination() const = 0;
149  virtual double getDestinationPos() const = 0;
150  virtual void saveAsXML(OutputDevice& os, const bool extended) const = 0;
151  protected:
152  double cost;
153  };
154 
159  class Ride : public TripItem {
160  public:
161  Ride(const ROEdge* const _from, const ROEdge* const _to,
162  const std::string& _lines, const double _cost, const double arrivalPos,
163  const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
164  TripItem(_cost),
165  from(_from), to(_to),
166  lines(_lines),
167  destStop(_destStop),
168  intended(_intended),
169  depart(_depart),
170  arr(arrivalPos) {
171  }
172 
173  const ROEdge* getOrigin() const {
174  return from;
175  }
176  const ROEdge* getDestination() const {
177  return to;
178  }
179  double getDestinationPos() const {
180  return arr;
181  }
182  void saveAsXML(OutputDevice& os, const bool extended) const;
183 
184  private:
185  const ROEdge* const from;
186  const ROEdge* const to;
187  const std::string lines;
188  const std::string destStop;
189  const std::string intended;
191  const double arr;
192 
193  private:
195  Ride& operator=(const Ride& src);
196 
197  };
198 
203  class Walk : public TripItem {
204  public:
205  Walk(const ConstROEdgeVector& _edges, const double _cost,
206  double departPos = std::numeric_limits<double>::infinity(),
207  double arrivalPos = std::numeric_limits<double>::infinity(),
208  const std::string& _destStop = "")
209  : TripItem(_cost), edges(_edges), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
210  Walk(const ConstROEdgeVector& edges, const double _cost, const double duration, const double speed,
211  const double departPos, const double arrivalPos, const std::string& _destStop)
212  : TripItem(_cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
213  const ROEdge* getOrigin() const {
214  return edges.front();
215  }
216  const ROEdge* getDestination() const {
217  return edges.back();
218  }
219  double getDestinationPos() const {
220  return arr;
221  }
222  void saveAsXML(OutputDevice& os, const bool extended) const;
223 
224  private:
226  const double dur, v, dep, arr;
227  const std::string destStop;
228 
229  private:
231  Walk& operator=(const Walk& src);
232 
233  };
234 
239  class PersonTrip : public PlanItem {
240  public:
242  : from(0), to(0), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(""), walkFactor(1.0) {}
243  PersonTrip(const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet,
244  const double departPos, const double arrivalPos, const std::string& _stopDest, double _walkFactor)
245  : from(from), to(to), modes(modeSet), dep(departPos), arr(arrivalPos), stopDest(_stopDest), walkFactor(_walkFactor) {}
247  virtual ~PersonTrip() {
248  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
249  delete *it;
250  }
251  for (std::vector<ROVehicle*>::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
252  delete(*it)->getRouteDefinition();
253  delete *it;
254  }
255  }
256 
257  virtual void addTripItem(TripItem* tripIt) {
258  myTripItems.push_back(tripIt);
259  }
260  void addVehicle(ROVehicle* veh) {
261  myVehicles.push_back(veh);
262  }
263  std::vector<ROVehicle*>& getVehicles() {
264  return myVehicles;
265  }
266  const ROEdge* getOrigin() const {
267  return from != 0 ? from : myTripItems.front()->getOrigin();
268  }
269  const ROEdge* getDestination() const {
270  return to;
271  }
272  double getDestinationPos() const {
273  if (myTripItems.empty()) {
274  return getArrivalPos(true);
275  } else {
276  return myTripItems.back()->getDestinationPos();
277  }
278  }
279  double getDepartPos(bool replaceDefault = true) const {
280  return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
281  }
282  double getArrivalPos(bool replaceDefault = true) const {
283  return arr == std::numeric_limits<double>::infinity() && replaceDefault ? -POSITION_EPS : arr;
284  }
286  return modes;
287  }
288  const std::string& getStopDest() const {
289  return stopDest;
290  }
291  virtual bool needsRouting() const {
292  return myTripItems.empty();
293  }
294  void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
295  void saveAsXML(OutputDevice& os, const bool extended) const {
296  for (std::vector<TripItem*>::const_iterator it = myTripItems.begin(); it != myTripItems.end(); ++it) {
297  (*it)->saveAsXML(os, extended);
298  }
299  }
300  double getWalkFactor() const {
301  return walkFactor;
302  }
303 
304  private:
305  const ROEdge* from;
306  const ROEdge* to;
308  const double dep, arr;
309  const std::string stopDest;
311  std::vector<TripItem*> myTripItems;
313  std::vector<ROVehicle*> myVehicles;
315  double walkFactor;
316 
317  private:
319  PersonTrip& operator=(const PersonTrip& src);
320 
321  };
322 
323 
328  const ROEdge* getDepartEdge() const {
329  return myPlan.front()->getOrigin();
330  }
331 
332 
333  void computeRoute(const RORouterProvider& provider,
334  const bool removeLoops, MsgHandler* errorHandler);
335 
336 
347  void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
348 
349  std::vector<PlanItem*>& getPlan() {
350  return myPlan;
351  }
352 
353 private:
354  bool computeIntermodal(const RORouterProvider& provider, PersonTrip* const trip, const ROVehicle* const veh, MsgHandler* const errorHandler);
355 
356 private:
360  std::vector<PlanItem*> myPlan;
361 
362 
363 private:
365  ROPerson(const ROPerson& src);
366 
368  ROPerson& operator=(const ROPerson& src);
369 
370 };
371 
372 #endif
373 
374 /****************************************************************************/
375 
long long int SUMOTime
Definition: SUMOTime.h:36
is a pedestrian
const std::string lines
Definition: ROPerson.h:187
SVCPermissions getModes() const
Definition: ROPerson.h:285
virtual double getDestinationPos() const =0
const ROEdge *const edge
Definition: ROPerson.h:127
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:161
void addVehicle(ROVehicle *veh)
Definition: ROPerson.h:260
Structure representing possible vehicle parameter.
const std::string stopDest
Definition: ROPerson.h:309
const SVCPermissions modes
Definition: ROPerson.h:307
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:105
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition: ROPerson.h:313
const ROEdge *const from
Definition: ROPerson.h:185
bool computeIntermodal(const RORouterProvider &provider, PersonTrip *const trip, const ROVehicle *const veh, MsgHandler *const errorHandler)
Definition: ROPerson.cpp:189
double getDestinationPos() const
Definition: ROPerson.h:219
const SUMOTime depart
Definition: ROPerson.h:190
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:56
const ROEdge * getOrigin() const
Definition: ROPerson.h:109
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:239
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:210
const ROEdge * getOrigin() const
Definition: ROPerson.h:173
A routable thing such as a vehicle or person.
Definition: RORoutable.h:55
const ROEdge * getDestination() const
Definition: ROPerson.h:216
A ride is part of a trip, e.g., go from here to here by car or bus.
Definition: ROPerson.h:159
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:213
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition: ROPerson.h:91
const ROEdge * from
Definition: ROPerson.h:305
std::vector< PlanItem * > myPlan
The plan of the person.
Definition: ROPerson.h:360
bool isStop() const
Definition: ROPerson.h:121
SUMOVehicleParameter::Stop stopDesc
Definition: ROPerson.h:126
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:349
TripItem(const double _cost)
Definition: ROPerson.h:141
virtual bool needsRouting() const
Definition: ROPerson.h:96
virtual void addTripItem(TripItem *)
Definition: ROPerson.h:85
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition: ROPerson.cpp:113
void saveAsXML(OutputDevice &os, const bool extended) const
Definition: ROPerson.h:295
const ROEdge * getDestination() const
Definition: ROPerson.h:176
A person as used by router.
Definition: ROPerson.h:51
#define POSITION_EPS
Definition: config.h:172
const double dep
Definition: ROPerson.h:308
A TripItem is part of a trip, e.g., go from here to here by car.
Definition: ROPerson.h:139
A walk is part of a trip, e.g., go from here to here by foot.
Definition: ROPerson.h:203
A basic edge for routing applications.
Definition: ROEdge.h:72
virtual const ROEdge * getDestination() const =0
const std::string & getStopDest() const
Definition: ROPerson.h:288
virtual ~ROPerson()
Destructor.
Definition: ROPerson.cpp:52
std::vector< TripItem * > myTripItems
the fully specified trips
Definition: ROPerson.h:311
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:60
ROPerson(const SUMOVehicleParameter &pars, const SUMOVTypeParameter *type)
Constructor.
Definition: ROPerson.cpp:47
const double v
Definition: ROPerson.h:226
virtual ~PersonTrip()
Destructor.
Definition: ROPerson.h:247
double getWalkFactor() const
Definition: ROPerson.h:300
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition: ROPerson.cpp:220
double getDestinationPos() const
Definition: ROPerson.h:179
Structure representing possible vehicle parameter.
const std::string destStop
Definition: ROPerson.h:227
double getArrivalPos(bool replaceDefault=true) const
Definition: ROPerson.h:282
virtual bool needsRouting() const
Definition: ROPerson.h:291
const std::string intended
Definition: ROPerson.h:189
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:104
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:205
Definition of vehicle stop (position and duration)
A storage for options typed value containers)
Definition: OptionsCont.h:92
const std::string destStop
Definition: ROPerson.h:188
const ROEdge * to
Definition: ROPerson.h:306
double getDestinationPos() const
Definition: ROPerson.h:272
double getDepartPos(bool replaceDefault=true) const
Definition: ROPerson.h:279
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, double arrivalPos, const std::string &destStop)
Definition: ROPerson.cpp:95
const ROEdge * getDestination() const
Definition: ROPerson.h:112
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
const ConstROEdgeVector edges
Definition: ROPerson.h:225
std::vector< ROVehicle * > & getVehicles()
Definition: ROPerson.h:263
virtual void addTripItem(TripItem *tripIt)
Definition: ROPerson.h:257
double getDestinationPos() const
Definition: ROPerson.h:115
void saveAsXML(OutputDevice &os, const bool) const
Definition: ROPerson.h:118
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition: ROPerson.h:107
virtual const ROEdge * getOrigin() const =0
const double arr
Definition: ROPerson.h:191
virtual void saveAsXML(OutputDevice &os, const bool extended) const =0
double walkFactor
walking speed factor
Definition: ROPerson.h:315
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition: ROPerson.h:328
const ROEdge * getOrigin() const
Definition: ROPerson.h:266
const ROEdge *const to
Definition: ROPerson.h:186
virtual bool isStop() const
Definition: ROPerson.h:93
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:243
virtual ~TripItem()
Destructor.
Definition: ROPerson.h:145
const ROEdge * getDestination() const
Definition: ROPerson.h:269