Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2010-2024 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 537053491 : bool isVehicle() const {
100 537053491 : 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 80539962 : inline const MSRoute& getRoute() const {
140 80539962 : return *myRoute;
141 : }
142 :
143 : /** @brief Returns the current route
144 : * @return The route the vehicle uses
145 : */
146 958860 : inline ConstMSRoutePtr getRoutePtr() const {
147 958860 : return myRoute;
148 : }
149 :
150 : /** @brief Returns the vehicle's type definition
151 : * @return The vehicle's type definition
152 : */
153 48137454967 : inline const MSVehicleType& getVehicleType() const {
154 48137454967 : return *myType;
155 : }
156 :
157 : /** @brief Returns the vehicle's type parameter
158 : * @return The vehicle's type parameter
159 : */
160 11075650 : inline const SUMOVTypeParameter& getVTypeParameter() const {
161 11075650 : return myType->getParameter();
162 : }
163 :
164 : /** @brief Returns the vehicle's access class
165 : * @return The vehicle's access class
166 : */
167 7517979641 : inline SUMOVehicleClass getVClass() const {
168 7517979641 : 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 6 : virtual const MSEdge* getCurrentEdge() const {
200 6 : 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 53852 : virtual bool isRemoteControlled() const {
229 53852 : return false;
230 : }
231 :
232 225 : virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
233 : UNUSED_PARAMETER(lookBack);
234 225 : 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 55840 : virtual double getLateralPositionOnLane() const {
249 55840 : 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 265862 : virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const {
268 265862 : 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 554285 : virtual const MSEdge* getRerouteDestination() const {
276 554285 : 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 167595308 : 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 11687061 : const MSRouteIterator& getCurrentRouteEdge() const {
302 11687061 : 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 11636183 : inline SUMOTime getDeparture() const {
366 11636183 : 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 269 : virtual double getStopDelay() const {
375 : /// @todo implement for meso
376 269 : return -1;
377 : }
378 :
379 : /** @brief Returns the estimated public transport stop arrival delay in seconds
380 : */
381 1755 : virtual double getStopArrivalDelay() const {
382 : /// @todo implement for meso
383 1755 : return INVALID_DOUBLE;
384 : }
385 :
386 : /** @brief Returns this vehicle's real departure position
387 : * @return This vehicle's real departure position
388 : */
389 238561 : inline double getDepartPos() const {
390 238561 : return myDepartPos;
391 : }
392 :
393 : /** @brief Returns this vehicle's desired arrivalPos for its current route
394 : * (may change on reroute)
395 : * @return This vehicle's real arrivalPos
396 : */
397 1519009 : virtual double getArrivalPos() const {
398 1519009 : return myArrivalPos;
399 : }
400 :
401 0 : virtual int getArrivalLane() const {
402 0 : return myArrivalLane;
403 : }
404 :
405 : /** @brief Sets this vehicle's desired arrivalPos for its current route
406 : */
407 1593 : virtual void setArrivalPos(double arrivalPos) {
408 1593 : myArrivalPos = arrivalPos;
409 1593 : }
410 :
411 : /** @brief Called when the vehicle is removed from the network.
412 : *
413 : * Moves along work reminders and
414 : * informs all devices about quitting. Calls "leaveLane" then.
415 : *
416 : * @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
417 : */
418 0 : virtual void onRemovalFromNet(const MSMoveReminder::Notification /*reason*/) {}
419 :
420 : /** @brief Returns whether this vehicle has already departed
421 : */
422 21813043 : inline bool hasDeparted() const {
423 21813043 : return myDeparture != NOT_YET_DEPARTED;
424 : }
425 :
426 : /** @brief Returns whether this vehicle has already arived
427 : * (by default this is true if the vehicle has reached its final edge)
428 : */
429 : virtual bool hasArrived() const;
430 :
431 : /// @brief return index of edge within route
432 : int getRoutePosition() const;
433 :
434 : /// @brief reset index of edge within route
435 : void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure);
436 :
437 : /** @brief Returns the distance that was already driven by this vehicle
438 : * @return the distance driven [m]
439 : */
440 : double getOdometer() const;
441 :
442 : /// @brief Manipulate the odometer
443 : void addToOdometer(double value) {
444 80 : myOdometer += value;
445 24 : }
446 :
447 : /** @brief Returns the number of new routes this vehicle got
448 : * @return the number of new routes this vehicle got
449 : */
450 341567 : inline int getNumberReroutes() const {
451 341567 : return myNumberReroutes;
452 : }
453 :
454 : /// @brief Returns this vehicles impatience
455 : double getImpatience() const;
456 :
457 : /** @brief Returns the number of persons
458 : * @return The number of passengers on-board
459 : */
460 : int getPersonNumber() const;
461 :
462 : /** @brief Returns the number of leaving persons
463 : * @return The number of leaving passengers
464 : */
465 : int getLeavingPersonNumber() const;
466 :
467 : /** @brief Returns the list of persons
468 : * @return The list of passengers on-board
469 : */
470 : std::vector<std::string> getPersonIDList() const;
471 :
472 : /** @brief Returns the number of containers
473 : * @return The number of contaiers on-board
474 : */
475 : int getContainerNumber() const;
476 :
477 :
478 : /** @brief Returns this vehicle's devices
479 : * @return This vehicle's devices
480 : */
481 3653325 : inline const std::vector<MSVehicleDevice*>& getDevices() const {
482 3653325 : return myDevices;
483 : }
484 :
485 : /// @brief whether the given transportable is allowed to board this vehicle
486 : bool allowsBoarding(const MSTransportable* t) const;
487 :
488 : /** @brief Adds a person or container to this vehicle
489 : *
490 : * @param[in] transportable The person/container to add
491 : */
492 : virtual void addTransportable(MSTransportable* transportable);
493 :
494 : /// @brief removes a person or container
495 : void removeTransportable(MSTransportable* t);
496 :
497 : /// @brief retrieve riding persons
498 : const std::vector<MSTransportable*>& getPersons() const;
499 :
500 : /// @brief retrieve riding containers
501 : const std::vector<MSTransportable*>& getContainers() const;
502 :
503 : /// @brief returns whether the vehicle serves a public transport line that serves the given stop
504 : bool isLineStop(double position) const;
505 :
506 : /// @brief check wether the vehicle has jump at the given part of its route
507 : bool hasJump(const MSRouteIterator& it) const;
508 :
509 : /** @brief Validates the current or given route
510 : * @param[out] msg Description why the route is not valid (if it is the case)
511 : * @param[in] route The route to check (or 0 if the current route shall be checked)
512 : * @return Whether the vehicle's current route is valid
513 : */
514 : bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const;
515 :
516 : /// @brief checks wether the vehicle can depart on the first edge
517 : virtual bool hasValidRouteStart(std::string& msg);
518 :
519 : /// @brief check for route validity at first insertion attempt
520 : int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr);
521 :
522 : /** @brief Adds a MoveReminder dynamically
523 : *
524 : * @param[in] rem the reminder to add
525 : * @see MSMoveReminder
526 : */
527 : void addReminder(MSMoveReminder* rem);
528 :
529 : /** @brief Removes a MoveReminder dynamically
530 : *
531 : * @param[in] rem the reminder to remove
532 : * @see MSMoveReminder
533 : */
534 : void removeReminder(MSMoveReminder* rem);
535 :
536 : /** @brief "Activates" all current move reminder
537 : *
538 : * For all move reminder stored in "myMoveReminders", their method
539 : * "MSMoveReminder::notifyEnter" is called.
540 : *
541 : * @param[in] reason The reason for changing the reminders' states
542 : * @param[in] enteredLane The lane, which is entered (if applicable)
543 : * @see MSMoveReminder
544 : * @see MSMoveReminder::notifyEnter
545 : * @see MSMoveReminder::Notification
546 : */
547 : virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
548 :
549 :
550 : /** @brief Returns the vehicle's length
551 : * @return vehicle's length
552 : */
553 759663998 : inline double getLength() const {
554 759663998 : return myType->getLength();
555 : }
556 :
557 :
558 : /** @brief Returns the vehicle's width
559 : * @return vehicle's width
560 : */
561 : inline double getWidth() const {
562 72384180 : return myType->getWidth();
563 : }
564 :
565 :
566 : /** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
567 : * @return Speed limit factor
568 : */
569 4978910200 : inline double getChosenSpeedFactor() const {
570 4978910200 : return myChosenSpeedFactor;
571 : }
572 :
573 : /** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit
574 : * @return Speed limit factor
575 : */
576 39387 : inline void setChosenSpeedFactor(const double factor) {
577 39387 : myChosenSpeedFactor = factor;
578 39387 : }
579 :
580 : /// @brief Returns a device of the given type if it exists, nullptr otherwise
581 : MSDevice* getDevice(const std::type_info& type) const;
582 :
583 :
584 : /** @brief Replaces the current vehicle type by the one given
585 : *
586 : * If the currently used vehicle type is marked as being used by this vehicle
587 : * only, it is deleted, first. The new, given type is then assigned to
588 : * "myType".
589 : * @param[in] type The new vehicle type
590 : * @see MSBaseVehicle::myType
591 : */
592 : virtual void replaceVehicleType(MSVehicleType* type);
593 :
594 :
595 : /** @brief Replaces the current vehicle type with a new one used by this vehicle only
596 : *
597 : * If the currently used vehicle type is already marked as being used by this vehicle
598 : * only, no new type is created.
599 : * @return The new modifiable vehicle type
600 : * @see MSBaseVehicle::myType
601 : */
602 : MSVehicleType& getSingularType();
603 :
604 : /// @name state io
605 : //@{
606 :
607 : /// Saves the (common) state of a vehicle
608 : virtual void saveState(OutputDevice& out);
609 :
610 : //@}
611 :
612 : virtual bool handleCollisionStop(MSStop& stop, const double distToStop);
613 :
614 : /** @brief Returns whether the vehicle is at a stop
615 : * @return Whether the vehicle has stopped
616 : */
617 : bool isStopped() const;
618 :
619 : /** @brief Returns whether the vehicle is parking
620 : * @return whether the vehicle is parking
621 : */
622 : bool isParking() const;
623 :
624 : /** @brief Returns whether the vehicle is perform a jump
625 : * @return whether the vehicle is starting to jump
626 : */
627 : bool isJumping() const;
628 :
629 : /** @brief Returns whether the logical state of the vehicle is reversed - for drawing
630 : * @return whether the logical state of the vehicle is reversed
631 : */
632 : inline bool isReversed() const {
633 8945890 : return myAmReversed;
634 : }
635 :
636 : /** @brief Returns whether the vehicle is on a triggered stop
637 : * @return whether the vehicle is on a triggered stop
638 : */
639 : bool isStoppedTriggered() const;
640 :
641 : /** @brief Returns whether the vehicle is on a parking stop
642 : * @return whether the vehicle is on a parking stop
643 : */
644 : bool isStoppedParking() const;
645 :
646 : /** @brief return whether the given position is within range of the current stop
647 : */
648 : bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const;
649 :
650 : /** @brief Returns whether the vehicle has to stop somewhere
651 : * @return Whether the vehicle has to stop somewhere
652 : */
653 1444796829 : bool hasStops() const {
654 1444796829 : return !myStops.empty();
655 : }
656 :
657 : /** @brief replace the current parking area stop with a new stop with merge duration
658 : */
659 : bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg);
660 :
661 : /** @brief get the upcoming parking area stop or nullptr
662 : */
663 : MSParkingArea* getNextParkingArea();
664 :
665 : /** @brief get the current parking area stop or nullptr */
666 : MSParkingArea* getCurrentParkingArea();
667 :
668 : /// @brief get the valid parking access rights (vehicle settings override vehicle type settings)
669 : const std::vector<std::string>& getParkingBadges() const;
670 :
671 : /// @brief departure position where the vehicle fits fully onto the edge (if possible)
672 : double basePos(const MSEdge* edge) const;
673 :
674 : /** @brief Adds a stop
675 : *
676 : * The stop is put into the sorted list.
677 : * @param[in] stop The stop to add
678 : * @return Whether the stop could be added
679 : */
680 : bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
681 : MSRouteIterator* searchStart = nullptr);
682 :
683 : /** @brief Adds stops to the built vehicle
684 : *
685 : * This code needs to be separated from the MSBaseVehicle constructor
686 : * since it is not allowed to call virtual functions from a constructor
687 : *
688 : * @param[in] ignoreStopErrors whether invalid stops trigger a warning only
689 : */
690 : void addStops(const bool ignoreStopErrors, MSRouteIterator* searchStart = nullptr, bool addRouteStops = true);
691 :
692 : /// @brief check whether all stop.edge MSRouteIterators are valid and in order
693 : bool haveValidStopEdges(bool silent = false) const;
694 :
695 : /** @brief Returns the list of still pending stop edges
696 : * also returns the first and last stop position
697 : */
698 : const ConstMSEdgeVector getStopEdges(double& firstPos, double& lastPos, std::set<int>& jumps) const;
699 :
700 : /// @brief return list of route indices for the remaining stops
701 : std::vector<std::pair<int, double> > getStopIndices() const;
702 :
703 : /**
704 : * returns the list of stops not yet reached in the stop queue
705 : * @return the list of upcoming stops
706 : */
707 87044 : inline const std::list<MSStop>& getStops() const {
708 87044 : return myStops;
709 : }
710 :
711 : inline const std::vector<SUMOVehicleParameter::Stop>& getPastStops() const {
712 : return myPastStops;
713 : }
714 :
715 : /**
716 : * returns the next imminent stop in the stop queue
717 : * @return the upcoming stop
718 : */
719 : MSStop& getNextStop();
720 :
721 : /// @brief get remaining stop duration or 0 if the vehicle isn't stopped
722 : SUMOTime getStopDuration() const;
723 :
724 : /**
725 : * returns the upcoming stop with the given index in the stop queue
726 : * @return an upcoming stop
727 : */
728 : MSStop& getStop(int nextStopIndex);
729 :
730 : /// @brief return parameters for the next stop (SUMOVehicle Interface)
731 : const SUMOVehicleParameter::Stop* getNextStopParameter() const;
732 :
733 : /**
734 : * schedule a new stop for the vehicle; each time a stop is reached, the vehicle
735 : * will wait for the given duration before continuing on its route
736 : * @param[in] stop Stop parameters
737 : * @param[out] errorMsg returned error message
738 : */
739 : virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg);
740 :
741 : /**
742 : * resumes a vehicle from stopping
743 : * @return true on success, the resuming fails if the vehicle wasn't parking in the first place
744 : */
745 : virtual bool resumeFromStopping() = 0;
746 :
747 : /// @brief mark vehicle as active
748 : void unregisterWaiting();
749 :
750 : /// @brief deletes the next stop at the given index if it exists
751 : bool abortNextStop(int nextStopIndex = 0);
752 :
753 : /**
754 : * replace the next stop at the given index with the given stop parameters
755 : * will wait for the given duration before continuing on its route
756 : * The route between start other stops and destination will be kept unchanged and
757 : * only the part around the replacement index will be adapted according to the new stop location
758 : * @param[in] nextStopIndex The replacement index
759 : * @param[in] stop Stop parameters
760 : * @param[in] info The rerouting info
761 : * @param[in] teleport Whether to cover the route to the replacement stop via teleporting
762 : * @param[out] errorMsg returned error message
763 : */
764 : bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
765 :
766 : /**
767 : * reroute between stops nextStopIndex - 1 and nextStopIndex (defaults to current position / final edge) if the respective stops do not exist
768 : * @param[in] nextStopIndex The replacement index
769 : * @param[in] info The rerouting info
770 : * @param[in] teleport Whether to cover the route between stops via teleporting
771 : * @param[out] errorMsg returned error message
772 : */
773 : bool rerouteBetweenStops(int nextStopIndex, const std::string& info, bool teleport, std::string& errorMsg);
774 :
775 : /**
776 : * insert stop at the given index with the given stop parameters
777 : * will wait for the given duration before continuing on its route
778 : * 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).
779 : * @param[in] nextStopIndex The replacement index
780 : * @param[in] stop Stop parameters
781 : * @param[in] info The rerouting info
782 : * @param[in] teleport Whether to cover the route to the new stop via teleporting
783 : * @param[out] errorMsg returned error message
784 : */
785 : bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);
786 :
787 :
788 : /// @brief whether this vehicle is selected in the GUI
789 245668435 : virtual bool isSelected() const {
790 245668435 : return false;
791 : }
792 :
793 : /// @brief @return The index of the vehicle's associated RNG
794 : int getRNGIndex() const;
795 :
796 : /// @brief @return The vehicle's associated RNG
797 : SumoRNG* getRNG() const;
798 :
799 23578448898 : inline NumericalID getNumericalID() const {
800 23578448898 : return myNumericalID;
801 : }
802 :
803 : const MSDevice_Transportable* getPersonDevice() const {
804 8949371 : return myPersonDevice;
805 : }
806 :
807 : const MSDevice_Transportable* getContainerDevice() const {
808 8949371 : return myContainerDevice;
809 : }
810 :
811 : /// @brief retrieve parameters for the energy consumption model
812 101003933 : inline EnergyParams* getEmissionParameters() const {
813 101003933 : if (myEnergyParams == nullptr) {
814 861209 : myEnergyParams = new EnergyParams(getVehicleType().getEmissionParameters());
815 : }
816 101003933 : return myEnergyParams;
817 : }
818 :
819 : /// @name Emission retrieval
820 : //@{
821 :
822 : /** @brief Returns emissions of the current state
823 : * The value is always per 1s, so multiply by step length if necessary.
824 : * @return The current emission
825 : */
826 : template<PollutantsInterface::EmissionType ET>
827 4832 : double getEmissions() const {
828 4832 : if (isOnRoad() || isIdling()) {
829 4760 : return PollutantsInterface::compute(myType->getEmissionClass(), ET, getSpeed(), getAcceleration(), getSlope(), getEmissionParameters());
830 : }
831 : return 0.;
832 : }
833 :
834 : /** @brief Returns actual state of charge of battery (Wh)
835 : * RICE_CHECK: This may be a misnomer, SOC is typically percentage of the maximum battery capacity.
836 : * @return The actual battery state of charge
837 : */
838 : double getStateOfCharge() const;
839 :
840 : /** @brief Returns actual relative state of charge of battery (-)
841 : * @return The actual relative battery state of charge, normalised to the maximum battery capacity.
842 : */
843 : double getRelativeStateOfCharge() const;
844 :
845 : /** @brief Returns the energy charged to the battery in the current time step (Wh)
846 : * @return The energy charged to the battery in the current time step.
847 : */
848 : double getChargedEnergy() const;
849 :
850 : /** @brief Returns the maximum charge rate allowed by the battery in the current time step (W)
851 : * @return The maximum charge rate in the current time step.
852 : */
853 : double getMaxChargeRate() const;
854 :
855 : /** @brief Returns actual current (A) of ElecHybrid device
856 : * RICE_CHECK: Is this the current consumed from the overhead wire or the current driving the powertrain of the vehicle?
857 : * RICE_REV_JS: It is the current drawn from the overhead wire (value if the vehicle is not connected to overhead wire?)
858 : * @return The current of ElecHybrid device
859 : */
860 : double getElecHybridCurrent() const;
861 :
862 : /** @brief Returns noise emissions of the current state
863 : * @return The noise produced
864 : */
865 : double getHarmonoise_NoiseEmissions() const;
866 : //@}
867 :
868 : /** @class Influencer
869 : * @brief Changes the wished vehicle speed / lanes
870 : *
871 : * The class is used for passing velocities or velocity profiles obtained via TraCI to the vehicle.
872 : * The speed adaptation is controlled by the stored speedTimeLine
873 : * Additionally, the variables myConsiderSafeVelocity, myConsiderMaxAcceleration, and myConsiderMaxDeceleration
874 : * control whether the safe velocity, the maximum acceleration, and the maximum deceleration
875 : * have to be regarded.
876 : *
877 : * Furthermore this class is used to affect lane changing decisions according to
878 : * LaneChangeMode and any given laneTimeLine
879 : */
880 : class BaseInfluencer {
881 : public:
882 : /// @brief Constructor
883 : BaseInfluencer();
884 :
885 : /// @brief Destructor
886 0 : virtual ~BaseInfluencer() {}
887 :
888 : /// @brief Static initalization
889 : static void init();
890 : /// @brief Static cleanup
891 : static void cleanup();
892 :
893 :
894 : /// @brief return the current routing mode
895 : double getExtraImpatience() const {
896 220795 : return myExtraImpatience;
897 : }
898 :
899 : /** @brief Sets routing behavior
900 : * @param[in] value an enum value controlling the different modes
901 : */
902 : void setExtraImpatience(double value) {
903 257482 : myExtraImpatience = value;
904 257455 : }
905 :
906 : protected:
907 : /// @brief dynamic impatience offset
908 : double myExtraImpatience = 0;
909 :
910 : };
911 :
912 :
913 :
914 : /** @brief Returns the velocity/lane influencer
915 : *
916 : * If no influencer was existing before, one is built, first
917 : * @return Reference to this vehicle's speed influencer
918 : */
919 : virtual BaseInfluencer& getBaseInfluencer() = 0;
920 :
921 : virtual const BaseInfluencer* getBaseInfluencer() const = 0;
922 :
923 : virtual bool hasInfluencer() const = 0;
924 :
925 : /// @brief return routing mode (configures router choice but also handling of transient permission changes)
926 638106635 : int getRoutingMode() const {
927 638106635 : return myRoutingMode;
928 : }
929 :
930 : /** @brief Sets routing behavior
931 : * @param[in] value an enum value controlling the different modes
932 : */
933 : void setRoutingMode(int value) {
934 5779 : myRoutingMode = value;
935 147 : }
936 :
937 :
938 : SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT() const;
939 :
940 : /** @brief Returns the vehicle's internal edge travel times/efforts container
941 : *
942 : * If the vehicle does not have such a container, it is built.
943 : * @return The vehicle's knowledge about edge weights
944 : */
945 : const MSEdgeWeightsStorage& getWeightsStorage() const;
946 : MSEdgeWeightsStorage& getWeightsStorage();
947 :
948 : /** @brief Returns the leader of the vehicle looking for a fixed distance.
949 : *
950 : * If the distance is not given it is calculated from the brake gap.
951 : * The gap returned does not include the minGap.
952 : * @param dist up to which distance to look at least for a leader
953 : * @return The leading vehicle together with the gap; (0, -1) if no leader was found.
954 : */
955 479 : virtual std::pair<const MSVehicle* const, double> getLeader(double dist = 0) const {
956 : UNUSED_PARAMETER(dist);
957 479 : WRITE_WARNING(TL("getLeader not yet implemented for meso"));
958 479 : return std::make_pair(nullptr, -1);
959 : }
960 :
961 : /** @brief Returns the follower of the vehicle looking for a fixed distance.
962 : *
963 : * If the distance is not given it is set to the value of MSCFModel::brakeGap(2*roadSpeed, 4.5, 0)
964 : * The gap returned does not include the minGap.
965 : * If there are multiple followers, the one that maximizes the term (getSecureGap - gap) is returned.
966 : * @param dist up to which distance to look at least for a leader
967 : * @return The leading vehicle together with the gap; (0, -1) if no leader was found.
968 : */
969 54 : virtual std::pair<const MSVehicle* const, double> getFollower(double dist = 0) const {
970 : UNUSED_PARAMETER(dist);
971 54 : WRITE_WARNING(TL("getFollower not yet implemented for meso"));
972 54 : return std::make_pair(nullptr, -1);
973 : }
974 :
975 : /** @brief (Re-)Calculates the arrival position and lane from the vehicle parameters
976 : */
977 : void calculateArrivalParams(bool onInit);
978 :
979 : /// @brief apply departEdge and arrivalEdge attributes
980 : void setDepartAndArrivalEdge();
981 :
982 : /// @brief interpret stop lane on opposite side of the road
983 : static MSLane* interpretOppositeStop(SUMOVehicleParameter::Stop& stop);
984 :
985 : /// @name state io
986 : //@{
987 : void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local);
988 : SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const;
989 : void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local);
990 : SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const;
991 :
992 : /// @brief score only needed when running with gui
993 : void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score);
994 : void resetParkingAreaScores();
995 : void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score);
996 : void resetChargingStationScores();
997 :
998 48223 : int getNumberParkingReroutes() const {
999 48223 : return myNumberParkingReroutes;
1000 : }
1001 19433 : void setNumberParkingReroutes(int value) {
1002 19433 : myNumberParkingReroutes = value;
1003 19433 : }
1004 :
1005 : const StoppingPlaceMemory* getParkingMemory() const {
1006 65 : return myParkingMemory;
1007 : }
1008 :
1009 : const StoppingPlaceMemory* getChargingMemory() const {
1010 80 : return myChargingMemory;
1011 : }
1012 : //@}
1013 :
1014 : protected:
1015 : /// @brief This vehicle's parameter.
1016 : const SUMOVehicleParameter* myParameter;
1017 :
1018 : /// @brief This vehicle's route.
1019 : ConstMSRoutePtr myRoute;
1020 :
1021 : /// @brief This vehicle's type.
1022 : MSVehicleType* myType;
1023 :
1024 : /// @brief Iterator to current route-edge
1025 : MSRouteIterator myCurrEdge;
1026 :
1027 : /// @brief A precomputed factor by which the driver wants to be faster than the speed limit
1028 : double myChosenSpeedFactor;
1029 :
1030 : /// @brief The vehicle's list of stops
1031 : std::list<MSStop> myStops;
1032 :
1033 : /// @brief The list of stops that the vehicle has already reached
1034 : std::vector<SUMOVehicleParameter::Stop> myPastStops;
1035 :
1036 :
1037 : /// @name Move reminder structures
1038 : /// @{
1039 :
1040 : /// @brief Definition of a move reminder container
1041 : // The double value holds the relative position offset, i.e.,
1042 : // offset + vehicle-position - moveReminder-position = distance,
1043 : // i.e. the offset is counted up when the vehicle continues to a
1044 : // succeeding lane.
1045 : typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
1046 :
1047 : /// @brief Currently relevant move reminders
1048 : MoveReminderCont myMoveReminders;
1049 : /// @}
1050 :
1051 : /// @brief The devices this vehicle has
1052 : std::vector<MSVehicleDevice*> myDevices;
1053 :
1054 : /// @brief The passengers this vehicle may have
1055 : MSDevice_Transportable* myPersonDevice;
1056 :
1057 : /// @brief The containers this vehicle may have
1058 : MSDevice_Transportable* myContainerDevice;
1059 :
1060 : /// @brief The emission parameters this vehicle may have
1061 : mutable EnergyParams* myEnergyParams;
1062 :
1063 : /// @brief The real departure time
1064 : SUMOTime myDeparture;
1065 :
1066 : /// @brief The real depart position
1067 : double myDepartPos;
1068 :
1069 : /// @brief The position on the destination lane where the vehicle stops
1070 : double myArrivalPos;
1071 :
1072 : /// @brief The destination lane where the vehicle stops
1073 : int myArrivalLane;
1074 :
1075 : /// @brief The number of reroutings
1076 : int myNumberReroutes;
1077 :
1078 : /// @brief The offset when adding route stops with 'until' on route replacement
1079 : SUMOTime myStopUntilOffset;
1080 :
1081 : /// @brief A simple odometer to keep track of the length of the route already driven
1082 : double myOdometer;
1083 :
1084 : /// @brief status of the current vehicle route
1085 : int myRouteValidity;
1086 :
1087 : /// memory for parking search
1088 : StoppingPlaceMemory* myParkingMemory = nullptr;
1089 : StoppingPlaceMemory* myChargingMemory = nullptr;
1090 : int myNumberParkingReroutes = 0;
1091 :
1092 : /// @brief Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
1093 : bool myAmRegisteredAsWaiting = false;
1094 :
1095 : /* @brief magic value for undeparted vehicles
1096 : * @note: in previous versions this was -1
1097 : */
1098 : static const SUMOTime NOT_YET_DEPARTED;
1099 :
1100 : static std::vector<MSTransportable*> myEmptyTransportableVector;
1101 :
1102 : /* @brief The logical 'reversed' state of the vehicle - intended to be used by drawing functions
1103 : * @note: only set by vClass rail reversing at the moment
1104 : */
1105 : bool myAmReversed = false;
1106 :
1107 : ///@brief routing mode (see TraCIConstants.h)
1108 : int myRoutingMode;
1109 :
1110 : private:
1111 : const NumericalID myNumericalID;
1112 :
1113 : /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1114 : * @note member is initialized on first access */
1115 : mutable MSEdgeWeightsStorage* myEdgeWeights;
1116 :
1117 : MSEdgeWeightsStorage& _getWeightsStorage() const;
1118 :
1119 : static NumericalID myCurrentNumericalIndex;
1120 :
1121 : /// @brief init model parameters from generic params
1122 : void initTransientModelParams();
1123 :
1124 : /// @brief reconstruct flow id from vehicle id
1125 : std::string getFlowID() const;
1126 :
1127 : /// @brief remove route at the end of the simulation
1128 : void checkRouteRemoval();
1129 :
1130 : /// @brief helper function
1131 : bool insertJump(int nextStopIndex, MSRouteIterator itStart, std::string& errorMsg);
1132 :
1133 : /// @brief patch stop.pars.index to record the number of skipped candidate edges before stop.edge (in a looped route)
1134 : void setSkips(MSStop& stop, int prevActiveStops);
1135 :
1136 : private:
1137 : /// invalidated assignment operator
1138 : MSBaseVehicle& operator=(const MSBaseVehicle& s) = delete;
1139 :
1140 : #ifdef _DEBUG
1141 : public:
1142 : static void initMoveReminderOutput(const OptionsCont& oc);
1143 :
1144 : protected:
1145 : /// @brief optionally generate movereminder-output for this vehicle
1146 : void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
1147 :
1148 : /// @brief whether this vehicle shall trace its moveReminders
1149 : const bool myTraceMoveReminders;
1150 : private:
1151 : /// @brief vehicles which shall trace their move reminders
1152 : static std::set<std::string> myShallTraceMoveReminders;
1153 : #endif
1154 :
1155 :
1156 : };
|