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-2026 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>
31#include "RORoutable.h"
32#include "RORouteDef.h"
33#include "ROVehicle.h"
34
35
36// ===========================================================================
37// class declarations
38// ===========================================================================
39class OutputDevice;
40class ROEdge;
41
42
43// ===========================================================================
44// class definitions
45// ===========================================================================
50class ROPerson : public RORoutable {
51
52public:
53 class PlanItem;
59 ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
60
62 virtual ~ROPerson();
63
64 static void addTrip(std::vector<PlanItem*>& plan, const std::string& id,
65 const ROEdge* const from, const ROEdge* const to, const SVCPermissions modeSet, const std::string& vTypes,
66 const double departPos, const std::string& stopOrigin,
67 const double arrivalPos, const std::string& busStop,
68 double walkFactor, const std::string& group);
69
70 static void addRide(std::vector<PlanItem*>& plan, const ROEdge* const from, const ROEdge* const to, const std::string& lines,
71 double arrivalPos, const std::string& destStop, const std::string& group);
72
73 static void addWalk(std::vector<PlanItem*>& plan, const ConstROEdgeVector& edges, const double duration, const double speed,
74 const double departPos, const double arrivalPos, const std::string& busStop);
75
76 static void addStop(std::vector<PlanItem*>& plan, const SUMOVehicleParameter::Stop& stopPar, const ROEdge* const stopEdge);
77
78 class TripItem;
83 class PlanItem : public Parameterised {
84 public:
86 virtual ~PlanItem() {}
87
88 virtual PlanItem* clone() const = 0;
89
90 virtual void addTripItem(TripItem* /* tripIt */) {
91 throw ProcessError();
92 }
93 virtual const ROEdge* getOrigin() const = 0;
94 virtual const ROEdge* getDestination() const = 0;
95 virtual double getDestinationPos() 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 bool asTrip, OptionsCont& options) const = 0;
98 virtual bool isStop() const {
99 return false;
100 }
101 virtual bool needsRouting() const {
102 return false;
103 }
105 return nullptr;
106 }
107
108 virtual SUMOTime getDuration() const = 0;
109 virtual const std::string& getStopDest() const {
111 }
112
113 static const std::string UNDEFINED_STOPPING_PLACE;
114 };
115
120 class Stop : public PlanItem {
121 public:
122 Stop(const SUMOVehicleParameter::Stop& stop, const ROEdge* const stopEdge)
123 : stopDesc(stop), edge(stopEdge) {}
124
125 PlanItem* clone() const {
126 return new Stop(stopDesc, edge);
127 }
128
129 const ROEdge* getOrigin() const {
130 return edge;
131 }
132 const ROEdge* getDestination() const {
133 return edge;
134 }
135 double getDestinationPos() const {
136 return (stopDesc.startPos + stopDesc.endPos) / 2;
137 }
138 void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
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 const ConstROEdgeVector& getEdges() const {
278 return edges;
279 }
280 inline const std::string& getStopDest() const {
281 return destStop;
282 }
283 inline double getDestinationPos() const {
284 return arr == std::numeric_limits<double>::infinity() ? 0 : arr;
285 }
286 void saveAsXML(OutputDevice& os, const bool extended, OptionsCont& options) const;
287
288 private:
290 const std::vector<double> exitTimes;
291 const double dur, v, dep, arr;
292 const std::string destStop;
293
294 private:
296 Walk& operator=(const Walk& src);
297
298 };
299
304 class PersonTrip : public PlanItem {
305 public:
306 PersonTrip(const ROEdge* _to, const std::string _stopDest) :
307 from(0), to(_to), modes(SVC_PEDESTRIAN), dep(0), arr(0), stopDest(_stopDest), walkFactor(1.0) {}
308 PersonTrip(const ROEdge* const _from, const ROEdge* const _to, const SVCPermissions modeSet,
309 const double departPos, const std::string& _stopOrigin, const double arrivalPos, const std::string& _stopDest, double _walkFactor, const std::string& _group) :
310 from(_from), to(_to), modes(modeSet), dep(departPos), arr(arrivalPos), stopOrigin(_stopOrigin), stopDest(_stopDest), walkFactor(_walkFactor), group(_group) { }
312 virtual ~PersonTrip() {
313 for (TripItem* const it : myTripItems) {
314 delete it;
315 }
316 for (ROVehicle* const v : myVehicles) {
317 delete v->getRouteDefinition();
318 delete v;
319 }
320 }
321
322 PlanItem* clone() const;
323
324 virtual void addTripItem(TripItem* tripIt) {
325 myTripItems.push_back(tripIt);
326 }
328 myVehicles.push_back(veh);
329 }
330 std::vector<ROVehicle*>& getVehicles() {
331 return myVehicles;
332 }
333 const std::vector<TripItem*>& getTripItems() const {
334 return myTripItems;
335 }
336 const ROEdge* getOrigin() const {
337 return from != 0 ? from : myTripItems.front()->getOrigin();
338 }
339 const ROEdge* getDestination() const {
340 return to;
341 }
342 double getDestinationPos() const {
343 if (myTripItems.empty()) {
344 return getArrivalPos(true);
345 } else {
346 return myTripItems.back()->getDestinationPos();
347 }
348 }
349 double getDepartPos(bool replaceDefault = true) const {
350 return dep == std::numeric_limits<double>::infinity() && replaceDefault ? 0 : dep;
351 }
352 double getArrivalPos(bool replaceDefault = true) const {
353 return arr == std::numeric_limits<double>::infinity() && replaceDefault ? to->getLength() / 2 : arr;
354 }
356 return modes;
357 }
358 void updateModes(SVCPermissions additionalModes) {
359 modes |= additionalModes;
360 }
361
362 const std::string& getGroup() const {
363 return group;
364 }
365
366 const std::string& getStopOrigin() const {
367 return stopOrigin;
368 }
369
370 const std::string& getStopDest() const {
371 return stopDest;
372 }
373 virtual bool needsRouting() const {
374 return myTripItems.empty();
375 }
376
377 void setItems(std::vector<TripItem*>& newItems, const ROVehicle* const veh) {
378 assert(myTripItems.empty());
379 myTripItems.swap(newItems);
380 for (auto it = myVehicles.begin(); it != myVehicles.end();) {
381 if (*it != veh) {
382 delete (*it)->getRouteDefinition();
383 delete (*it);
384 it = myVehicles.erase(it);
385 } else {
386 it++;
387 }
388 }
389 }
390
391 void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
392 void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
393
394 double getWalkFactor() const {
395 return walkFactor;
396 }
397
399 SUMOTime getDuration() const;
400
401 private:
402 const ROEdge* from;
403 const ROEdge* to;
405 const double dep, arr;
406 const std::string stopOrigin;
407 const std::string stopDest;
409 std::vector<TripItem*> myTripItems;
411 std::vector<ROVehicle*> myVehicles;
415 const std::string group;
416
417 private:
420
421 };
422
423
428 const ROEdge* getDepartEdge() const {
429 return myPlan.front()->getOrigin();
430 }
431
432
433 void computeRoute(const RORouterProvider& provider,
434 const bool removeLoops, MsgHandler* errorHandler);
435
436
447 void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const;
448
449 std::vector<PlanItem*>& getPlan() {
450 return myPlan;
451 }
452
453private:
454 bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
455 const PersonTrip* const trip, const ROVehicle* const veh,
456 std::vector<TripItem*>& resultItems, MsgHandler* const errorHandler);
457
458private:
462 std::vector<PlanItem*> myPlan;
463
465
466private:
468 ROPerson(const ROPerson& src);
469
472
473};
long long int SUMOTime
Definition GUI.h:36
std::vector< const ROEdge * > ConstROEdgeVector
Definition ROEdge.h:57
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_PEDESTRIAN
pedestrian
A storage for options typed value containers)
Definition OptionsCont.h:92
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.
A basic edge for routing applications.
Definition ROEdge.h:73
double getLength() const
Returns the length of the edge.
Definition ROEdge.h:225
A planItem can be a Trip which contains multiple tripItems.
Definition ROPerson.h:304
double getDepartPos(bool replaceDefault=true) const
Definition ROPerson.h:349
void saveVehicles(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
Definition ROPerson.cpp:255
double getDestinationPos() const
Definition ROPerson.h:342
PersonTrip & operator=(const PersonTrip &src)
Invalidated assignment operator.
const std::string & getStopOrigin() const
Definition ROPerson.h:366
const std::string stopDest
Definition ROPerson.h:407
SVCPermissions getModes() const
Definition ROPerson.h:355
virtual ~PersonTrip()
Destructor.
Definition ROPerson.h:312
double walkFactor
walking speed factor
Definition ROPerson.h:413
const std::string stopOrigin
Definition ROPerson.h:406
const std::string & getStopDest() const
Definition ROPerson.h:370
double getWalkFactor() const
Definition ROPerson.h:394
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition ROPerson.h:411
const ROEdge * getDestination() const
Definition ROPerson.h:339
const ROEdge * from
Definition ROPerson.h:402
SUMOTime getDuration() const
return duration sum of all trip items
Definition ROPerson.cpp:340
double getArrivalPos(bool replaceDefault=true) const
Definition ROPerson.h:352
const double dep
Definition ROPerson.h:405
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:308
const double arr
Definition ROPerson.h:405
virtual void addTripItem(TripItem *tripIt)
Definition ROPerson.h:324
std::vector< ROVehicle * > & getVehicles()
Definition ROPerson.h:330
const std::string & getGroup() const
Definition ROPerson.h:362
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const
Definition ROPerson.cpp:264
const std::string group
group id for travelling in groups
Definition ROPerson.h:415
virtual bool needsRouting() const
Definition ROPerson.h:373
const ROEdge * getOrigin() const
Definition ROPerson.h:336
const std::vector< TripItem * > & getTripItems() const
Definition ROPerson.h:333
PlanItem * clone() const
Definition ROPerson.cpp:246
const ROEdge * to
Definition ROPerson.h:403
SVCPermissions modes
Definition ROPerson.h:404
PersonTrip(const ROEdge *_to, const std::string _stopDest)
Definition ROPerson.h:306
std::vector< TripItem * > myTripItems
the fully specified trips
Definition ROPerson.h:409
void setItems(std::vector< TripItem * > &newItems, const ROVehicle *const veh)
Definition ROPerson.h:377
void addVehicle(ROVehicle *veh)
Definition ROPerson.h:327
void updateModes(SVCPermissions additionalModes)
Definition ROPerson.h:358
Every person has a plan comprising of multiple planItems.
Definition ROPerson.h:83
virtual double getDestinationPos() const =0
virtual ~PlanItem()
Destructor.
Definition ROPerson.h:86
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:113
virtual PlanItem * clone() const =0
virtual bool isStop() const
Definition ROPerson.h:98
virtual const ROEdge * getDestination() const =0
virtual bool needsRouting() const
Definition ROPerson.h:101
virtual const std::string & getStopDest() const
Definition ROPerson.h:109
virtual void saveVehicles(OutputDevice &, OutputDevice *const, bool, OptionsCont &) const
Definition ROPerson.h:96
virtual SUMOTime getDuration() const =0
virtual void addTripItem(TripItem *)
Definition ROPerson.h:90
virtual SUMOVehicleParameter::Stop * getStopParameters()
Definition ROPerson.h:104
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:141
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:120
virtual SUMOVehicleParameter::Stop * getStopParameters()
Definition ROPerson.h:143
bool isStop() const
Definition ROPerson.h:140
PlanItem * clone() const
Definition ROPerson.h:125
SUMOTime getDuration() const
Definition ROPerson.h:146
double getDestinationPos() const
Definition ROPerson.h:135
const ROEdge * getDestination() const
Definition ROPerson.h:132
Stop(const SUMOVehicleParameter::Stop &stop, const ROEdge *const stopEdge)
Definition ROPerson.h:122
const ROEdge *const edge
Definition ROPerson.h:155
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const
Definition ROPerson.cpp:188
SUMOVehicleParameter::Stop stopDesc
Definition ROPerson.h:154
const std::string & getStopDest() const
Definition ROPerson.h:149
const ROEdge * getOrigin() const
Definition ROPerson.h:129
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:291
const ConstROEdgeVector edges
Definition ROPerson.h:289
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
Definition ROPerson.cpp:205
const double dur
Definition ROPerson.h:291
TripItem * clone() const
Definition ROPerson.h:267
const ROEdge * getOrigin() const
Definition ROPerson.h:271
const double arr
Definition ROPerson.h:291
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.
const std::string & getStopDest() const
Definition ROPerson.h:280
double getDestinationPos() const
Definition ROPerson.h:283
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:290
const ConstROEdgeVector & getEdges() const
Definition ROPerson.h:277
const double dep
Definition ROPerson.h:291
const std::string destStop
Definition ROPerson.h:292
A person as used by router.
Definition ROPerson.h:50
static bool myHaveWarnedPTMissing
Definition ROPerson.h:464
virtual ~ROPerson()
Destructor.
Definition ROPerson.cpp:55
bool computeIntermodal(SUMOTime time, const RORouterProvider &provider, const PersonTrip *const trip, const ROVehicle *const veh, std::vector< TripItem * > &resultItems, MsgHandler *const errorHandler)
Definition ROPerson.cpp:349
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:63
static void addStop(std::vector< PlanItem * > &plan, const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition ROPerson.cpp:135
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:118
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
Definition ROPerson.cpp:423
void saveAsXML(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options, int cloneIndex=0) const
Saves the complete person description.
Definition ROPerson.cpp:555
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:126
std::vector< PlanItem * > & getPlan()
Definition ROPerson.h:449
ROPerson(const ROPerson &src)
Invalidated copy constructor.
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition ROPerson.h:428
std::vector< PlanItem * > myPlan
The plan of the person.
Definition ROPerson.h:462
A routable thing such as a vehicle or person.
Definition RORoutable.h:53
A vehicle as used by router.
Definition ROVehicle.h:51
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
double startPos
The stopping position start.
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.