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