Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSBaseVehicle.h
193674 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2010-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
/****************************************************************************/
14
/// @file MSBaseVehicle.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @author Jakob Erdmann
18
/// @date Mon, 8 Nov 2010
19
///
20
// A base class for vehicle implementations
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <iostream>
26
#include <vector>
27
#include <set>
28
#include <utils/common/StdDefs.h>
29
#include <utils/emissions/EnergyParams.h>
30
#include <utils/emissions/PollutantsInterface.h>
31
#include <utils/vehicle/SUMOVehicle.h>
32
#include "MSRoute.h"
33
#include "MSMoveReminder.h"
34
#include "MSVehicleType.h"
35
36
37
// ===========================================================================
38
// class declarations
39
// ===========================================================================
40
class MSLane;
41
class MSStop;
42
class MSDevice_Transportable;
43
class MSDevice_Emissions;
44
class MSVehicleDevice;
45
class MSEdgeWeightsStorage;
46
class MSChargingStation;
47
class StoppingPlaceMemory;
48
49
50
// ===========================================================================
51
// class definitions
52
// ===========================================================================
53
/**
54
* @class MSBaseVehicle
55
* @brief The base class for microscopic and mesoscopic vehicles
56
*/
57
class MSBaseVehicle : public SUMOVehicle {
58
public:
59
// XXX: This definition was introduced to make the MSVehicle's previousSpeed
60
// available in the context of MSMoveReminder::notifyMove(). Another solution
61
// would be to modify notifyMove()'s interface to work with MSVehicle instead
62
// of SUMOVehicle (it is only called with MSVehicles!). Refs. #2579
63
/** @brief Returns the vehicle's previous speed
64
* @return The vehicle's speed
65
*/
66
double getPreviousSpeed() const;
67
68
friend class GUIBaseVehicle;
69
70
/** @enum RouteValidity
71
*/
72
enum RouteValidity {
73
ROUTE_VALID = 0,
74
ROUTE_UNCHECKED = 1 << 0,
75
/// route was checked and is valid
76
ROUTE_INVALID = 1 << 1,
77
// starting edge permissions invalid (could change)
78
ROUTE_START_INVALID_PERMISSIONS = 1 << 2,
79
// insertion lane does not exist
80
ROUTE_START_INVALID_LANE = 1 << 3
81
};
82
83
/** @brief Constructor
84
* @param[in] pars The vehicle description
85
* @param[in] route The vehicle's route
86
* @param[in] type The vehicle's type
87
* @param[in] speedFactor The factor for driven lane's speed limits
88
* @exception ProcessError If a value is wrong
89
*/
90
MSBaseVehicle(SUMOVehicleParameter* pars, ConstMSRoutePtr route,
91
MSVehicleType* type, const double speedFactor);
92
93
94
/// @brief Destructor
95
virtual ~MSBaseVehicle();
96
97
virtual void initDevices();
98
99
bool isVehicle() const {
100
return true;
101
}
102
103
/// @brief set the id (inherited from Named but forbidden for vehicles)
104
void setID(const std::string& newID);
105
106
/** @brief Returns the vehicle's parameter (including departure definition)
107
*
108
* @return The vehicle's parameter
109
*/
110
const SUMOVehicleParameter& getParameter() const;
111
112
/// @brief retrieve parameters of devices, models and the vehicle itself
113
std::string getPrefixedParameter(const std::string& key, std::string& error) const;
114
115
/// @brief replace the vehicle parameter (deleting the old one)
116
void replaceParameter(const SUMOVehicleParameter* newParameter);
117
118
/// @brief check whether the vehicle is equiped with a device of the given name
119
bool hasDevice(const std::string& deviceName) const;
120
121
/// @brief create device of the given type
122
void createDevice(const std::string& deviceName);
123
124
/// @brief try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no device parameter by that name exists
125
std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;
126
127
/// @brief try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device parameter by that name exists
128
void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);
129
130
/// @brief set individual junction model paramete (not type related)
131
void setJunctionModelParameter(const std::string& key, const std::string& value);
132
133
/// @brief set individual carFollow model parameters (not type related)
134
void setCarFollowModelParameter(const std::string& key, const std::string& value);
135
136
/** @brief Returns the current route
137
* @return The route the vehicle uses
138
*/
139
inline const MSRoute& getRoute() const {
140
return *myRoute;
141
}
142
143
/** @brief Returns the current route
144
* @return The route the vehicle uses
145
*/
146
inline ConstMSRoutePtr getRoutePtr() const {
147
return myRoute;
148
}
149
150
/** @brief Returns the vehicle's type definition
151
* @return The vehicle's type definition
152
*/
153
inline const MSVehicleType& getVehicleType() const {
154
return *myType;
155
}
156
157
/** @brief Returns the vehicle's type parameter
158
* @return The vehicle's type parameter
159
*/
160
inline const SUMOVTypeParameter& getVTypeParameter() const {
161
return myType->getParameter();
162
}
163
164
/** @brief Returns the vehicle's access class
165
* @return The vehicle's access class
166
*/
167
inline SUMOVehicleClass getVClass() const {
168
return myType->getParameter().vehicleClass;
169
}
170
171
/** @brief Returns whether this object is ignoring transient permission
172
* changes (during routing)
173
*/
174
bool ignoreTransientPermissions() const;
175
176
/// @brief whether instant stopping is permitted
177
virtual bool instantStopping() const {
178
return false;
179
}
180
181
/** @brief Returns the maximum speed (the minimum of desired and technical maximum speed)
182
* @return The vehicle's maximum speed
183
*/
184
double getMaxSpeed() const;
185
186
/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at
187
*
188
* If the rest of the route (counted from the current edge) has less than nSuccs edges,
189
* 0 is returned.
190
* @param[in] nSuccs The number of edge to look forward
191
* @return The nSuccs'th following edge in the vehicle's route
192
*/
193
const MSEdge* succEdge(int nSuccs) const;
194
195
/** @brief Returns the edge the vehicle is currently at
196
*
197
* @return The current edge in the vehicle's route
198
*/
199
const MSEdge* getEdge() const;
200
201
/** @brief Returns the edge the vehicle is currently at (possibly an
202
* internal edge)
203
*/
204
virtual const MSEdge* getCurrentEdge() const {
205
return getEdge();
206
}
207
208
/// @brief returns the numerical ids of edges to travel
209
const std::set<SUMOTrafficObject::NumericalID> getUpcomingEdgeIDs() const;
210
211
/** @brief Returns whether the vehicle stops at the given stopping place */
212
bool stopsAt(MSStoppingPlace* stop) const;
213
214
/** @brief Returns whether the vehicle stops at the given edge */
215
bool stopsAtEdge(const MSEdge* edge) const;
216
217
/// @brief returns the next edge (possibly an internal edge)
218
virtual const MSEdge* getNextEdgePtr() const {
219
return nullptr;
220
}
221
222
/** @brief Returns the information whether the vehicle is on a road (is simulated)
223
* @return Whether the vehicle is simulated
224
*/
225
virtual bool isOnRoad() const {
226
return true;
227
}
228
229
/** @brief Returns the information whether the vehicle is fully controlled
230
* via TraCI
231
* @return Whether the vehicle is remote-controlled
232
*/
233
virtual bool isRemoteControlled() const {
234
return false;
235
}
236
237
virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
238
UNUSED_PARAMETER(lookBack);
239
return false;
240
}
241
242
/** @brief Returns the information whether the front of the vehhicle is on the given lane
243
* @return Whether the vehicle's front is on that lane
244
*/
245
virtual bool isFrontOnLane(const MSLane*) const {
246
return true;
247
}
248
249
/** @brief Get the vehicle's lateral position on the lane
250
* @return The lateral position of the vehicle (in m relative to the
251
* centerline of the lane)
252
*/
253
virtual double getLateralPositionOnLane() const {
254
return 0;
255
}
256
257
/** @brief Get the vehicle's lateral position on the edge of the given lane
258
* (or its current edge if lane == 0)
259
* @return The lateral position of the vehicle (in m distance between right
260
* side of vehicle and ride side of edge
261
*/
262
virtual double getRightSideOnEdge(const MSLane* lane = 0) const {
263
UNUSED_PARAMETER(lane);
264
return 0;
265
}
266
267
/** @brief Returns the starting point for reroutes (usually the current edge)
268
*
269
* This differs from *myCurrEdge only if the vehicle is on an internal edge
270
* @return The rerouting start point
271
*/
272
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const {
273
return myCurrEdge;
274
}
275
276
/** @brief Returns the end point for reroutes (usually the last edge of the route)
277
*
278
* @return The rerouting end point
279
*/
280
virtual const MSEdge* getRerouteDestination() const {
281
return myRoute->getLastEdge();
282
}
283
284
/** @brief Returns the time loss in seconds
285
*/
286
virtual double getTimeLossSeconds() const {
287
// better timeLoss for meso?
288
return 0;
289
}
290
291
/** @brief Returns the number of seconds waited (speed was lesser than 0.1m/s)
292
*
293
* The value is reset if the vehicle moves faster than 0.1m/s
294
* Intentional stopping does not count towards this time.
295
* @return The time the vehicle is standing
296
*/
297
double getWaitingSeconds() const {
298
return STEPS2TIME(getWaitingTime());
299
}
300
301
302
303
/** @brief Returns an iterator pointing to the current edge in this vehicles route
304
* @return The current route pointer
305
*/
306
const MSRouteIterator& getCurrentRouteEdge() const {
307
return myCurrEdge;
308
}
309
310
311
/** @brief Performs a rerouting using the given router
312
*
313
* Tries to find a new route between the current edge and the destination edge, first.
314
* Tries to replace the current route by the new one using replaceRoute.
315
*
316
* @param[in] t The time for which the route is computed
317
* @param[in] router The router to use
318
* @param[in] sink (optionally) a new destination edge
319
* @see replaceRoute
320
*/
321
bool reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr);
322
323
324
/** @brief Replaces the current route by the given edges
325
*
326
* It is possible that the new route is not accepted, if a) it does not
327
* contain the vehicle's current edge, or b) something fails on insertion
328
* into the routes container (see in-line comments).
329
*
330
* @param[in] edges The new list of edges to pass
331
* @param[in] onInit Whether the vehicle starts with this route
332
* @param[in] check Whether the route should be checked for validity
333
* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
334
* @return Whether the new route was accepted
335
*/
336
bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true,
337
std::string* msgReturn = nullptr);
338
339
/** @brief Replaces the current route by the given one
340
*
341
* It is possible that the new route is not accepted, if it does not
342
* contain the vehicle's current edge.
343
*
344
* @param[in] route The new route to pass
345
* @param[in] info Information regarding the replacement
346
* @param[in] addRouteStops Whether stops from the replacement route should be added
347
* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
348
* @return Whether the new route was accepted
349
*/
350
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true,
351
std::string* msgReturn = nullptr);
352
353
/** @brief Returns the vehicle's acceleration
354
*
355
* This default implementation returns always 0.
356
* @return The acceleration
357
*/
358
virtual double getAcceleration() const;
359
360
/** @brief Called when the vehicle is inserted into the network
361
*
362
* Sets optional information about departure time, informs the vehicle
363
* control about a further running vehicle.
364
*/
365
void onDepart();
366
367
/** @brief Returns this vehicle's real departure time
368
* @return This vehicle's real departure time
369
*/
370
inline SUMOTime getDeparture() const {
371
return myDeparture;
372
}
373
374
/** @brief Returns the depart delay */
375
SUMOTime getDepartDelay() const;
376
377
/** @brief Returns the estimated public transport stop (departure) delay in seconds
378
*/
379
virtual double getStopDelay() const {
380
/// @todo implement for meso
381
return -1;
382
}
383
384
/** @brief Returns the estimated public transport stop arrival delay in seconds
385
*/
386
virtual double getStopArrivalDelay() const {
387
/// @todo implement for meso
388
return INVALID_DOUBLE;
389
}
390
391
/// @brief return time (s) and distance to the next stop
392
virtual std::pair<double, double> estimateTimeToNextStop() const {
393
return std::make_pair(-1, -1);
394
}
395
396
/** @brief Returns this vehicle's real departure position
397
* @return This vehicle's real departure position
398
*/
399
inline double getDepartPos() const {
400
return myDepartPos;
401
}
402
403
/** @brief Returns this vehicle's desired arrivalPos for its current route
404
* (may change on reroute)
405
* @return This vehicle's real arrivalPos
406
*/
407
virtual double getArrivalPos() const {
408
return myArrivalPos;
409
}
410
411
virtual int getArrivalLane() const {
412
return myArrivalLane;
413
}
414
415
/** @brief Sets this vehicle's desired arrivalPos for its current route
416
*/
417
virtual void setArrivalPos(double arrivalPos) {
418
myArrivalPos = arrivalPos;
419
}
420
421
/** @brief Called when the vehicle is removed from the network.
422
*
423
* Moves along work reminders and
424
* informs all devices about quitting. Calls "leaveLane" then.
425
*
426
* @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
427
*/
428
virtual void onRemovalFromNet(const MSMoveReminder::Notification /*reason*/) {}
429
430
/** @brief Returns whether this vehicle has already departed
431
*/
432
inline bool hasDeparted() const {
433
return myDeparture != NOT_YET_DEPARTED;
434
}
435
436
/** @brief Returns whether this vehicle has already arived
437
* (by default this is true if the vehicle has reached its final edge)
438
*/
439
virtual bool hasArrived() const;
440
441
/// @brief return index of edge within route
442
int getRoutePosition() const;
443
444
/// @brief return the number of edges remaining in the route (include the current)
445
int getNumRemainingEdges() const;
446
447
int getArrivalIndex() const {
448
return myParameter->arrivalEdge;
449
}
450
451
/// @brief reset index of edge within route
452
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure);
453
454
/** @brief Returns the distance that was already driven by this vehicle
455
* @return the distance driven [m]
456
*/
457
double getOdometer() const;
458
459
/// @brief Manipulate the odometer
460
void addToOdometer(double value) {
461
myOdometer += value;
462
}
463
464
/** @brief Returns the number of new routes this vehicle got
465
* @return the number of new routes this vehicle got
466
*/
467
inline int getNumberReroutes() const {
468
return myNumberReroutes;
469
}
470
471
/// @brief Returns this vehicles impatience
472
double getImpatience() const;
473
474
/** @brief Returns the number of persons
475
* @return The number of passengers on-board
476
*/
477
int getPersonNumber() const;
478
479
/** @brief Returns the number of leaving persons
480
* @return The number of leaving passengers
481
*/
482
int getLeavingPersonNumber() const;
483
484
/** @brief Returns the list of persons
485
* @return The list of passengers on-board
486
*/
487
std::vector<std::string> getPersonIDList() const;
488
489
/** @brief Returns the number of containers
490
* @return The number of contaiers on-board
491
*/
492
int getContainerNumber() const;
493
494
495
/** @brief Returns this vehicle's devices
496
* @return This vehicle's devices
497
*/
498
inline const std::vector<MSVehicleDevice*>& getDevices() const {
499
return myDevices;
500
}
501
502
/// @brief whether the given transportable is allowed to board this vehicle
503
bool allowsBoarding(const MSTransportable* t) const;
504
505
/** @brief Adds a person or container to this vehicle
506
*
507
* @param[in] transportable The person/container to add
508
*/
509
virtual void addTransportable(MSTransportable* transportable);
510
511
/// @brief removes a person or container
512
void removeTransportable(MSTransportable* t);
513
514
/// @brief removes a person or containers mass
515
void removeTransportableMass(MSTransportable* t);
516
517
/// @brief retrieve riding persons
518
const std::vector<MSTransportable*>& getPersons() const;
519
520
/// @brief retrieve riding containers
521
const std::vector<MSTransportable*>& getContainers() const;
522
523
/// @brief returns whether the vehicle serves a public transport line that serves the given stop
524
bool isLineStop(double position) const;
525
526
/// @brief check wether the vehicle has jump at the given part of its route
527
bool hasJump(const MSRouteIterator& it) const;
528
529
/** @brief Validates the current or given route
530
* @param[out] msg Description why the route is not valid (if it is the case)
531
* @param[in] route The route to check (or 0 if the current route shall be checked)
532
* @return Whether the vehicle's current route is valid
533
*/
534
bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const;
535
536
bool hasValidRoute(std::string& msg, MSRouteIterator start, MSRouteIterator last, bool checkJumps) const;
537
538
/// @brief checks wether the vehicle can depart on the first edge
539
virtual bool hasValidRouteStart(std::string& msg);
540
541
/// @brief check for route validity at first insertion attempt
542
int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr);
543
544
/// @brief Checks whether the vehilce has the given MoveReminder
545
bool hasReminder(MSMoveReminder* rem) const;
546
547
/** @brief Adds a MoveReminder dynamically
548
*
549
* @param[in] rem the reminder to add
550
* @see MSMoveReminder
551
*/
552
void addReminder(MSMoveReminder* rem, double pos = 0);
553
554
/** @brief Removes a MoveReminder dynamically
555
*
556
* @param[in] rem the reminder to remove
557
* @see MSMoveReminder
558
*/
559
void removeReminder(MSMoveReminder* rem);
560
561
/** @brief "Activates" all current move reminder
562
*
563
* For all move reminder stored in "myMoveReminders", their method
564
* "MSMoveReminder::notifyEnter" is called.
565
*
566
* @param[in] reason The reason for changing the reminders' states
567
* @param[in] enteredLane The lane, which is entered (if applicable)
568
* @see MSMoveReminder
569
* @see MSMoveReminder::notifyEnter
570
* @see MSMoveReminder::Notification
571
*/
572
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
573
574
575
/** @brief Returns the vehicle's length
576
* @return vehicle's length
577
*/
578
inline double getLength() const {
579
return myType->getLength();
580
}
581
582
/* @brief Return whether this vehicle must be treated like a railway vehicle
583
* either due to its vClass or the vClass of it's edge */
584
bool isRail() const;
585
586
/** @brief Returns the vehicle's width
587
* @return vehicle's width
588
*/
589
inline double getWidth() const {
590
return myType->getWidth();
591
}
592
593
594
/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
595
* @return Speed limit factor
596
*/
597
inline double getChosenSpeedFactor() const {
598
return myChosenSpeedFactor;
599
}
600
601
inline double getDesiredMaxSpeed() const {
602
return myType->getDesiredMaxSpeed() * myChosenSpeedFactor;
603
}
604
605
/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
606
* @return Speed limit factor
607
*/
608
inline void setChosenSpeedFactor(const double factor) {
609
myChosenSpeedFactor = factor;
610
}
611
612
/// @brief Returns a device of the given type if it exists, nullptr otherwise
613
MSDevice* getDevice(const std::type_info& type) const;
614
615
616
/** @brief Replaces the current vehicle type by the one given
617
*
618
* If the currently used vehicle type is marked as being used by this vehicle
619
* only, it is deleted, first. The new, given type is then assigned to
620
* "myType".
621
* @param[in] type The new vehicle type
622
* @see MSBaseVehicle::myType
623
*/
624
virtual void replaceVehicleType(const MSVehicleType* type);
625
626
627
/** @brief Replaces the current vehicle type with a new one used by this vehicle only
628
*
629
* If the currently used vehicle type is already marked as being used by this vehicle
630
* only, no new type is created.
631
* @return The new modifiable vehicle type
632
* @see MSBaseVehicle::myType
633
*/
634
MSVehicleType& getSingularType();
635
636
/// @name state io
637
//@{
638
639
/// Saves the (common) state of a vehicle
640
virtual void saveState(OutputDevice& out);
641
642
//@}
643
644
virtual bool handleCollisionStop(MSStop& stop, const double distToStop);
645
646
/** @brief Returns whether the vehicle is at a stop
647
* @return Whether the vehicle has stopped
648
*/
649
bool isStopped() const;
650
651
/** @brief Returns whether the vehicle is parking
652
* @return whether the vehicle is parking
653
*/
654
bool isParking() const;
655
656
/** @brief Returns whether the vehicle is perform a jump
657
* @return whether the vehicle is starting to jump
658
*/
659
bool isJumping() const;
660
661
/** @brief Returns whether the logical state of the vehicle is reversed - for drawing
662
* @return whether the logical state of the vehicle is reversed
663
*/
664
inline bool isReversed() const {
665
return myAmReversed;
666
}
667
668
/** @brief Returns whether the vehicle is on a triggered stop
669
* @return whether the vehicle is on a triggered stop
670
*/
671
bool isStoppedTriggered() const;
672
673
/** @brief Returns whether the vehicle is on a parking stop
674
* @return whether the vehicle is on a parking stop
675
*/
676
bool isStoppedParking() const;
677
678
/** @brief return whether the given position is within range of the current stop
679
*/
680
bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const;
681
682
/** @brief Returns whether the vehicle has to stop somewhere
683
* @return Whether the vehicle has to stop somewhere
684
*/
685
bool hasStops() const {
686
return !myStops.empty();
687
}
688
689
/** @brief replace the current parking area stop with a new stop with merge duration
690
*/
691
bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg);
692
693
/** @brief get the upcoming parking area stop or nullptr
694
*/
695
MSParkingArea* getNextParkingArea();
696
697
/** @brief get the current parking area stop or nullptr */
698
MSParkingArea* getCurrentParkingArea();
699
700
/// @brief get the valid parking access rights (vehicle settings override vehicle type settings)
701
const std::vector<std::string>& getParkingBadges() const;
702
703
/// @brief departure position where the vehicle fits fully onto the edge (if possible)
704
double basePos(const MSEdge* edge) const;
705
706
/** @brief Adds a stop
707
*
708
* The stop is put into the sorted list.
709
* @param[in] stop The stop to add
710
* @return Whether the stop could be added
711
*/
712
bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
713
MSRouteIterator* searchStart = nullptr);
714
715
/** @brief Adds stops to the built vehicle
716
*
717
* This code needs to be separated from the MSBaseVehicle constructor
718
* since it is not allowed to call virtual functions from a constructor
719
*
720
* @param[in] ignoreStopErrors whether invalid stops trigger a warning only
721
*/
722
void addStops(const bool ignoreStopErrors, MSRouteIterator* searchStart = nullptr, bool addRouteStops = true);
723
724
/// @brief check whether all stop.edge MSRouteIterators are valid and in order
725
bool haveValidStopEdges(bool silent = false) const;
726
727
/// @brief return list of route indices for the remaining stops
728
std::vector<std::pair<int, double> > getStopIndices() const;
729
730
/**
731
* returns the list of stops not yet reached in the stop queue
732
* @return the list of upcoming stops
733
*/
734
inline const std::list<MSStop>& getStops() const {
735
return myStops;
736
}
737
738
inline const StopParVector& getPastStops() const {
739
return myPastStops;
740
}
741
742
/**
743
* returns the next imminent stop in the stop queue
744
* @return the upcoming stop
745
*/
746
const MSStop& getNextStop() const;
747
748
/**
749
* returns the next imminent stop in the stop queue
750
* @return the upcoming stop
751
*/
752
MSStop& getNextStopMutable();
753
754
/// @brief get remaining stop duration or 0 if the vehicle isn't stopped
755
SUMOTime getStopDuration() const;
756
757
/**
758
* returns the upcoming stop with the given index in the stop queue
759
* @return an upcoming stop
760
*/
761
MSStop& getStop(int nextStopIndex);
762
763
/// @brief return parameters for the next stop (SUMOVehicle Interface)
764
const SUMOVehicleParameter::Stop* getNextStopParameter() const;
765
766
/**
767
* schedule a new stop for the vehicle; each time a stop is reached, the vehicle
768
* will wait for the given duration before continuing on its route
769
* @param[in] stop Stop parameters
770
* @param[out] errorMsg returned error message
771
*/
772
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg);
773
774
/**
775
* resumes a vehicle from stopping
776
* @return true on success, the resuming fails if the vehicle wasn't parking in the first place
777
*/
778
virtual bool resumeFromStopping() = 0;
779
780
/// @brief mark vehicle as active
781
void unregisterWaiting();
782
783
/// @brief deletes the next stop at the given index if it exists
784
bool abortNextStop(int nextStopIndex = 0);
785
786
/**
787
* replace the next stop at the given index with the given stop parameters
788
* will wait for the given duration before continuing on its route
789
* The route between start other stops and destination will be kept unchanged and
790
* only the part around the replacement index will be adapted according to the new stop location
791
* @param[in] nextStopIndex The replacement index
792
* @param[in] stop Stop parameters
793
* @param[in] info The rerouting info
794
* @param[in] teleport Whether to cover the route to the replacement stop via teleporting
795
* @param[out] errorMsg returned error message
796
*/
797
bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
798
799
/**
800
* reroute between stops nextStopIndex - 1 and nextStopIndex (defaults to current position / final edge) if the respective stops do not exist
801
* @param[in] nextStopIndex The replacement index
802
* @param[in] info The rerouting info
803
* @param[in] teleport Whether to cover the route between stops via teleporting
804
* @param[out] errorMsg returned error message
805
*/
806
bool rerouteBetweenStops(int nextStopIndex, const std::string& info, bool teleport, std::string& errorMsg);
807
808
/**
809
* insert stop at the given index with the given stop parameters
810
* will wait for the given duration before continuing on its route
811
* The route will be adapted to pass the new stop edge but only from the previous stop (or start) to the new stop and only up to the next stop (or end).
812
* @param[in] nextStopIndex The replacement index
813
* @param[in] stop Stop parameters
814
* @param[in] info The rerouting info
815
* @param[in] teleport Whether to cover the route to the new stop via teleporting
816
* @param[out] errorMsg returned error message
817
*/
818
bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
819
820
821
/// @brief whether this vehicle is selected in the GUI
822
virtual bool isSelected() const {
823
return false;
824
}
825
826
/// @brief @return The index of the vehicle's associated RNG
827
int getRNGIndex() const;
828
829
/// @brief @return The vehicle's associated RNG
830
SumoRNG* getRNG() const;
831
832
inline NumericalID getNumericalID() const {
833
return myNumericalID;
834
}
835
836
/// @brief return vehicle-specific random number
837
long long int getRandomSeed() const {
838
return myRandomSeed;
839
}
840
841
const MSDevice_Transportable* getPersonDevice() const {
842
return myPersonDevice;
843
}
844
845
const MSDevice_Transportable* getContainerDevice() const {
846
return myContainerDevice;
847
}
848
849
/// @brief retrieve parameters for the energy consumption model
850
EnergyParams* getEmissionParameters() const;
851
852
/// @name Emission retrieval
853
//@{
854
855
/** @brief Returns emissions of the current state
856
* The value is always per 1s, so multiply by step length if necessary.
857
* @return The current emission
858
*/
859
template<PollutantsInterface::EmissionType ET>
860
double getEmissions() const {
861
if (isOnRoad() || isIdling()) {
862
return PollutantsInterface::compute(myType->getEmissionClass(), ET, getSpeed(), getAcceleration(), getSlope(), getEmissionParameters());
863
}
864
return 0.;
865
}
866
867
/** @brief Returns actual state of charge of battery (Wh)
868
* RICE_CHECK: This may be a misnomer, SOC is typically percentage of the maximum battery capacity.
869
* @return The actual battery state of charge
870
*/
871
double getStateOfCharge() const;
872
873
/** @brief Returns actual relative state of charge of battery (-)
874
* @return The actual relative battery state of charge, normalised to the maximum battery capacity.
875
*/
876
double getRelativeStateOfCharge() const;
877
878
/** @brief Returns the energy charged to the battery in the current time step (Wh)
879
* @return The energy charged to the battery in the current time step.
880
*/
881
double getChargedEnergy() const;
882
883
/** @brief Returns the maximum charge rate allowed by the battery in the current time step (W)
884
* @return The maximum charge rate in the current time step.
885
*/
886
double getMaxChargeRate() const;
887
888
/** @brief Returns actual current (A) of ElecHybrid device
889
* RICE_CHECK: Is this the current consumed from the overhead wire or the current driving the powertrain of the vehicle?
890
* RICE_REV_JS: It is the current drawn from the overhead wire (value if the vehicle is not connected to overhead wire?)
891
* @return The current of ElecHybrid device
892
*/
893
double getElecHybridCurrent() const;
894
895
/** @brief Returns noise emissions of the current state
896
* @return The noise produced
897
*/
898
double getHarmonoise_NoiseEmissions() const;
899
//@}
900
901
/** @class Influencer
902
* @brief Changes the wished vehicle speed / lanes
903
*
904
* The class is used for passing velocities or velocity profiles obtained via TraCI to the vehicle.
905
* The speed adaptation is controlled by the stored speedTimeLine
906
* Additionally, the variables myConsiderSafeVelocity, myConsiderMaxAcceleration, and myConsiderMaxDeceleration
907
* control whether the safe velocity, the maximum acceleration, and the maximum deceleration
908
* have to be regarded.
909
*
910
* Furthermore this class is used to affect lane changing decisions according to
911
* LaneChangeMode and any given laneTimeLine
912
*/
913
class BaseInfluencer {
914
public:
915
/// @brief Constructor
916
BaseInfluencer();
917
918
/// @brief Destructor
919
virtual ~BaseInfluencer() {}
920
921
/// @brief Static initalization
922
static void init();
923
/// @brief Static cleanup
924
static void cleanup();
925
926
927
/// @brief return the current routing mode
928
double getExtraImpatience() const {
929
return myExtraImpatience;
930
}
931
932
/** @brief Sets routing behavior
933
* @param[in] value an enum value controlling the different modes
934
*/
935
void setExtraImpatience(double value) {
936
myExtraImpatience = value;
937
}
938
939
protected:
940
/// @brief dynamic impatience offset
941
double myExtraImpatience = 0;
942
943
};
944
945
946
947
/** @brief Returns the velocity/lane influencer
948
*
949
* If no influencer was existing before, one is built, first
950
* @return Reference to this vehicle's speed influencer
951
*/
952
virtual BaseInfluencer& getBaseInfluencer() = 0;
953
954
virtual const BaseInfluencer* getBaseInfluencer() const = 0;
955
956
virtual bool hasInfluencer() const = 0;
957
958
/// @brief return routing mode (configures router choice but also handling of transient permission changes)
959
int getRoutingMode() const {
960
return myRoutingMode;
961
}
962
963
/** @brief Sets routing behavior
964
* @param[in] value an enum value controlling the different modes
965
*/
966
void setRoutingMode(int value) {
967
myRoutingMode = value;
968
}
969
970
971
SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT() const;
972
973
/** @brief Returns the vehicle's internal edge travel times/efforts container
974
*
975
* If the vehicle does not have such a container, it is built.
976
* @return The vehicle's knowledge about edge weights
977
*/
978
const MSEdgeWeightsStorage& getWeightsStorage() const;
979
MSEdgeWeightsStorage& getWeightsStorage();
980
981
/** @brief Returns the leader of the vehicle looking for a fixed distance.
982
*
983
* If the distance is not given it is calculated from the brake gap.
984
* The gap returned does not include the minGap.
985
* @param dist up to which distance to look at least for a leader
986
* @param considerCrossingFoes Whether vehicles on crossing foe links should be considered
987
* @return The leading vehicle together with the gap; (0, -1) if no leader was found.
988
*/
989
virtual std::pair<const MSVehicle* const, double> getLeader(double dist = 0, bool considerCrossingFoes = true) const {
990
UNUSED_PARAMETER(dist);
991
UNUSED_PARAMETER(considerCrossingFoes);
992
WRITE_WARNING(TL("getLeader not yet implemented for meso"));
993
return std::make_pair(nullptr, -1);
994
}
995
996
/** @brief Returns the follower of the vehicle looking for a fixed distance.
997
*
998
* If the distance is not given it is set to the value of MSCFModel::brakeGap(2*roadSpeed, 4.5, 0)
999
* The gap returned does not include the minGap.
1000
* If there are multiple followers, the one that maximizes the term (getSecureGap - gap) is returned.
1001
* @param dist up to which distance to look at least for a leader
1002
* @return The leading vehicle together with the gap; (0, -1) if no leader was found.
1003
*/
1004
virtual std::pair<const MSVehicle* const, double> getFollower(double dist = 0) const {
1005
UNUSED_PARAMETER(dist);
1006
WRITE_WARNING(TL("getFollower not yet implemented for meso"));
1007
return std::make_pair(nullptr, -1);
1008
}
1009
1010
/** @brief (Re-)Calculates the arrival position and lane from the vehicle parameters
1011
*/
1012
void calculateArrivalParams(bool onInit);
1013
1014
/// @brief apply departEdge and arrivalEdge attributes
1015
void setDepartAndArrivalEdge();
1016
1017
int getDepartEdge() const;
1018
1019
int getInsertionChecks() const;
1020
1021
/// @brief interpret stop lane on opposite side of the road
1022
static MSLane* interpretOppositeStop(SUMOVehicleParameter::Stop& stop);
1023
1024
/// @name state io
1025
//@{
1026
void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local);
1027
SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const;
1028
void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local);
1029
SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const;
1030
1031
/// @brief score only needed when running with gui
1032
void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score);
1033
void resetParkingAreaScores();
1034
void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score);
1035
void resetChargingStationScores();
1036
1037
int getNumberParkingReroutes() const {
1038
return myNumberParkingReroutes;
1039
}
1040
void setNumberParkingReroutes(int value) {
1041
myNumberParkingReroutes = value;
1042
}
1043
1044
const StoppingPlaceMemory* getParkingMemory() const {
1045
return myParkingMemory;
1046
}
1047
1048
const StoppingPlaceMemory* getChargingMemory() const {
1049
return myChargingMemory;
1050
}
1051
//@}
1052
1053
struct StopEdgeInfo {
1054
1055
StopEdgeInfo(const MSEdge* _edge, double _priority, SUMOTime _arrival, double _pos, bool _isSink = false):
1056
edge(_edge), pos(_pos),
1057
priority(_priority),
1058
arrival(_arrival),
1059
isSink(_isSink) {}
1060
1061
const MSEdge* edge;
1062
double pos;
1063
double priority;
1064
SUMOTime arrival;
1065
bool isSink;
1066
const SUMOVehicleParameter::Stop* stopPar = nullptr;
1067
/// @brief values set during routing and used during optimization
1068
int routeIndex = -1;
1069
bool skipped = false;
1070
bool backtracked = false;
1071
SUMOTime delay = 0;
1072
/// @brief optional info about stopping place
1073
std::pair<std::string, SumoXMLTag> nameTag;
1074
/// @brief set when replacing stop with an alternative
1075
const MSEdge* origEdge = nullptr;
1076
1077
bool operator==(const StopEdgeInfo& o) const {
1078
return edge == o.edge;
1079
}
1080
bool operator!=(const StopEdgeInfo& o) const {
1081
return !(*this == o);
1082
}
1083
};
1084
1085
protected:
1086
/// @brief reset rail signal approach information
1087
virtual void resetApproachOnReroute() {};
1088
1089
/** @brief Returns the list of still pending stop edges
1090
* also returns the first and last stop position
1091
*/
1092
std::vector<StopEdgeInfo> getStopEdges(double& firstPos, double& lastPos, std::set<int>& jumps) const;
1093
1094
static double addStopPriority(double p1, double p2);
1095
1096
/// @brief replace stop with a same-name alternative that is on the route and return success
1097
bool replaceWithAlternative(std::list<MSStop>::iterator iter, const MSRouteIterator searchStart, const MSRouteIterator end);
1098
1099
protected:
1100
/// @brief This vehicle's parameter.
1101
const SUMOVehicleParameter* myParameter;
1102
1103
/// @brief This vehicle's route.
1104
ConstMSRoutePtr myRoute;
1105
1106
/// @brief This vehicle's type.
1107
const MSVehicleType* myType;
1108
1109
/// @brief Iterator to current route-edge
1110
MSRouteIterator myCurrEdge;
1111
1112
/// @brief A precomputed factor by which the driver wants to be faster than the speed limit
1113
double myChosenSpeedFactor;
1114
1115
/// @brief The vehicle's list of stops
1116
std::list<MSStop> myStops;
1117
1118
/// @brief The list of stops that the vehicle has already reached
1119
StopParVector myPastStops;
1120
1121
/// @name Move reminder structures
1122
/// @{
1123
1124
/// @brief Definition of a move reminder container
1125
// The double value holds the relative position offset, i.e.,
1126
// offset + vehicle-position - moveReminder-position = distance,
1127
// i.e. the offset is counted up when the vehicle continues to a
1128
// succeeding lane.
1129
typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
1130
1131
/// @brief Currently relevant move reminders
1132
MoveReminderCont myMoveReminders;
1133
/// @}
1134
1135
/// @brief The devices this vehicle has
1136
std::vector<MSVehicleDevice*> myDevices;
1137
1138
/// @brief The passengers this vehicle may have
1139
MSDevice_Transportable* myPersonDevice;
1140
1141
/// @brief The containers this vehicle may have
1142
MSDevice_Transportable* myContainerDevice;
1143
1144
/// @brief The emission parameters this vehicle may have
1145
mutable EnergyParams* myEnergyParams;
1146
1147
/// @brief The real departure time
1148
SUMOTime myDeparture;
1149
1150
/// @brief The real depart position
1151
double myDepartPos;
1152
1153
/// @brief The position on the destination lane where the vehicle stops
1154
double myArrivalPos;
1155
1156
/// @brief The destination lane where the vehicle stops
1157
int myArrivalLane;
1158
1159
/// @brief The number of reroutings
1160
int myNumberReroutes;
1161
1162
/// @brief The offset when adding route stops with 'until' on route replacement
1163
SUMOTime myStopUntilOffset;
1164
1165
/// @brief A simple odometer to keep track of the length of the route already driven
1166
double myOdometer;
1167
1168
/// @brief status of the current vehicle route
1169
int myRouteValidity;
1170
1171
/// memory for parking search
1172
StoppingPlaceMemory* myParkingMemory = nullptr;
1173
StoppingPlaceMemory* myChargingMemory = nullptr;
1174
int myNumberParkingReroutes = 0;
1175
1176
/// @brief Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
1177
bool myAmRegisteredAsWaiting = false;
1178
1179
/* @brief magic value for undeparted vehicles
1180
* @note: in previous versions this was -1
1181
*/
1182
static const SUMOTime NOT_YET_DEPARTED;
1183
1184
static std::vector<MSTransportable*> myEmptyTransportableVector;
1185
1186
/* @brief The logical 'reversed' state of the vehicle - intended to be used by drawing functions
1187
* @note: only set by vClass rail reversing at the moment
1188
*/
1189
bool myAmReversed = false;
1190
1191
///@brief routing mode (see TraCIConstants.h)
1192
int myRoutingMode;
1193
1194
private:
1195
const NumericalID myNumericalID;
1196
1197
const long long int myRandomSeed;
1198
1199
/* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1200
* @note member is initialized on first access */
1201
mutable MSEdgeWeightsStorage* myEdgeWeights;
1202
1203
MSEdgeWeightsStorage& _getWeightsStorage() const;
1204
1205
static NumericalID myCurrentNumericalIndex;
1206
1207
/// @brief init model parameters from generic params
1208
void initTransientModelParams();
1209
1210
/// @brief reconstruct flow id from vehicle id
1211
std::string getFlowID() const;
1212
1213
/// @brief remove route at the end of the simulation
1214
void checkRouteRemoval();
1215
1216
/// @brief helper function
1217
bool insertJump(int nextStopIndex, MSRouteIterator itStart, std::string& errorMsg);
1218
1219
/// @brief patch stop.pars.index to record the number of skipped candidate edges before stop.edge (in a looped route)
1220
void setSkips(MSStop& stop, int prevActiveStops);
1221
1222
/// @brief remove outdated driveways on reroute
1223
SUMOTime activateRemindersOnReroute(SUMOTime currentTime);
1224
1225
private:
1226
/// invalidated assignment operator
1227
MSBaseVehicle& operator=(const MSBaseVehicle& s) = delete;
1228
1229
#ifdef _DEBUG
1230
public:
1231
static void initMoveReminderOutput(const OptionsCont& oc);
1232
1233
protected:
1234
/// @brief optionally generate movereminder-output for this vehicle
1235
void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
1236
1237
/// @brief whether this vehicle shall trace its moveReminders
1238
const bool myTraceMoveReminders;
1239
private:
1240
/// @brief vehicles which shall trace their move reminders
1241
static std::set<std::string> myShallTraceMoveReminders;
1242
#endif
1243
1244
1245
};
1246
1247