Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/router/ROPerson.h
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-2025 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
/****************************************************************************/
14
/// @file ROPerson.h
15
/// @author Robert Hilbrich
16
/// @author Michael Behrisch
17
/// @date Sept 2002
18
///
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/Parameterised.h>
27
#include <utils/common/StdDefs.h>
28
#include <utils/common/SUMOTime.h>
29
#include <utils/vehicle/SUMOVehicleParameter.h>
30
#include <utils/vehicle/SUMOVTypeParameter.h>
31
#include "RORoutable.h"
32
#include "RORouteDef.h"
33
#include "ROVehicle.h"
34
35
36
// ===========================================================================
37
// class declarations
38
// ===========================================================================
39
class OutputDevice;
40
class ROEdge;
41
42
43
// ===========================================================================
44
// class definitions
45
// ===========================================================================
46
/**
47
* @class ROPerson
48
* @brief A person as used by router
49
*/
50
class ROPerson : public RORoutable {
51
52
public:
53
class PlanItem;
54
/** @brief Constructor
55
*
56
* @param[in] pars Parameter of this person
57
* @param[in] type The type of the person
58
*/
59
ROPerson(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type);
60
61
/// @brief Destructor
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;
79
/**
80
* @brief Every person has a plan comprising of multiple planItems
81
*
82
*/
83
class PlanItem : public Parameterised {
84
public:
85
/// @brief Destructor
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
}
104
virtual SUMOVehicleParameter::Stop* getStopParameters() {
105
return nullptr;
106
}
107
108
virtual SUMOTime getDuration() const = 0;
109
virtual const std::string& getStopDest() const {
110
return UNDEFINED_STOPPING_PLACE;
111
}
112
113
static const std::string UNDEFINED_STOPPING_PLACE;
114
};
115
116
/**
117
* @brief A planItem can be a Stop
118
*
119
*/
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
}
143
virtual SUMOVehicleParameter::Stop* getStopParameters() {
144
return &stopDesc;
145
}
146
SUMOTime getDuration() const {
147
return stopDesc.duration;
148
}
149
inline const std::string& getStopDest() const {
150
return stopDesc.busstop;
151
}
152
153
private:
154
SUMOVehicleParameter::Stop stopDesc;
155
const ROEdge* const edge;
156
157
private:
158
/// @brief Invalidated assignment operator
159
Stop& operator=(const Stop& src);
160
161
};
162
163
/**
164
* @brief A TripItem is part of a trip, e.g., go from here to here by car
165
*
166
*/
167
class TripItem {
168
public:
169
TripItem(const SUMOTime start, const double cost)
170
: myStart(start), myCost(cost) {}
171
172
/// @brief Destructor
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:
194
const SUMOTime myStart;
195
const double myCost;
196
};
197
198
/**
199
* @brief A ride is part of a trip, e.g., go from here to here by car or bus
200
*
201
*/
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 {
220
return new Ride(myStart, from, to, lines, group, myCost, arrPos, length, destStop, intended, depart);
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;
241
const SUMOTime depart;
242
const double arrPos;
243
const double length;
244
245
private:
246
/// @brief Invalidated assignment operator
247
Ride& operator=(const Ride& src);
248
249
};
250
251
/**
252
* @brief A walk is part of a trip, e.g., go from here to here by foot
253
*
254
*/
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:
283
const ConstROEdgeVector edges;
284
const std::vector<double> exitTimes;
285
const double dur, v, dep, arr;
286
const std::string destStop;
287
288
private:
289
/// @brief Invalidated assignment operator
290
Walk& operator=(const Walk& src);
291
292
};
293
294
/**
295
* @brief A planItem can be a Trip which contains multiple tripItems
296
*
297
*/
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) { }
305
/// @brief Destructor
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
}
321
void addVehicle(ROVehicle* veh) {
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
}
346
SVCPermissions getModes() const {
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
389
/// @brief return duration sum of all trip items
390
SUMOTime getDuration() const;
391
392
private:
393
const ROEdge* from;
394
const ROEdge* to;
395
SVCPermissions modes;
396
const double dep, arr;
397
const std::string stopOrigin;
398
const std::string stopDest;
399
/// @brief the fully specified trips
400
std::vector<TripItem*> myTripItems;
401
/// @brief the vehicles which may be used for routing
402
std::vector<ROVehicle*> myVehicles;
403
/// @brief walking speed factor
404
double walkFactor;
405
/// @brief group id for travelling in groups
406
const std::string group;
407
408
private:
409
/// @brief Invalidated assignment operator
410
PersonTrip& operator=(const PersonTrip& src);
411
412
};
413
414
415
/** @brief Returns the first edge the person takes
416
*
417
* @return The person's departure edge
418
*/
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
428
/** @brief Saves the complete person description.
429
*
430
* Saves the person itself including the trips and stops.
431
*
432
* @param[in] os The routes or alternatives output device to store the routable's description into
433
* @param[in] typeos The types - output device to store additional types into
434
* @param[in] asAlternatives Whether the route shall be saved as route alternatives
435
* @param[in] options to find out about defaults and whether exit times for the edges shall be written
436
* @exception IOError If something fails (not yet implemented)
437
*/
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
444
private:
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
449
private:
450
/**
451
* @brief The plan of the person
452
*/
453
std::vector<PlanItem*> myPlan;
454
455
456
private:
457
/// @brief Invalidated copy constructor
458
ROPerson(const ROPerson& src);
459
460
/// @brief Invalidated assignment operator
461
ROPerson& operator=(const ROPerson& src);
462
463
};
464
465