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-2024 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 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 void setItems(std::vector<TripItem*>& newItems, const ROVehicle* const veh) {
369 assert(myTripItems.empty());
370 myTripItems.swap(newItems);
371 for (auto it = myVehicles.begin(); it != myVehicles.end();) {
372 if (*it != veh) {
373 delete (*it)->getRouteDefinition();
374 delete (*it);
375 it = myVehicles.erase(it);
376 } else {
377 it++;
378 }
379 }
380 }
381
382 void saveVehicles(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
383 void saveAsXML(OutputDevice& os, const bool extended, const bool asTrip, OptionsCont& options) const;
384
385 double getWalkFactor() const {
386 return walkFactor;
387 }
388
390 SUMOTime getDuration() const;
391
392 private:
393 const ROEdge* from;
394 const ROEdge* to;
396 const double dep, arr;
397 const std::string stopOrigin;
398 const std::string stopDest;
400 std::vector<TripItem*> myTripItems;
402 std::vector<ROVehicle*> myVehicles;
406 const std::string group;
407
408 private:
411
412 };
413
414
419 const ROEdge* getDepartEdge() const {
420 return myPlan.front()->getOrigin();
421 }
422
423
424 void computeRoute(const RORouterProvider& provider,
425 const bool removeLoops, MsgHandler* errorHandler);
426
427
438 void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex=0) const;
439
440 std::vector<PlanItem*>& getPlan() {
441 return myPlan;
442 }
443
444private:
445 bool computeIntermodal(SUMOTime time, const RORouterProvider& provider,
446 const PersonTrip* const trip, const ROVehicle* const veh,
447 std::vector<TripItem*>& resultItems, MsgHandler* const errorHandler);
448
449private:
453 std::vector<PlanItem*> myPlan;
454
455
456private:
458 ROPerson(const ROPerson& src);
459
462
463};
long long int SUMOTime
Definition GUI.h:36
std::vector< const ROEdge * > ConstROEdgeVector
Definition ROEdge.h:56
#define TIME2STEPS(x)
Definition SUMOTime.h:57
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:89
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:72
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:250
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:398
SVCPermissions getModes() const
Definition ROPerson.h:346
virtual ~PersonTrip()
Destructor.
Definition ROPerson.h:306
double walkFactor
walking speed factor
Definition ROPerson.h:404
const std::string stopOrigin
Definition ROPerson.h:397
const std::string & getStopDest() const
Definition ROPerson.h:361
double getWalkFactor() const
Definition ROPerson.h:385
std::vector< ROVehicle * > myVehicles
the vehicles which may be used for routing
Definition ROPerson.h:402
const ROEdge * getDestination() const
Definition ROPerson.h:330
const ROEdge * from
Definition ROPerson.h:393
SUMOTime getDuration() const
return duration sum of all trip items
Definition ROPerson.cpp:335
double getArrivalPos(bool replaceDefault=true) const
Definition ROPerson.h:343
const double dep
Definition ROPerson.h:396
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:396
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:259
const std::string group
group id for travelling in groups
Definition ROPerson.h:406
virtual bool needsRouting() const
Definition ROPerson.h:364
const ROEdge * getOrigin() const
Definition ROPerson.h:327
PlanItem * clone() const
Definition ROPerson.cpp:241
const ROEdge * to
Definition ROPerson.h:394
SVCPermissions modes
Definition ROPerson.h:395
PersonTrip(const ROEdge *_to, const std::string _stopDest)
Definition ROPerson.h:300
std::vector< TripItem * > myTripItems
the fully specified trips
Definition ROPerson.h:400
void setItems(std::vector< TripItem * > &newItems, const ROVehicle *const veh)
Definition ROPerson.h:368
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: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: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: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:183
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:285
const ConstROEdgeVector edges
Definition ROPerson.h:283
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
Definition ROPerson.cpp:200
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:50
virtual ~ROPerson()
Destructor.
Definition ROPerson.cpp:53
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:344
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:413
void saveAsXML(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options, int cloneIndex=0) const
Saves the complete person description.
Definition ROPerson.cpp:453
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:440
ROPerson(const ROPerson &src)
Invalidated copy constructor.
const ROEdge * getDepartEdge() const
Returns the first edge the person takes.
Definition ROPerson.h:419
std::vector< PlanItem * > myPlan
The plan of the person.
Definition ROPerson.h:453
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.
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.