Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSBaseVehicle.h
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2010-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 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 Returns the maximum speed (the minimum of desired and technical maximum speed)
177
* @return The vehicle's maximum speed
178
*/
179
double getMaxSpeed() const;
180
181
/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at
182
*
183
* If the rest of the route (counted from the current edge) has less than nSuccs edges,
184
* 0 is returned.
185
* @param[in] nSuccs The number of edge to look forward
186
* @return The nSuccs'th following edge in the vehicle's route
187
*/
188
const MSEdge* succEdge(int nSuccs) const;
189
190
/** @brief Returns the edge the vehicle is currently at
191
*
192
* @return The current edge in the vehicle's route
193
*/
194
const MSEdge* getEdge() const;
195
196
/** @brief Returns the edge the vehicle is currently at (possibly an
197
* internal edge)
198
*/
199
virtual const MSEdge* getCurrentEdge() const {
200
return getEdge();
201
}
202
203
/// @brief returns the numerical ids of edges to travel
204
const std::set<SUMOTrafficObject::NumericalID> getUpcomingEdgeIDs() const;
205
206
/** @brief Returns whether the vehicle stops at the given stopping place */
207
bool stopsAt(MSStoppingPlace* stop) const;
208
209
/** @brief Returns whether the vehicle stops at the given edge */
210
bool stopsAtEdge(const MSEdge* edge) const;
211
212
/// @brief returns the next edge (possibly an internal edge)
213
virtual const MSEdge* getNextEdgePtr() const {
214
return nullptr;
215
}
216
217
/** @brief Returns the information whether the vehicle is on a road (is simulated)
218
* @return Whether the vehicle is simulated
219
*/
220
virtual bool isOnRoad() const {
221
return true;
222
}
223
224
/** @brief Returns the information whether the vehicle is fully controlled
225
* via TraCI
226
* @return Whether the vehicle is remote-controlled
227
*/
228
virtual bool isRemoteControlled() const {
229
return false;
230
}
231
232
virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
233
UNUSED_PARAMETER(lookBack);
234
return false;
235
}
236
237
/** @brief Returns the information whether the front of the vehhicle is on the given lane
238
* @return Whether the vehicle's front is on that lane
239
*/
240
virtual bool isFrontOnLane(const MSLane*) const {
241
return true;
242
}
243
244
/** @brief Get the vehicle's lateral position on the lane
245
* @return The lateral position of the vehicle (in m relative to the
246
* centerline of the lane)
247
*/
248
virtual double getLateralPositionOnLane() const {
249
return 0;
250
}
251
252
/** @brief Get the vehicle's lateral position on the edge of the given lane
253
* (or its current edge if lane == 0)
254
* @return The lateral position of the vehicle (in m distance between right
255
* side of vehicle and ride side of edge
256
*/
257
virtual double getRightSideOnEdge(const MSLane* lane = 0) const {
258
UNUSED_PARAMETER(lane);
259
return 0;
260
}
261
262
/** @brief Returns the starting point for reroutes (usually the current edge)
263
*
264
* This differs from *myCurrEdge only if the vehicle is on an internal edge
265
* @return The rerouting start point
266
*/
267
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const {
268
return myCurrEdge;
269
}
270
271
/** @brief Returns the end point for reroutes (usually the last edge of the route)
272
*
273
* @return The rerouting end point
274
*/
275
virtual const MSEdge* getRerouteDestination() const {
276
return myRoute->getLastEdge();
277
}
278
279
/** @brief Returns the time loss in seconds
280
*/
281
virtual double getTimeLossSeconds() const {
282
// better timeLoss for meso?
283
return 0;
284
}
285
286
/** @brief Returns the number of seconds waited (speed was lesser than 0.1m/s)
287
*
288
* The value is reset if the vehicle moves faster than 0.1m/s
289
* Intentional stopping does not count towards this time.
290
* @return The time the vehicle is standing
291
*/
292
double getWaitingSeconds() const {
293
return STEPS2TIME(getWaitingTime());
294
}
295
296
297
298
/** @brief Returns an iterator pointing to the current edge in this vehicles route
299
* @return The current route pointer
300
*/
301
const MSRouteIterator& getCurrentRouteEdge() const {
302
return myCurrEdge;
303
}
304
305
306
/** @brief Performs a rerouting using the given router
307
*
308
* Tries to find a new route between the current edge and the destination edge, first.
309
* Tries to replace the current route by the new one using replaceRoute.
310
*
311
* @param[in] t The time for which the route is computed
312
* @param[in] router The router to use
313
* @param[in] sink (optionally) a new destination edge
314
* @see replaceRoute
315
*/
316
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);
317
318
319
/** @brief Replaces the current route by the given edges
320
*
321
* It is possible that the new route is not accepted, if a) it does not
322
* contain the vehicle's current edge, or b) something fails on insertion
323
* into the routes container (see in-line comments).
324
*
325
* @param[in] edges The new list of edges to pass
326
* @param[in] onInit Whether the vehicle starts with this route
327
* @param[in] check Whether the route should be checked for validity
328
* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
329
* @return Whether the new route was accepted
330
*/
331
bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true,
332
std::string* msgReturn = nullptr);
333
334
/** @brief Replaces the current route by the given one
335
*
336
* It is possible that the new route is not accepted, if it does not
337
* contain the vehicle's current edge.
338
*
339
* @param[in] route The new route to pass
340
* @param[in] info Information regarding the replacement
341
* @param[in] addRouteStops Whether stops from the replacement route should be added
342
* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
343
* @return Whether the new route was accepted
344
*/
345
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true,
346
std::string* msgReturn = nullptr);
347
348
/** @brief Returns the vehicle's acceleration
349
*
350
* This default implementation returns always 0.
351
* @return The acceleration
352
*/
353
virtual double getAcceleration() const;
354
355
/** @brief Called when the vehicle is inserted into the network
356
*
357
* Sets optional information about departure time, informs the vehicle
358
* control about a further running vehicle.
359
*/
360
void onDepart();
361
362
/** @brief Returns this vehicle's real departure time
363
* @return This vehicle's real departure time
364
*/
365
inline SUMOTime getDeparture() const {
366
return myDeparture;
367
}
368
369
/** @brief Returns the depart delay */
370
SUMOTime getDepartDelay() const;
371
372
/** @brief Returns the estimated public transport stop (departure) delay in seconds
373
*/
374
virtual double getStopDelay() const {
375
/// @todo implement for meso
376
return -1;
377
}
378
379
/** @brief Returns the estimated public transport stop arrival delay in seconds
380
*/
381
virtual double getStopArrivalDelay() const {
382
/// @todo implement for meso
383
return INVALID_DOUBLE;
384
}
385
386
/// @brief return time (s) and distance to the next stop
387
virtual std::pair<double, double> estimateTimeToNextStop() const {
388
return std::make_pair(-1, -1);
389
}
390
391
/** @brief Returns this vehicle's real departure position
392
* @return This vehicle's real departure position
393
*/
394
inline double getDepartPos() const {
395
return myDepartPos;
396
}
397
398
/** @brief Returns this vehicle's desired arrivalPos for its current route
399
* (may change on reroute)
400
* @return This vehicle's real arrivalPos
401
*/
402
virtual double getArrivalPos() const {
403
return myArrivalPos;
404
}
405
406
virtual int getArrivalLane() const {
407
return myArrivalLane;
408
}
409
410
/** @brief Sets this vehicle's desired arrivalPos for its current route
411
*/
412
virtual void setArrivalPos(double arrivalPos) {
413
myArrivalPos = arrivalPos;
414
}
415
416
/** @brief Called when the vehicle is removed from the network.
417
*
418
* Moves along work reminders and
419
* informs all devices about quitting. Calls "leaveLane" then.
420
*
421
* @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
422
*/
423
virtual void onRemovalFromNet(const MSMoveReminder::Notification /*reason*/) {}
424
425
/** @brief Returns whether this vehicle has already departed
426
*/
427
inline bool hasDeparted() const {
428
return myDeparture != NOT_YET_DEPARTED;
429
}
430
431
/** @brief Returns whether this vehicle has already arived
432
* (by default this is true if the vehicle has reached its final edge)
433
*/
434
virtual bool hasArrived() const;
435
436
/// @brief return index of edge within route
437
int getRoutePosition() const;
438
439
/// @brief return the number of edges remaining in the route (include the current)
440
int getNumRemainingEdges() const;
441
442
int getArrivalIndex() const {
443
return myParameter->arrivalEdge;
444
}
445
446
/// @brief reset index of edge within route
447
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure);
448
449
/** @brief Returns the distance that was already driven by this vehicle
450
* @return the distance driven [m]
451
*/
452
double getOdometer() const;
453
454
/// @brief Manipulate the odometer
455
void addToOdometer(double value) {
456
myOdometer += value;
457
}
458
459
/** @brief Returns the number of new routes this vehicle got
460
* @return the number of new routes this vehicle got
461
*/
462
inline int getNumberReroutes() const {
463
return myNumberReroutes;
464
}
465
466
/// @brief Returns this vehicles impatience
467
double getImpatience() const;
468
469
/** @brief Returns the number of persons
470
* @return The number of passengers on-board
471
*/
472
int getPersonNumber() const;
473
474
/** @brief Returns the number of leaving persons
475
* @return The number of leaving passengers
476
*/
477
int getLeavingPersonNumber() const;
478
479
/** @brief Returns the list of persons
480
* @return The list of passengers on-board
481
*/
482
std::vector<std::string> getPersonIDList() const;
483
484
/** @brief Returns the number of containers
485
* @return The number of contaiers on-board
486
*/
487
int getContainerNumber() const;
488
489
490
/** @brief Returns this vehicle's devices
491
* @return This vehicle's devices
492
*/
493
inline const std::vector<MSVehicleDevice*>& getDevices() const {
494
return myDevices;
495
}
496
497
/// @brief whether the given transportable is allowed to board this vehicle
498
bool allowsBoarding(const MSTransportable* t) const;
499
500
/** @brief Adds a person or container to this vehicle
501
*
502
* @param[in] transportable The person/container to add
503
*/
504
virtual void addTransportable(MSTransportable* transportable);
505
506
/// @brief removes a person or container
507
void removeTransportable(MSTransportable* t);
508
509
/// @brief removes a person or containers mass
510
void removeTransportableMass(MSTransportable* t);
511
512
/// @brief retrieve riding persons
513
const std::vector<MSTransportable*>& getPersons() const;
514
515
/// @brief retrieve riding containers
516
const std::vector<MSTransportable*>& getContainers() const;
517
518
/// @brief returns whether the vehicle serves a public transport line that serves the given stop
519
bool isLineStop(double position) const;
520
521
/// @brief check wether the vehicle has jump at the given part of its route
522
bool hasJump(const MSRouteIterator& it) const;
523
524
/** @brief Validates the current or given route
525
* @param[out] msg Description why the route is not valid (if it is the case)
526
* @param[in] route The route to check (or 0 if the current route shall be checked)
527
* @return Whether the vehicle's current route is valid
528
*/
529
bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const;
530
531
bool hasValidRoute(std::string& msg, MSRouteIterator start, MSRouteIterator last, bool checkJumps) const;
532
533
/// @brief checks wether the vehicle can depart on the first edge
534
virtual bool hasValidRouteStart(std::string& msg);
535
536
/// @brief check for route validity at first insertion attempt
537
int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr);
538
539
/// @brief Checks whether the vehilce has the given MoveReminder
540
bool hasReminder(MSMoveReminder* rem) const;
541
542
/** @brief Adds a MoveReminder dynamically
543
*
544
* @param[in] rem the reminder to add
545
* @see MSMoveReminder
546
*/
547
void addReminder(MSMoveReminder* rem, double pos = 0);
548
549
/** @brief Removes a MoveReminder dynamically
550
*
551
* @param[in] rem the reminder to remove
552
* @see MSMoveReminder
553
*/
554
void removeReminder(MSMoveReminder* rem);
555
556
/** @brief "Activates" all current move reminder
557
*
558
* For all move reminder stored in "myMoveReminders", their method
559
* "MSMoveReminder::notifyEnter" is called.
560
*
561
* @param[in] reason The reason for changing the reminders' states
562
* @param[in] enteredLane The lane, which is entered (if applicable)
563
* @see MSMoveReminder
564
* @see MSMoveReminder::notifyEnter
565
* @see MSMoveReminder::Notification
566
*/
567
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
568
569
570
/** @brief Returns the vehicle's length
571
* @return vehicle's length
572
*/
573
inline double getLength() const {
574
return myType->getLength();
575
}
576
577
/* @brief Return whether this vehicle must be treated like a railway vehicle
578
* either due to its vClass or the vClass of it's edge */
579
bool isRail() const;
580
581
/** @brief Returns the vehicle's width
582
* @return vehicle's width
583
*/
584
inline double getWidth() const {
585
return myType->getWidth();
586
}
587
588
589
/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
590
* @return Speed limit factor
591
*/
592
inline double getChosenSpeedFactor() const {
593
return myChosenSpeedFactor;
594
}
595
596
inline double getDesiredMaxSpeed() const {
597
return myType->getDesiredMaxSpeed() * myChosenSpeedFactor;
598
}
599
600
/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
601
* @return Speed limit factor
602
*/
603
inline void setChosenSpeedFactor(const double factor) {
604
myChosenSpeedFactor = factor;
605
}
606
607
/// @brief Returns a device of the given type if it exists, nullptr otherwise
608
MSDevice* getDevice(const std::type_info& type) const;
609
610
611
/** @brief Replaces the current vehicle type by the one given
612
*
613
* If the currently used vehicle type is marked as being used by this vehicle
614
* only, it is deleted, first. The new, given type is then assigned to
615
* "myType".
616
* @param[in] type The new vehicle type
617
* @see MSBaseVehicle::myType
618
*/
619
virtual void replaceVehicleType(const MSVehicleType* type);
620
621
622
/** @brief Replaces the current vehicle type with a new one used by this vehicle only
623
*
624
* If the currently used vehicle type is already marked as being used by this vehicle
625
* only, no new type is created.
626
* @return The new modifiable vehicle type
627
* @see MSBaseVehicle::myType
628
*/
629
MSVehicleType& getSingularType();
630
631
/// @name state io
632
//@{
633
634
/// Saves the (common) state of a vehicle
635
virtual void saveState(OutputDevice& out);
636
637
//@}
638
639
virtual bool handleCollisionStop(MSStop& stop, const double distToStop);
640
641
/** @brief Returns whether the vehicle is at a stop
642
* @return Whether the vehicle has stopped
643
*/
644
bool isStopped() const;
645
646
/** @brief Returns whether the vehicle is parking
647
* @return whether the vehicle is parking
648
*/
649
bool isParking() const;
650
651
/** @brief Returns whether the vehicle is perform a jump
652
* @return whether the vehicle is starting to jump
653
*/
654
bool isJumping() const;
655
656
/** @brief Returns whether the logical state of the vehicle is reversed - for drawing
657
* @return whether the logical state of the vehicle is reversed
658
*/
659
inline bool isReversed() const {
660
return myAmReversed;
661
}
662
663
/** @brief Returns whether the vehicle is on a triggered stop
664
* @return whether the vehicle is on a triggered stop
665
*/
666
bool isStoppedTriggered() const;
667
668
/** @brief Returns whether the vehicle is on a parking stop
669
* @return whether the vehicle is on a parking stop
670
*/
671
bool isStoppedParking() const;
672
673
/** @brief return whether the given position is within range of the current stop
674
*/
675
bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const;
676
677
/** @brief Returns whether the vehicle has to stop somewhere
678
* @return Whether the vehicle has to stop somewhere
679
*/
680
bool hasStops() const {
681
return !myStops.empty();
682
}
683
684
/** @brief replace the current parking area stop with a new stop with merge duration
685
*/
686
bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg);
687
688
/** @brief get the upcoming parking area stop or nullptr
689
*/
690
MSParkingArea* getNextParkingArea();
691
692
/** @brief get the current parking area stop or nullptr */
693
MSParkingArea* getCurrentParkingArea();
694
695
/// @brief get the valid parking access rights (vehicle settings override vehicle type settings)
696
const std::vector<std::string>& getParkingBadges() const;
697
698
/// @brief departure position where the vehicle fits fully onto the edge (if possible)
699
double basePos(const MSEdge* edge) const;
700
701
/** @brief Adds a stop
702
*
703
* The stop is put into the sorted list.
704
* @param[in] stop The stop to add
705
* @return Whether the stop could be added
706
*/
707
bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
708
MSRouteIterator* searchStart = nullptr);
709
710
/** @brief Adds stops to the built vehicle
711
*
712
* This code needs to be separated from the MSBaseVehicle constructor
713
* since it is not allowed to call virtual functions from a constructor
714
*
715
* @param[in] ignoreStopErrors whether invalid stops trigger a warning only
716
*/
717
void addStops(const bool ignoreStopErrors, MSRouteIterator* searchStart = nullptr, bool addRouteStops = true);
718
719
/// @brief check whether all stop.edge MSRouteIterators are valid and in order
720
bool haveValidStopEdges(bool silent = false) const;
721
722
/// @brief return list of route indices for the remaining stops
723
std::vector<std::pair<int, double> > getStopIndices() const;
724
725
/**
726
* returns the list of stops not yet reached in the stop queue
727
* @return the list of upcoming stops
728
*/
729
inline const std::list<MSStop>& getStops() const {
730
return myStops;
731
}
732
733
inline const StopParVector& getPastStops() const {
734
return myPastStops;
735
}
736
737
/**
738
* returns the next imminent stop in the stop queue
739
* @return the upcoming stop
740
*/
741
const MSStop& getNextStop() const;
742
743
/**
744
* returns the next imminent stop in the stop queue
745
* @return the upcoming stop
746
*/
747
MSStop& getNextStopMutable();
748
749
/// @brief get remaining stop duration or 0 if the vehicle isn't stopped
750
SUMOTime getStopDuration() const;
751
752
/**
753
* returns the upcoming stop with the given index in the stop queue
754
* @return an upcoming stop
755
*/
756
MSStop& getStop(int nextStopIndex);
757
758
/// @brief return parameters for the next stop (SUMOVehicle Interface)
759
const SUMOVehicleParameter::Stop* getNextStopParameter() const;
760
761
/**
762
* schedule a new stop for the vehicle; each time a stop is reached, the vehicle
763
* will wait for the given duration before continuing on its route
764
* @param[in] stop Stop parameters
765
* @param[out] errorMsg returned error message
766
*/
767
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg);
768
769
/**
770
* resumes a vehicle from stopping
771
* @return true on success, the resuming fails if the vehicle wasn't parking in the first place
772
*/
773
virtual bool resumeFromStopping() = 0;
774
775
/// @brief mark vehicle as active
776
void unregisterWaiting();
777
778
/// @brief deletes the next stop at the given index if it exists
779
bool abortNextStop(int nextStopIndex = 0);
780
781
/**
782
* replace the next stop at the given index with the given stop parameters
783
* will wait for the given duration before continuing on its route
784
* The route between start other stops and destination will be kept unchanged and
785
* only the part around the replacement index will be adapted according to the new stop location
786
* @param[in] nextStopIndex The replacement index
787
* @param[in] stop Stop parameters
788
* @param[in] info The rerouting info
789
* @param[in] teleport Whether to cover the route to the replacement stop via teleporting
790
* @param[out] errorMsg returned error message
791
*/
792
bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
793
794
/**
795
* reroute between stops nextStopIndex - 1 and nextStopIndex (defaults to current position / final edge) if the respective stops do not exist
796
* @param[in] nextStopIndex The replacement index
797
* @param[in] info The rerouting info
798
* @param[in] teleport Whether to cover the route between stops via teleporting
799
* @param[out] errorMsg returned error message
800
*/
801
bool rerouteBetweenStops(int nextStopIndex, const std::string& info, bool teleport, std::string& errorMsg);
802
803
/**
804
* insert stop at the given index with the given stop parameters
805
* will wait for the given duration before continuing on its route
806
* 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).
807
* @param[in] nextStopIndex The replacement index
808
* @param[in] stop Stop parameters
809
* @param[in] info The rerouting info
810
* @param[in] teleport Whether to cover the route to the new stop via teleporting
811
* @param[out] errorMsg returned error message
812
*/
813
bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
814
815
816
/// @brief whether this vehicle is selected in the GUI
817
virtual bool isSelected() const {
818
return false;
819
}
820
821
/// @brief @return The index of the vehicle's associated RNG
822
int getRNGIndex() const;
823
824
/// @brief @return The vehicle's associated RNG
825
SumoRNG* getRNG() const;
826
827
inline NumericalID getNumericalID() const {
828
return myNumericalID;
829
}
830
831
/// @brief return vehicle-specific random number
832
long long int getRandomSeed() const {
833
return myRandomSeed;
834
}
835
836
const MSDevice_Transportable* getPersonDevice() const {
837
return myPersonDevice;
838
}
839
840
const MSDevice_Transportable* getContainerDevice() const {
841
return myContainerDevice;
842
}
843
844
/// @brief retrieve parameters for the energy consumption model
845
inline EnergyParams* getEmissionParameters() const {
846
if (myEnergyParams == nullptr) {
847
myEnergyParams = new EnergyParams(getVehicleType().getEmissionParameters());
848
}
849
return myEnergyParams;
850
}
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