Line data Source code
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 622631165 : bool isVehicle() const {
100 622631165 : 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 64115602 : inline const MSRoute& getRoute() const {
140 64115602 : return *myRoute;
141 : }
142 :
143 : /** @brief Returns the current route
144 : * @return The route the vehicle uses
145 : */
146 1030100 : inline ConstMSRoutePtr getRoutePtr() const {
147 1030100 : return myRoute;
148 : }
149 :
150 : /** @brief Returns the vehicle's type definition
151 : * @return The vehicle's type definition
152 : */
153 50774569268 : inline const MSVehicleType& getVehicleType() const {
154 50774569268 : return *myType;
155 : }
156 :
157 : /** @brief Returns the vehicle's type parameter
158 : * @return The vehicle's type parameter
159 : */
160 22929916 : inline const SUMOVTypeParameter& getVTypeParameter() const {
161 22929916 : return myType->getParameter();
162 : }
163 :
164 : /** @brief Returns the vehicle's access class
165 : * @return The vehicle's access class
166 : */
167 10785747812 : inline SUMOVehicleClass getVClass() const {
168 10785747812 : 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 138024 : virtual const MSEdge* getCurrentEdge() const {
200 138024 : 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 0 : virtual const MSEdge* getNextEdgePtr() const {
214 0 : 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 0 : virtual bool isOnRoad() const {
221 0 : 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 54160 : virtual bool isRemoteControlled() const {
229 54160 : return false;
230 : }
231 :
232 227 : virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
233 : UNUSED_PARAMETER(lookBack);
234 227 : 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 0 : virtual bool isFrontOnLane(const MSLane*) const {
241 0 : 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 22 : virtual double getLateralPositionOnLane() const {
249 22 : 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 0 : virtual double getRightSideOnEdge(const MSLane* lane = 0) const {
258 : UNUSED_PARAMETER(lane);
259 0 : 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 266451 : virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const {
268 266451 : 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 618484 : virtual const MSEdge* getRerouteDestination() const {
276 618484 : return myRoute->getLastEdge();
277 : }
278 :
279 : /** @brief Returns the time loss in seconds
280 : */
281 9 : virtual double getTimeLossSeconds() const {
282 : // better timeLoss for meso?
283 9 : 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 0 : double getWaitingSeconds() const {
293 48328250 : 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 8759064 : const MSRouteIterator& getCurrentRouteEdge() const {
302 8759064 : 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 12291468 : inline SUMOTime getDeparture() const {
366 12291468 : 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 308 : virtual double getStopDelay() const {
375 : /// @todo implement for meso
376 308 : return -1;
377 : }
378 :
379 : /** @brief Returns the estimated public transport stop arrival delay in seconds
380 : */
381 1786 : virtual double getStopArrivalDelay() const {
382 : /// @todo implement for meso
383 1786 : return INVALID_DOUBLE;
384 : }
385 :
386 : /// @brief return time (s) and distance to the next stop
387 4 : virtual std::pair<double, double> estimateTimeToNextStop() const {
388 4 : 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 242706 : inline double getDepartPos() const {
395 242706 : 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 1606389 : virtual double getArrivalPos() const {
403 1606389 : return myArrivalPos;
404 : }
405 :
406 0 : virtual int getArrivalLane() const {
407 0 : return myArrivalLane;
408 : }
409 :
410 : /** @brief Sets this vehicle's desired arrivalPos for its current route
411 : */
412 1620 : virtual void setArrivalPos(double arrivalPos) {
413 1620 : myArrivalPos = arrivalPos;
414 1620 : }
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 0 : virtual void onRemovalFromNet(const MSMoveReminder::Notification /*reason*/) {}
424 :
425 : /** @brief Returns whether this vehicle has already departed
426 : */
427 23509858 : inline bool hasDeparted() const {
428 23509858 : 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 80 : myOdometer += value;
457 24 : }
458 :
459 : /** @brief Returns the number of new routes this vehicle got
460 : * @return the number of new routes this vehicle got
461 : */
462 361102 : inline int getNumberReroutes() const {
463 361102 : 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 3839979 : inline const std::vector<MSVehicleDevice*>& getDevices() const {
494 3839979 : 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 822830051 : inline double getLength() const {
574 822830051 : 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 81061213 : 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 5414105425 : inline double getChosenSpeedFactor() const {
593 5414105425 : return myChosenSpeedFactor;
594 : }
595 :
596 : inline double getDesiredMaxSpeed() const {
597 603822217 : 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 40374 : inline void setChosenSpeedFactor(const double factor) {
604 40374 : myChosenSpeedFactor = factor;
605 40374 : }
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 11594044 : 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 1591504649 : bool hasStops() const {
681 1591504649 : 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 3220532 : inline const std::list<MSStop>& getStops() const {
730 3220532 : 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 261571388 : virtual bool isSelected() const {
818 261571388 : 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 26765501657 : inline NumericalID getNumericalID() const {
828 26765501657 : return myNumericalID;
829 : }
830 :
831 : const MSDevice_Transportable* getPersonDevice() const {
832 11597855 : return myPersonDevice;
833 : }
834 :
835 : const MSDevice_Transportable* getContainerDevice() const {
836 11597855 : return myContainerDevice;
837 : }
838 :
839 : /// @brief retrieve parameters for the energy consumption model
840 105913884 : inline EnergyParams* getEmissionParameters() const {
841 105913884 : if (myEnergyParams == nullptr) {
842 914922 : myEnergyParams = new EnergyParams(getVehicleType().getEmissionParameters());
843 : }
844 105913884 : return myEnergyParams;
845 : }
846 :
847 : /// @name Emission retrieval
848 : //@{
849 :
850 : /** @brief Returns emissions of the current state
851 : * The value is always per 1s, so multiply by step length if necessary.
852 : * @return The current emission
853 : */
854 : template<PollutantsInterface::EmissionType ET>
855 6060 : double getEmissions() const {
856 6060 : if (isOnRoad() || isIdling()) {
857 5988 : return PollutantsInterface::compute(myType->getEmissionClass(), ET, getSpeed(), getAcceleration(), getSlope(), getEmissionParameters());
858 : }
859 : return 0.;
860 : }
861 :
862 : /** @brief Returns actual state of charge of battery (Wh)
863 : * RICE_CHECK: This may be a misnomer, SOC is typically percentage of the maximum battery capacity.
864 : * @return The actual battery state of charge
865 : */
866 : double getStateOfCharge() const;
867 :
868 : /** @brief Returns actual relative state of charge of battery (-)
869 : * @return The actual relative battery state of charge, normalised to the maximum battery capacity.
870 : */
871 : double getRelativeStateOfCharge() const;
872 :
873 : /** @brief Returns the energy charged to the battery in the current time step (Wh)
874 : * @return The energy charged to the battery in the current time step.
875 : */
876 : double getChargedEnergy() const;
877 :
878 : /** @brief Returns the maximum charge rate allowed by the battery in the current time step (W)
879 : * @return The maximum charge rate in the current time step.
880 : */
881 : double getMaxChargeRate() const;
882 :
883 : /** @brief Returns actual current (A) of ElecHybrid device
884 : * RICE_CHECK: Is this the current consumed from the overhead wire or the current driving the powertrain of the vehicle?
885 : * RICE_REV_JS: It is the current drawn from the overhead wire (value if the vehicle is not connected to overhead wire?)
886 : * @return The current of ElecHybrid device
887 : */
888 : double getElecHybridCurrent() const;
889 :
890 : /** @brief Returns noise emissions of the current state
891 : * @return The noise produced
892 : */
893 : double getHarmonoise_NoiseEmissions() const;
894 : //@}
895 :
896 : /** @class Influencer
897 : * @brief Changes the wished vehicle speed / lanes
898 : *
899 : * The class is used for passing velocities or velocity profiles obtained via TraCI to the vehicle.
900 : * The speed adaptation is controlled by the stored speedTimeLine
901 : * Additionally, the variables myConsiderSafeVelocity, myConsiderMaxAcceleration, and myConsiderMaxDeceleration
902 : * control whether the safe velocity, the maximum acceleration, and the maximum deceleration
903 : * have to be regarded.
904 : *
905 : * Furthermore this class is used to affect lane changing decisions according to
906 : * LaneChangeMode and any given laneTimeLine
907 : */
908 : class BaseInfluencer {
909 : public:
910 : /// @brief Constructor
911 : BaseInfluencer();
912 :
913 : /// @brief Destructor
914 0 : virtual ~BaseInfluencer() {}
915 :
916 : /// @brief Static initalization
917 : static void init();
918 : /// @brief Static cleanup
919 : static void cleanup();
920 :
921 :
922 : /// @brief return the current routing mode
923 : double getExtraImpatience() const {
924 235473 : return myExtraImpatience;
925 : }
926 :
927 : /** @brief Sets routing behavior
928 : * @param[in] value an enum value controlling the different modes
929 : */
930 : void setExtraImpatience(double value) {
931 270850 : myExtraImpatience = value;
932 270823 : }
933 :
934 : protected:
935 : /// @brief dynamic impatience offset
936 : double myExtraImpatience = 0;
937 :
938 : };
939 :
940 :
941 :
942 : /** @brief Returns the velocity/lane influencer
943 : *
944 : * If no influencer was existing before, one is built, first
945 : * @return Reference to this vehicle's speed influencer
946 : */
947 : virtual BaseInfluencer& getBaseInfluencer() = 0;
948 :
949 : virtual const BaseInfluencer* getBaseInfluencer() const = 0;
950 :
951 : virtual bool hasInfluencer() const = 0;
952 :
953 : /// @brief return routing mode (configures router choice but also handling of transient permission changes)
954 661591436 : int getRoutingMode() const {
955 661591436 : return myRoutingMode;
956 : }
957 :
958 : /** @brief Sets routing behavior
959 : * @param[in] value an enum value controlling the different modes
960 : */
961 : void setRoutingMode(int value) {
962 5824 : myRoutingMode = value;
963 207 : }
964 :
965 :
966 : SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT() const;
967 :
968 : /** @brief Returns the vehicle's internal edge travel times/efforts container
969 : *
970 : * If the vehicle does not have such a container, it is built.
971 : * @return The vehicle's knowledge about edge weights
972 : */
973 : const MSEdgeWeightsStorage& getWeightsStorage() const;
974 : MSEdgeWeightsStorage& getWeightsStorage();
975 :
976 : /** @brief Returns the leader of the vehicle looking for a fixed distance.
977 : *
978 : * If the distance is not given it is calculated from the brake gap.
979 : * The gap returned does not include the minGap.
980 : * @param dist up to which distance to look at least for a leader
981 : * @param considerCrossingFoes Whether vehicles on crossing foe links should be considered
982 : * @return The leading vehicle together with the gap; (0, -1) if no leader was found.
983 : */
984 479 : virtual std::pair<const MSVehicle* const, double> getLeader(double dist = 0, bool considerCrossingFoes = true) const {
985 : UNUSED_PARAMETER(dist);
986 : UNUSED_PARAMETER(considerCrossingFoes);
987 479 : WRITE_WARNING(TL("getLeader not yet implemented for meso"));
988 479 : return std::make_pair(nullptr, -1);
989 : }
990 :
991 : /** @brief Returns the follower of the vehicle looking for a fixed distance.
992 : *
993 : * If the distance is not given it is set to the value of MSCFModel::brakeGap(2*roadSpeed, 4.5, 0)
994 : * The gap returned does not include the minGap.
995 : * If there are multiple followers, the one that maximizes the term (getSecureGap - gap) is returned.
996 : * @param dist up to which distance to look at least for a leader
997 : * @return The leading vehicle together with the gap; (0, -1) if no leader was found.
998 : */
999 54 : virtual std::pair<const MSVehicle* const, double> getFollower(double dist = 0) const {
1000 : UNUSED_PARAMETER(dist);
1001 54 : WRITE_WARNING(TL("getFollower not yet implemented for meso"));
1002 54 : return std::make_pair(nullptr, -1);
1003 : }
1004 :
1005 : /** @brief (Re-)Calculates the arrival position and lane from the vehicle parameters
1006 : */
1007 : void calculateArrivalParams(bool onInit);
1008 :
1009 : /// @brief apply departEdge and arrivalEdge attributes
1010 : void setDepartAndArrivalEdge();
1011 :
1012 : int getDepartEdge() const;
1013 :
1014 : int getInsertionChecks() const;
1015 :
1016 : /// @brief interpret stop lane on opposite side of the road
1017 : static MSLane* interpretOppositeStop(SUMOVehicleParameter::Stop& stop);
1018 :
1019 : /// @name state io
1020 : //@{
1021 : void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local);
1022 : SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const;
1023 : void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local);
1024 : SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const;
1025 :
1026 : /// @brief score only needed when running with gui
1027 : void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score);
1028 : void resetParkingAreaScores();
1029 : void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score);
1030 : void resetChargingStationScores();
1031 :
1032 58091 : int getNumberParkingReroutes() const {
1033 58091 : return myNumberParkingReroutes;
1034 : }
1035 27862 : void setNumberParkingReroutes(int value) {
1036 27862 : myNumberParkingReroutes = value;
1037 27862 : }
1038 :
1039 : const StoppingPlaceMemory* getParkingMemory() const {
1040 65 : return myParkingMemory;
1041 : }
1042 :
1043 : const StoppingPlaceMemory* getChargingMemory() const {
1044 98 : return myChargingMemory;
1045 : }
1046 : //@}
1047 :
1048 : protected:
1049 : /// @brief reset rail signal approach information
1050 29 : virtual void resetApproachOnReroute() {};
1051 :
1052 : struct StopEdgeInfo {
1053 :
1054 100230 : StopEdgeInfo(const MSEdge* _edge, double _priority, SUMOTime _arrival, double _pos):
1055 100230 : edge(_edge), pos(_pos),
1056 100230 : priority(_priority), arrival(_arrival) {};
1057 : const MSEdge* edge;
1058 : double pos;
1059 : double priority;
1060 : SUMOTime arrival;
1061 : /// @brief values set during routing and used during optimization
1062 : int routeIndex = -1;
1063 : bool skipped = false;
1064 : bool backtracked = false;
1065 : SUMOTime delay = 0;
1066 :
1067 : bool operator==(const StopEdgeInfo& o) const {
1068 7743 : return edge == o.edge;
1069 : }
1070 : bool operator!=(const StopEdgeInfo& o) const {
1071 : return !(*this == o);
1072 : }
1073 : };
1074 :
1075 : /** @brief Returns the list of still pending stop edges
1076 : * also returns the first and last stop position
1077 : */
1078 : std::vector<StopEdgeInfo> getStopEdges(double& firstPos, double& lastPos, std::set<int>& jumps) const;
1079 :
1080 : static double addStopPriority(double p1, double p2);
1081 :
1082 :
1083 : ConstMSEdgeVector optimizeSkipped(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router,
1084 : const MSEdge* source, double sourcePos, std::vector<StopEdgeInfo>& stops, ConstMSEdgeVector edges, SUMOTime maxDelay) const;
1085 :
1086 : ConstMSEdgeVector routeAlongStops(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router,
1087 : std::vector<StopEdgeInfo>& stops, ConstMSEdgeVector edges,
1088 : int originStop, SUMOTime maxDelay, double& skippedPrio2) const;
1089 :
1090 :
1091 : protected:
1092 : /// @brief This vehicle's parameter.
1093 : const SUMOVehicleParameter* myParameter;
1094 :
1095 : /// @brief This vehicle's route.
1096 : ConstMSRoutePtr myRoute;
1097 :
1098 : /// @brief This vehicle's type.
1099 : const MSVehicleType* myType;
1100 :
1101 : /// @brief Iterator to current route-edge
1102 : MSRouteIterator myCurrEdge;
1103 :
1104 : /// @brief A precomputed factor by which the driver wants to be faster than the speed limit
1105 : double myChosenSpeedFactor;
1106 :
1107 : /// @brief The vehicle's list of stops
1108 : std::list<MSStop> myStops;
1109 :
1110 : /// @brief The list of stops that the vehicle has already reached
1111 : StopParVector myPastStops;
1112 :
1113 : /// @name Move reminder structures
1114 : /// @{
1115 :
1116 : /// @brief Definition of a move reminder container
1117 : // The double value holds the relative position offset, i.e.,
1118 : // offset + vehicle-position - moveReminder-position = distance,
1119 : // i.e. the offset is counted up when the vehicle continues to a
1120 : // succeeding lane.
1121 : typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
1122 :
1123 : /// @brief Currently relevant move reminders
1124 : MoveReminderCont myMoveReminders;
1125 : /// @}
1126 :
1127 : /// @brief The devices this vehicle has
1128 : std::vector<MSVehicleDevice*> myDevices;
1129 :
1130 : /// @brief The passengers this vehicle may have
1131 : MSDevice_Transportable* myPersonDevice;
1132 :
1133 : /// @brief The containers this vehicle may have
1134 : MSDevice_Transportable* myContainerDevice;
1135 :
1136 : /// @brief The emission parameters this vehicle may have
1137 : mutable EnergyParams* myEnergyParams;
1138 :
1139 : /// @brief The real departure time
1140 : SUMOTime myDeparture;
1141 :
1142 : /// @brief The real depart position
1143 : double myDepartPos;
1144 :
1145 : /// @brief The position on the destination lane where the vehicle stops
1146 : double myArrivalPos;
1147 :
1148 : /// @brief The destination lane where the vehicle stops
1149 : int myArrivalLane;
1150 :
1151 : /// @brief The number of reroutings
1152 : int myNumberReroutes;
1153 :
1154 : /// @brief The offset when adding route stops with 'until' on route replacement
1155 : SUMOTime myStopUntilOffset;
1156 :
1157 : /// @brief A simple odometer to keep track of the length of the route already driven
1158 : double myOdometer;
1159 :
1160 : /// @brief status of the current vehicle route
1161 : int myRouteValidity;
1162 :
1163 : /// memory for parking search
1164 : StoppingPlaceMemory* myParkingMemory = nullptr;
1165 : StoppingPlaceMemory* myChargingMemory = nullptr;
1166 : int myNumberParkingReroutes = 0;
1167 :
1168 : /// @brief Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
1169 : bool myAmRegisteredAsWaiting = false;
1170 :
1171 : /* @brief magic value for undeparted vehicles
1172 : * @note: in previous versions this was -1
1173 : */
1174 : static const SUMOTime NOT_YET_DEPARTED;
1175 :
1176 : static std::vector<MSTransportable*> myEmptyTransportableVector;
1177 :
1178 : /* @brief The logical 'reversed' state of the vehicle - intended to be used by drawing functions
1179 : * @note: only set by vClass rail reversing at the moment
1180 : */
1181 : bool myAmReversed = false;
1182 :
1183 : ///@brief routing mode (see TraCIConstants.h)
1184 : int myRoutingMode;
1185 :
1186 : private:
1187 : const NumericalID myNumericalID;
1188 :
1189 : /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1190 : * @note member is initialized on first access */
1191 : mutable MSEdgeWeightsStorage* myEdgeWeights;
1192 :
1193 : MSEdgeWeightsStorage& _getWeightsStorage() const;
1194 :
1195 : static NumericalID myCurrentNumericalIndex;
1196 :
1197 : /// @brief init model parameters from generic params
1198 : void initTransientModelParams();
1199 :
1200 : /// @brief reconstruct flow id from vehicle id
1201 : std::string getFlowID() const;
1202 :
1203 : /// @brief remove route at the end of the simulation
1204 : void checkRouteRemoval();
1205 :
1206 : /// @brief helper function
1207 : bool insertJump(int nextStopIndex, MSRouteIterator itStart, std::string& errorMsg);
1208 :
1209 : /// @brief patch stop.pars.index to record the number of skipped candidate edges before stop.edge (in a looped route)
1210 : void setSkips(MSStop& stop, int prevActiveStops);
1211 :
1212 : /// @brief remove outdated driveways on reroute
1213 : SUMOTime activateRemindersOnReroute(SUMOTime currentTime);
1214 :
1215 : private:
1216 : /// invalidated assignment operator
1217 : MSBaseVehicle& operator=(const MSBaseVehicle& s) = delete;
1218 :
1219 : #ifdef _DEBUG
1220 : public:
1221 : static void initMoveReminderOutput(const OptionsCont& oc);
1222 :
1223 : protected:
1224 : /// @brief optionally generate movereminder-output for this vehicle
1225 : void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
1226 :
1227 : /// @brief whether this vehicle shall trace its moveReminders
1228 : const bool myTraceMoveReminders;
1229 : private:
1230 : /// @brief vehicles which shall trace their move reminders
1231 : static std::set<std::string> myShallTraceMoveReminders;
1232 : #endif
1233 :
1234 :
1235 : };
|