Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ROPerson.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2023 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>
30#include "RORoutable.h"
31#include "RORouteDef.h"
32#include "ROVehicle.h"
33
34
35// ===========================================================================
36// class declarations
37// ===========================================================================
38class OutputDevice;
39class ROEdge;
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
49class ROPerson : public RORoutable {
50
51public:
52 class PlanItem;
58 ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
59
61 virtual ~ROPerson();
62
63 static void addTrip(std::vector<PlanItem*>& plan, const std::string& id,
64 const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet, const std::string& vTypes,
65 const double departPos, const std::string& stopOrigin,
66 const double arrivalPos, const std::string& busStop,
67 double walkFactor, const std::string& group);
68
69 static void addRide(std::vector<PlanItem*>& plan, const ROEdge* const from, const ROEdge* const to, const std::string& lines,
70 double arrivalPos, const std::string& destStop, const std::string& group);
71
72 static void addWalk(std::vector<PlanItem*>& plan, const ConstROEdgeVector& edges, const double duration, const double speed,
73 const double departPos, const double arrivalPos, const std::string& busStop);
74
75 static void addStop(std::vector<PlanItem*>& plan, const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
76
77 class TripItem;
82 class PlanItem {
83 public:
85 virtual ~PlanItem() {}
86
87 virtual PlanItem* clone() const = 0;
88
89 virtual void addTripItem(TripItem* /* tripIt */) {
90 throw ProcessError();
91 }
92 virtual const ROEdge* getOrigin() const = 0;
93 virtual const ROEdge* getDestination() const = 0;
94 virtual double getDestinationPos() const = 0;
95 virtual void saveVehicles(OutputDevice& /* os */, OutputDevice* const /* typeos */, bool /* asAlternatives */, OptionsCont& /* options */) const {}
96 virtual void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const = 0;
97 virtual bool isStop() const {
98 return false;
99 }
100 virtual bool needsRouting() const {
101 return false;
102 }
104 return nullptr;
105 }
106
107 virtual SUMOTime getDuration() const = 0;
108 virtual const std::string& getStopDest() const {
110 }
111
112 static const std::string UNDEFINED_STOPPING_PLACE;
113 };
114
119 class Stop : public PlanItem {
120 public:
121 Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
122 : stopDesc(stop), edge(stopEdge) {}
123
124 PlanItem* clone() const {
125 return new Stop(stopDesc, edge);
126 }
127
128 const ROEdge* getOrigin() const {
129 return edge;
130 }
131 const ROEdge* getDestination() const {
132 return edge;
133 }
134 double getDestinationPos() const {
135 return (stopDesc.startPos + stopDesc.endPos) / 2;
136 }
137 void saveAsXML(OutputDevice& os, const bool /* extended */, const bool /*asTrip*/, OptionsCont& /* options */) const {
138 stopDesc.write(os);
139 }
140 bool isStop() const {
141 return true;
142 }
147 return stopDesc.duration;
148 }
149 inline const std::string& getStopDest() const {
150 return stopDesc.busstop;
151 }
152
153 private:
155 const ROEdge* const edge;
156
157 private:
159 Stop& operator=(const Stop& src);
160
161 };
162
167 class TripItem {
168 public:
169 TripItem(const SUMOTime start, const double cost)
170 : myStart(start), myCost(cost) {}
171
173 virtual ~TripItem() {}
174
175 virtual TripItem* clone() const = 0;
176
177 virtual const ROEdge* getOrigin() const = 0;
178 virtual const ROEdge* getDestination() const = 0;
179 virtual double getDestinationPos() const = 0;
180 virtual void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const = 0;
181
182 inline SUMOTime getStart() const {
183 return myStart;
184 }
185
186 inline SUMOTime getDuration() const {
187 return TIME2STEPS(myCost);
188 }
189
190 inline double getCost() const {
191 return myCost;
192 }
193 protected:
195 const double myCost;
196 };
197
202 class Ride : public TripItem {
203 public:
204 Ride(const SUMOTime start, const ROEdge* const _from, const ROEdge* const _to,
205 const std::string& _lines, const std::string& _group, const double cost,
206 const double arrivalPos, const double _length,
207 const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
208 TripItem(start, cost),
209 from(_from), to(_to),
210 lines(_lines),
211 group(_group),
212 destStop(_destStop),
213 intended(_intended),
214 depart(_depart),
215 arrPos(arrivalPos),
216 length(_length) {
217 }
218
219 TripItem* clone() const {
221 }
222
223 inline const ROEdge* getOrigin() const {
224 return from;
225 }
226 inline const ROEdge* getDestination() const {
227 return to;
228 }
229 inline double getDestinationPos() const {
230 return arrPos == std::numeric_limits<double>::infinity() ? -NUMERICAL_EPS : arrPos;
231 }
232 void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const;
233
234 private:
235 const ROEdge* const from;
236 const ROEdge* const to;
237 const std::string lines;
238 const std::string group;
239 const std::string destStop;
240 const std::string intended;
242 const double arrPos;
243 const double length;
244
245 private:
247 Ride& operator=(const Ride& src);
248
249 };
250
255 class Walk : public TripItem {
256 public:
257 Walk(const SUMOTime start, const ConstROEdgeVector& _edges, const double cost,
258 const std::vector<double>& _exitTimes,
259 double departPos = std::numeric_limits<double>::infinity(),
260 double arrivalPos = std::numeric_limits<double>::infinity(),
261 const std::string& _destStop = "")
262 : TripItem(start, cost), edges(_edges), exitTimes(_exitTimes), dur(-1), v(-1), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
263 Walk(const SUMOTime start, const ConstROEdgeVector& edges, const double cost, const double duration, const double speed,
264 const double departPos, const double arrivalPos, const std::string& _destStop)
265 : TripItem(start, cost), edges(edges), dur(duration), v(speed), dep(departPos), arr(arrivalPos), destStop(_destStop) {}
266
267 TripItem* clone() const {
268 return new Walk(myStart, edges, myCost, exitTimes, dep, arr, destStop);
269 }
270
271 inline const ROEdge* getOrigin() const {
272 return edges.front();
273 }
274 inline const ROEdge* getDestination() const {
275 return edges.back();
276 }
277 inline double getDestinationPos() const {
278 return arr == std::numeric_limits<double>::infinity() ? 0 : arr;
279 }
280 void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const;
281
282 private:
284 const std::vector<double> exitTimes;
285 const double dur, v, dep, arr;
286 const std::string destStop;
287
288 private:
290 Walk& operator=(const Walk& src);
291
292 };
293
298 class PersonTrip : public PlanItem {
299 public:
300 PersonTrip(const ROEdge* _to, const std::string _stopDest) :
301 from(0), to(_to), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(_stopDest), walkFactor(1.0) {}
302 PersonTrip(const ROEdge* const _from, const ROEdge* const _to, const SVCPermissions modeSet,
303 const double departPos, const std::string& _stopOrigin, const double arrivalPos, const std::string& _stopDest, double _walkFactor, const std::string& _group) :
304 from(_from), to(_to), modes(modeSet), dep(departPos), arr(arrivalPos), stopOrigin(_stopOrigin), stopDest(_stopDest), walkFactor(_walkFactor), group(_group) { }
306 virtual ~PersonTrip() {
307 for (TripItem* const it : myTripItems) {
308 delete it;
309 }
310 for (ROVehicle* const v : myVehicles) {
311 delete v->getRouteDefinition();
312 delete v;
313 }
314 }
315
316 PlanItem* clone() const;
317
318 virtual void addTripItem(TripItem* tripIt) {
319 myTripItems.push_back(tripIt);
320 }
322 myVehicles.push_back(veh);
323 }
324 std::vector<ROVehicle*>& getVehicles() {
325 return myVehicles;
326 }
327 const ROEdge* getOrigin() const {
328 return from != 0 ? from : myTripItems.front()->getOrigin();
329 }
330 const ROEdge* getDestination() const {
331 return to;
332 }
333 double getDestinationPos() const {
334 if (myTripItems.empty()) {
335 return getArrivalPos(true);
336 } else {
337 return myTripItems.back()->getDestinationPos();
338 }
339 }
340 double getDepartPos(bool replaceDefault = true) const {
341 return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
342 }
343 double getArrivalPos(bool replaceDefault = true) const {
344 return arr == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : arr;
345 }
347 return modes;
348 }
349 void updateModes(SVCPermissions additionalModes) {
350 modes |= additionalModes;
351 }
352
353 const std::string& getGroup() const {
354 return group;
355 }
356
357 const std::string& getStopOrigin() const {
358 return stopOrigin;
359 }
360
361 const std::string& getStopDest() const {
362 return stopDest;
363 }
364 virtual bool needsRouting() const {
365 return myTripItems.empty();
366 }
367
368 double getCost() const {
369 double result = 0;
370 for (TripItem* const it : myTripItems) {
371 result += it->getCost();
372 }
373 return result;
374 }
375
376 void clearItems() {
377 for (TripItem* const it : myTripItems) {
378 delete it;
379 }
380 myTripItems.clear();
381 }
382
383 void copyItems(PersonTrip* trip, ROVehicle* veh) {
384 for (TripItem* const it : myTripItems) {
385 delete it;
386 }
387 myTripItems = trip->myTripItems;
388 for (auto it = myVehicles.begin(); it != myVehicles.end();) {
389 if (*it != veh) {
390 delete (*it)->getRouteDefinition();
391 delete (*it);
392 it = myVehicles.erase(it);
393 } else {
394 it++;
395 }
396 }
397 }
398
399 void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
400 void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
401
402 double getWalkFactor() const {
403 return walkFactor;
404 }
405
407 SUMOTime getDuration() const;
408
409 private:
410 const ROEdge* from;
411 const ROEdge* to;
413 const double dep, arr;
414 const std::string stopOrigin;
415 const std::string stopDest;
417 std::vector<TripItem*> myTripItems;
419 std::vector<ROVehicle*> myVehicles;
423 const std::string group;
424
425 private:
428
429 };
430
431
436 const ROEdge* getDepartEdge() const {
437 return myPlan.front()->getOrigin();
438 }
439
440
441 void computeRoute(const RORouterProvider& provider,
442 const bool removeLoops, MsgHandler* errorHandler);
443
444
455 void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
456
457 std::vector<PlanItem*>& getPlan() {
458 return myPlan;
459 }
460
461private:
462 bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
463 PersonTrip* const trip, const ROVehicle* const veh, MsgHandler* const errorHandler);
464
465private:
469 std::vector<PlanItem*> myPlan;
470
471
472private:
474 ROPerson(const ROPerson& src);
475
478
479};
long long int SUMOTime
Definition GUI.h:36
std::vector< const ROEdge * > ConstROEdgeVector
Definition ROEdge.h:54
#define TIME2STEPS(x)
Definition SUMOTime.h:57
@ 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.
A basic edge for routing applications.
Definition ROEdge.h:70
A planItem can be a Trip which contains multiple tripItems.
Definition ROPerson.h:298
double getDepartPos(bool replaceDefault=true) const
Definition ROPerson.h:340
void saveVehicles(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
Definition ROPerson.cpp:233
double getDestinationPos() const
Definition ROPerson.h:333
PersonTrip & operator=(const PersonTrip &src)
Invalidated assignment operator.
const std::string & getStopOrigin() const
Definition ROPerson.h:357
const std::string stopDest
Definition ROPerson.h:415
SVCPermissions getModes() const
Definition ROPerson.h:346
virtual ~PersonTrip()
Destructor.
Definition ROPerson.h:306
double getCost() const
Definition ROPerson.h:368
double walkFactor
walking speed factor
Definition ROPerson.h:421
const std::string stopOrigin
Definition ROPerson.h:414
const std::string & getStopDest() const
Definition ROPerson.h:361
double getWalkFactor() const
Definition ROPerson.h:402
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition ROPerson.h:419
const ROEdge * getDestination() const
Definition ROPerson.h:330
const ROEdge * from
Definition ROPerson.h:410
SUMOTime getDuration() const
return duration sum of all trip items
Definition ROPerson.cpp:318
double getArrivalPos(bool replaceDefault=true) const
Definition ROPerson.h:343
void copyItems(PersonTrip *trip, ROVehicle *veh)
Definition ROPerson.h:383
const double dep
Definition ROPerson.h:413
PersonTrip(const ROEdge *const _from, const ROEdge *const _to, const SVCPermissions modeSet, const double departPos, const std::string &_stopOrigin, const double arrivalPos, const std::string &_stopDest, double _walkFactor, const std::string &_group)
Definition ROPerson.h:302
const double arr
Definition ROPerson.h:413
virtual void addTripItem(TripItem *tripIt)
Definition ROPerson.h:318
std::vector< ROVehicle * > & getVehicles()
Definition ROPerson.h:324
const std::string & getGroup() const
Definition ROPerson.h:353
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const
Definition ROPerson.cpp:242
const std::string group
group id for travelling in groups
Definition ROPerson.h:423
virtual bool needsRouting() const
Definition ROPerson.h:364
const ROEdge * getOrigin() const
Definition ROPerson.h:327
PlanItem * clone() const
Definition ROPerson.cpp:224
const ROEdge * to
Definition ROPerson.h:411
SVCPermissions modes
Definition ROPerson.h:412
PersonTrip(const ROEdge *_to, const std::string _stopDest)
Definition ROPerson.h:300
std::vector< TripItem * > myTripItems
the fully specified trips
Definition ROPerson.h:417
void addVehicle(ROVehicle *veh)
Definition ROPerson.h:321
void updateModes(SVCPermissions additionalModes)
Definition ROPerson.h:349
Every person has a plan comprising of multiple planItems.
Definition ROPerson.h:82
virtual double getDestinationPos() const =0
virtual ~PlanItem()
Destructor.
Definition ROPerson.h:85
virtual void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const =0
virtual const ROEdge * getOrigin() const =0
static const std::string UNDEFINED_STOPPING_PLACE
Definition ROPerson.h:112
virtual PlanItem * clone() const =0
virtual bool isStop() const
Definition ROPerson.h:97
virtual const ROEdge * getDestination() const =0
virtual bool needsRouting() const
Definition ROPerson.h:100
virtual const std::string & getStopDest() const
Definition ROPerson.h:108
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition ROPerson.h:95
virtual SUMOTime getDuration() const =0
virtual void addTripItem(TripItem *)
Definition ROPerson.h:89
virtual SUMOVehicleParameter::Stop * getStopParameters()
Definition ROPerson.h:103
A ride is part of a trip, e.g., go from here to here by car or bus.
Definition ROPerson.h:202
const double length
Definition ROPerson.h:243
double getDestinationPos() const
Definition ROPerson.h:229
const std::string lines
Definition ROPerson.h:237
const ROEdge * getDestination() const
Definition ROPerson.h:226
const std::string destStop
Definition ROPerson.h:239
const std::string group
Definition ROPerson.h:238
const std::string intended
Definition ROPerson.h:240
const ROEdge * getOrigin() const
Definition ROPerson.h:223
TripItem * clone() const
Definition ROPerson.h:219
const SUMOTime depart
Definition ROPerson.h:241
Ride(const SUMOTime start, const ROEdge *const _from, const ROEdge *const _to, const std::string &_lines, const std::string &_group, const double cost, const double arrivalPos, const double _length, const std::string &_destStop="", const std::string &_intended="", const SUMOTime _depart=-1)
Definition ROPerson.h:204
const ROEdge *const to
Definition ROPerson.h:236
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
Definition ROPerson.cpp:139
Ride & operator=(const Ride &src)
Invalidated assignment operator.
const double arrPos
Definition ROPerson.h:242
const ROEdge *const from
Definition ROPerson.h:235
A planItem can be a Stop.
Definition ROPerson.h:119
virtual SUMOVehicleParameter::Stop * getStopParameters()
Definition ROPerson.h:143
bool isStop() const
Definition ROPerson.h:140
PlanItem * clone() const
Definition ROPerson.h:124
SUMOTime getDuration() const
Definition ROPerson.h:146
double getDestinationPos() const
Definition ROPerson.h:134
const ROEdge * getDestination() const
Definition ROPerson.h:131
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition ROPerson.h:121
void saveAsXML(OutputDevice &os, const bool, const bool, OptionsCont &) const
Definition ROPerson.h:137
const ROEdge *const edge
Definition ROPerson.h:155
SUMOVehicleParameter::Stop stopDesc
Definition ROPerson.h:154
const std::string & getStopDest() const
Definition ROPerson.h:149
const ROEdge * getOrigin() const
Definition ROPerson.h:128
Stop & operator=(const Stop &src)
Invalidated assignment operator.
A TripItem is part of a trip, e.g., go from here to here by car.
Definition ROPerson.h:167
double getCost() const
Definition ROPerson.h:190
SUMOTime getStart() const
Definition ROPerson.h:182
virtual TripItem * clone() const =0
TripItem(const SUMOTime start, const double cost)
Definition ROPerson.h:169
virtual const ROEdge * getOrigin() const =0
SUMOTime getDuration() const
Definition ROPerson.h:186
virtual double getDestinationPos() const =0
const SUMOTime myStart
Definition ROPerson.h:194
const double myCost
Definition ROPerson.h:195
virtual void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const =0
virtual const ROEdge * getDestination() const =0
virtual ~TripItem()
Destructor.
Definition ROPerson.h:173
A walk is part of a trip, e.g., go from here to here by foot.
Definition ROPerson.h:255
const ROEdge * getDestination() const
Definition ROPerson.h:274
const double v
Definition ROPerson.h:285
const ConstROEdgeVector edges
Definition ROPerson.h:283
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
Definition ROPerson.cpp:183
const double dur
Definition ROPerson.h:285
TripItem * clone() const
Definition ROPerson.h:267
const ROEdge * getOrigin() const
Definition ROPerson.h:271
const double arr
Definition ROPerson.h:285
Walk(const SUMOTime start, 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:263
Walk & operator=(const Walk &src)
Invalidated assignment operator.
double getDestinationPos() const
Definition ROPerson.h:277
Walk(const SUMOTime start, const ConstROEdgeVector &_edges, const double cost, const std::vector< double > &_exitTimes, double departPos=std::numeric_limits< double >::infinity(), double arrivalPos=std::numeric_limits< double >::infinity(), const std::string &_destStop="")
Definition ROPerson.h:257
const std::vector< double > exitTimes
Definition ROPerson.h:284
const double dep
Definition ROPerson.h:285
const std::string destStop
Definition ROPerson.h:286
A person as used by router.
Definition ROPerson.h:49
virtual ~ROPerson()
Destructor.
Definition ROPerson.cpp:53
ROPerson & operator=(const ROPerson &src)
Invalidated assignment operator.
static void addTrip(std::vector< PlanItem * > &plan, const std::string &id, const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const double departPos, const std::string &stopOrigin, const double arrivalPos, const std::string &busStop, double walkFactor, const std::string &group)
Definition ROPerson.cpp:61
static void addStop(std::vector< PlanItem * > &plan, const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition ROPerson.cpp:133
static void addRide(std::vector< PlanItem * > &plan, 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:116
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition ROPerson.cpp:395
static void addWalk(std::vector< PlanItem * > &plan, const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition ROPerson.cpp:124
std::vector< PlanItem * > & getPlan()
Definition ROPerson.h:457
ROPerson(const ROPerson &src)
Invalidated copy constructor.
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition ROPerson.h:436
bool computeIntermodal(SUMOTime time, const RORouterProvider &provider, PersonTrip *const trip, const ROVehicle *const veh, MsgHandler *const errorHandler)
Definition ROPerson.cpp:327
void saveAsXML(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
Saves the complete person description.
Definition ROPerson.cpp:439
std::vector< PlanItem * > myPlan
The plan of the person.
Definition ROPerson.h:469
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)
double startPos
The stopping position start.
void write(OutputDevice &dev, const bool close=true, const bool writeTagAndParents=true) const
Writes the stop as XML.
double endPos
The stopping position end.
std::string busstop
(Optional) bus stop if one is assigned to the stop
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.