Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 MSCFModel.h
15 : /// @author Tobias Mayer
16 : /// @author Daniel Krajzewicz
17 : /// @author Jakob Erdmann
18 : /// @author Michael Behrisch
19 : /// @date Mon, 27 Jul 2009
20 : ///
21 : // The car-following model abstraction
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <cmath>
27 : #include <string>
28 : #include <utils/common/StdDefs.h>
29 : #include <utils/common/SUMOTime.h>
30 :
31 : #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
32 : // Factor that the minimum emergency decel is increased by in corresponding situations
33 : #define EMERGENCY_DECEL_AMPLIFIER 1.2
34 :
35 : // ===========================================================================
36 : // class declarations
37 : // ===========================================================================
38 : class MSVehicleType;
39 : class MSVehicle;
40 : class MSLane;
41 : class MSPerson;
42 : class MSLink;
43 :
44 :
45 : // ===========================================================================
46 : // class definitions
47 : // ===========================================================================
48 : /**
49 : * @class MSCFModel
50 : * @brief The car-following model abstraction
51 : *
52 : * MSCFModel is an interface for different car following Models to implement.
53 : * It provides methods to compute a vehicles velocity for a simulation step.
54 : */
55 : class MSCFModel {
56 :
57 : public:
58 :
59 378 : class VehicleVariables {
60 : public:
61 : virtual ~VehicleVariables();
62 : };
63 :
64 : /** @brief Constructor
65 : * @param[in] vtype the type for which this model is built and also the parameter object to configure this model
66 : */
67 : MSCFModel(const MSVehicleType* vtype);
68 :
69 :
70 : /// @brief Destructor
71 : virtual ~MSCFModel();
72 :
73 :
74 : /** @enum CalcReason
75 : * @brief What the return value of stop/follow/free-Speed is used for
76 : */
77 : enum CalcReason {
78 : /// @brief the return value is used for calculating the next speed
79 : CURRENT,
80 : /// @brief the return value is used for calculating future speeds
81 : FUTURE,
82 : /// @brief the return value is used for calculating junction stop speeds
83 : CURRENT_WAIT,
84 : /// @brief the return value is used for lane change calculations
85 : LANE_CHANGE
86 : };
87 :
88 :
89 : /// @name Methods to override by model implementation
90 : /// @{
91 :
92 : /** @brief Applies interaction with stops and lane changing model
93 : * influences. Called at most once per simulation step (exactcly once per action step)
94 : * @param[in] veh The ego vehicle
95 : * @param[in] vPos The possible velocity
96 : * @return The velocity after applying interactions with stops and lane change model influences
97 : */
98 : virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
99 :
100 :
101 : /// @brief apply custom speed adaptations within the given speed bounds
102 62095585 : virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
103 : UNUSED_PARAMETER(veh);
104 : UNUSED_PARAMETER(vMin);
105 62095585 : return vMax;
106 : }
107 :
108 : /// @brief apply speed adaptation on startup
109 : virtual double applyStartupDelay(const MSVehicle* veh, const double vMin, const double vMax, const SUMOTime addTime = 0) const;
110 :
111 :
112 : /** @brief Computes the vehicle's safe speed without a leader
113 : *
114 : * Returns the velocity of the vehicle in dependence to the length of the free street and the target
115 : * velocity at the end of the free range. If onInsertion is true, the vehicle may still brake
116 : * before the next movement.
117 : * @param[in] veh The vehicle (EGO)
118 : * @param[in] speed The vehicle's speed
119 : * @param[in] seen The look ahead distance
120 : * @param[in] maxSpeed The maximum allowed speed
121 : * @param[in] onInsertion whether speed at insertion is asked for
122 : * @param[in] usage What the return value is used for
123 : * @return EGO's safe speed
124 : */
125 : virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
126 : double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
127 :
128 :
129 : /** @brief Computes the vehicle's follow speed (no dawdling)
130 : *
131 : * Returns the velocity of the vehicle in dependence to the vehicle's and its leader's values and the distance between them.
132 : * @param[in] veh The vehicle (EGO)
133 : * @param[in] speed The vehicle's speed
134 : * @param[in] gap2pred The (net) distance to the LEADER
135 : * @param[in] predSpeed The speed of LEADER
136 : * @param[in] usage What the return value is used for
137 : * @return EGO's safe speed
138 : */
139 : virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
140 : double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const = 0;
141 :
142 :
143 : /** @brief Computes the vehicle's safe speed (no dawdling)
144 : * This method is used during the insertion stage. Whereas the method
145 : * followSpeed returns the desired speed which may be lower than the safe
146 : * speed, this method only considers safety constraints
147 : *
148 : * Returns the velocity of the vehicle in dependence to the vehicle's and its leader's values and the distance between them.
149 : * @param[in] veh The vehicle (EGO)
150 : * @param[in] speed The vehicle's speed
151 : * @param[in] gap2pred The (net) distance to the LEADER
152 : * @param[in] predSpeed The speed of LEADER
153 : * @return EGO's safe speed
154 : */
155 : virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
156 :
157 :
158 : /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
159 : *
160 : * Returns the velocity of the vehicle when approaching a static object (such as the end of a lane) assuming no reaction time is needed.
161 : * @param[in] veh The vehicle (EGO)
162 : * @param[in] speed The vehicle's speed
163 : * @param[in] gap The (net) distance to the obstacle
164 : * @param[in] usage What the return value is used for
165 : * @return EGO's safe speed for approaching a non-moving obstacle
166 : * @todo generic Interface, models can call for the values they need
167 : */
168 : inline double stopSpeed(const MSVehicle* const veh, const double speed, double gap, const CalcReason usage = CalcReason::CURRENT) const {
169 39130356 : return stopSpeed(veh, speed, gap, myDecel, usage);
170 : }
171 :
172 : /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
173 : *
174 : * Returns the velocity of the vehicle when approaching a static object (such as the end of a lane) assuming no reaction time is needed.
175 : * @param[in] veh The vehicle (EGO)
176 : * @param[in] speed The vehicle's speed
177 : * @param[in] gap The (net) distance to the obstacle
178 : * @param[in] decel The desired deceleration rate
179 : * @param[in] usage What the return value is used for
180 : * @return EGO's safe speed for approaching a non-moving obstacle
181 : * @todo generic Interface, models can call for the values they need
182 : */
183 : virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const = 0;
184 :
185 :
186 : /** @brief Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints
187 : * due to acceleration capabilities and previous speeds.
188 : * @param[in] veh The vehicle (EGO)
189 : * @param[in] speed The vehicle's speed
190 : * @param[in] gap The (net) distance to the obstacle
191 : * @return EGO's safe speed for approaching a non-moving obstacle at insertion
192 : * @see stopSpeed() and insertionFollowSpeed()
193 : *
194 : */
195 : virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
196 :
197 : /** @brief Computes the vehicle's follow speed that avoids a collision for the given amount of time
198 : *
199 : * Returns the velocity of the vehicle in dependence to the vehicle's and its leader's values and the distance between them.
200 : * @param[in] veh The vehicle (EGO)
201 : * @param[in] speed The vehicle's speed
202 : * @param[in] gap2pred The (net) distance to the LEADER
203 : * @param[in] predSpeed The speed of LEADER
204 : * @param[in] predMaxDecel The maximum leader deceleration
205 : * @return EGO's safe speed
206 : */
207 : virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
208 :
209 : /** @brief Returns the maximum gap at which an interaction between both vehicles occurs
210 : *
211 : * "interaction" means that the LEADER influences EGO's speed.
212 : * @param[in] veh The EGO vehicle
213 : * @param[in] vL LEADER's speed
214 : * @return The interaction gap
215 : * @todo evaluate signature
216 : */
217 : virtual double interactionGap(const MSVehicle* const veh, double vL) const;
218 :
219 :
220 : /** @brief Returns the maximum velocity the CF-model wants to achieve in the next step
221 : * @param[in] maxSpeed The maximum achievable speed in the next step
222 : * @param[in] maxSpeedLane The maximum speed the vehicle wants to drive on this lane (Speedlimit*SpeedFactor)
223 : */
224 541438397 : virtual double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
225 541438397 : double result = MIN2(maxSpeed, maxSpeedLane);
226 541438397 : applyOwnSpeedPerceptionError(veh, result);
227 541438397 : return result;
228 : }
229 :
230 :
231 : /** @brief Returns the model's ID; the XML-Tag number is used
232 : * @return The model's ID
233 : */
234 : virtual int getModelID() const = 0;
235 :
236 :
237 : /** @brief Duplicates the car-following model
238 : * @param[in] vtype The vehicle type this model belongs to (1:1)
239 : * @return A duplicate of this car-following model
240 : */
241 : virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
242 :
243 :
244 : /** @brief Returns model specific values which are stored inside a vehicle
245 : * and must be used with casting
246 : */
247 24544 : virtual VehicleVariables* createVehicleVariables() const {
248 24544 : return 0;
249 : }
250 : /// @}
251 :
252 :
253 : /** @brief Get the vehicle type's maximum acceleration [m/s^2]
254 : * @return The maximum acceleration (in m/s^2) of vehicles of this class
255 : */
256 : inline double getMaxAccel() const {
257 7306899584 : return myAccel;
258 : }
259 :
260 :
261 : /** @brief Get the vehicle type's maximal comfortable deceleration [m/s^2]
262 : * @return The maximal comfortable deceleration (in m/s^2) of vehicles of this class
263 : */
264 : inline double getMaxDecel() const {
265 7236696542 : return myDecel;
266 : }
267 :
268 :
269 : /** @brief Get the vehicle type's maximal physically possible deceleration [m/s^2]
270 : * @return The maximal physically possible deceleration (in m/s^2) of vehicles of this class
271 : */
272 : inline double getEmergencyDecel() const {
273 58143369 : return myEmergencyDecel;
274 : }
275 :
276 :
277 : /** @brief Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers
278 : * @return The apparent deceleration (in m/s^2) of vehicles of this class
279 : */
280 : inline double getApparentDecel() const {
281 1662568164 : return myApparentDecel;
282 : }
283 :
284 : /** @brief Get the vehicle type's startupDelay
285 : * @return The startupDelay
286 : */
287 : inline SUMOTime getStartupDelay() const {
288 13483905 : return myStartupDelay;
289 : }
290 :
291 : /** @brief Get the factor of minGap that must be maintained to avoid a collision event
292 : */
293 : inline double getCollisionMinGapFactor() const {
294 2122822848 : return myCollisionMinGapFactor;
295 : }
296 :
297 : /// @name Virtual methods with default implementation
298 : /// @{
299 :
300 : /** @brief Get the driver's imperfection
301 : * @return The imperfection of drivers of this class
302 : */
303 0 : virtual double getImperfection() const {
304 0 : return -1;
305 : }
306 :
307 :
308 : /** @brief Get the driver's desired headway [s]
309 : * @return The desired headway of this class' drivers in s
310 : */
311 244986533 : virtual double getHeadwayTime() const {
312 244986533 : return myHeadwayTime;
313 : }
314 :
315 : /// @brief whether startupDelay should be applied after stopping
316 13298997 : virtual bool startupDelayStopped() const {
317 13298997 : return false;
318 : }
319 : /// @}
320 :
321 :
322 :
323 :
324 : /// @name Currently fixed methods
325 : /// @{
326 :
327 : /** @brief Returns the maximum speed given the current speed
328 : *
329 : * The implementation of this method must take into account the time step
330 : * duration.
331 : *
332 : * Justification: Due to air brake or other influences, the vehicle's next maximum
333 : * speed may depend on the vehicle's current speed (given).
334 : *
335 : * @param[in] speed The vehicle's current speed
336 : * @param[in] veh The vehicle itself, for obtaining other values
337 : * @return The maximum possible speed for the next step
338 : */
339 : virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
340 :
341 :
342 : /** @brief Returns the maximum speed given the current speed and regarding driving dynamics
343 : * @param[in] speed The vehicle's current speed
344 : * @param[in] speed The vehicle itself, for obtaining other values
345 : * @return The maximum possible speed for the next step taking driving dynamics into account
346 : */
347 872286 : inline virtual double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
348 872286 : return maxNextSpeed(speed, veh);
349 : }
350 :
351 :
352 : /** @brief Returns the minimum speed given the current speed
353 : * (depends on the numerical update scheme and its step width)
354 : * Note that it wouldn't have to depend on the numerical update
355 : * scheme if the semantics would rely on acceleration instead of velocity.
356 : *
357 : * @param[in] speed The vehicle's current speed
358 : * @param[in] speed The vehicle itself, for obtaining other values, if needed as e.g. road conditions.
359 : * @return The minimum possible speed for the next step
360 : */
361 : virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
362 :
363 : /** @brief Returns the minimum speed after emergency braking, given the current speed
364 : * (depends on the numerical update scheme and its step width)
365 : * Note that it wouldn't have to depend on the numerical update
366 : * scheme if the semantics would rely on acceleration instead of velocity.
367 : *
368 : * @param[in] speed The vehicle's current speed
369 : * @param[in] speed The vehicle itself, for obtaining other values, if needed as e.g. road conditions.
370 : * @return The minimum possible speed for the next step
371 : */
372 : virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
373 :
374 :
375 : /** @brief Returns the distance the vehicle needs to halt including driver's reaction time tau (i.e. desired headway),
376 : * assuming that during the reaction time, the speed remains constant
377 : * @param[in] speed The vehicle's current speed
378 : * @return The distance needed to halt
379 : */
380 : double brakeGap(const double speed) const {
381 1458947272 : return brakeGap(speed, myDecel, myHeadwayTime);
382 : }
383 :
384 : virtual double brakeGap(const double speed, const double decel, const double headwayTime) const;
385 :
386 : static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
387 :
388 : static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
389 :
390 : /** @brief Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
391 : * @param[in] veh The vehicle itself, for obtaining other values
392 : * @param[in] pred The leader vehicle, for obtaining other values
393 : * @param[in] speed EGO's speed
394 : * @param[in] leaderSpeed LEADER's speed
395 : * @param[in] leaderMaxDecel LEADER's max. deceleration rate
396 : */
397 : virtual double getSecureGap(const MSVehicle* const veh, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
398 :
399 : virtual /** @brief Returns the velocity after maximum deceleration
400 : * @param[in] v The velocity
401 : * @return The velocity after maximum deceleration
402 : */
403 2019869 : inline double getSpeedAfterMaxDecel(double v) const {
404 2019869 : return MAX2(0., v - ACCEL2SPEED(myDecel));
405 : }
406 : /// @}
407 :
408 : /** @brief Computes the minimal time needed to cover a distance given the desired speed at arrival.
409 : * @param[in] dist Distance to be covered
410 : * @param[in] currentSpeed Actual speed of vehicle
411 : * @param[in] arrivalSpeed Desired speed at arrival
412 : */
413 : SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
414 :
415 :
416 : /** @brief Computes the time needed to travel a distance dist given an initial speed
417 : * and constant acceleration. The speed during traveling is assumed not to exceed the max speed.
418 : * @param[in] dist Distance to be covered (assumed >= 0.)
419 : * @param[in] speed Initial speed of vehicle
420 : * @param[in] accel Assumed acceleration until reaching maxspeed or speed=0.
421 : * @return Returns the estimated time needed to cover the given distance
422 : * If distance will never be covered with the given parameters INVALID_DOUBLE (from MSLink.h) is returned.
423 : */
424 : static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
425 :
426 : /** @brief Computes the time needed to travel a distance dist given an initial speed, arrival speed,
427 : * constant acceleration and deceleration. The speed during traveling is assumed not to exceed the max speed.
428 : * @param[in] dist Distance to be covered (assumed >= 0.)
429 : * @param[in] initialSpeed Initial speed of vehicle
430 : * @param[in] arrivalSpeed desired arrival speed of vehicle
431 : * @param[in] accel Assumed acceleration until reaching maxspeed.
432 : * @param[in] accel Assumed deceleration until reaching targetspeed.
433 : * @return Returns the estimated time needed to cover the given distance
434 : * If distance will never be covered with the given parameters INVALID_DOUBLE (from MSLink.h) is returned.
435 : * @note Currently, this is still a stub for actually very special situations in LC context:
436 : * It is assumed that 0==initialSpeed==arrivalSpeed<=maxspeed, accel==decel>0 (because currently
437 : * this is only used for lane change purposes, where lateral accel == lateral decel)
438 : */
439 : static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
440 :
441 : /** @brief Computes the acceleration needed to arrive not before the given time
442 : * @param[in] dist - the distance of the critical point
443 : * @param[in] time - the time after which an arrival at dist is allowed
444 : * @param[in] speed - the current speed
445 : * @return Returns the acceleration which would ensure an arrival at distance dist earliest for the given time
446 : */
447 : static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
448 :
449 :
450 : /** @brief Computes the minimal possible arrival speed after covering a given distance
451 : * @param[in] dist Distance to be covered
452 : * @param[in] currentSpeed Actual speed of vehicle
453 : */
454 : double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
455 :
456 : /** @brief Computes the minimal possible arrival speed after covering a given distance for Euler update
457 : * @param[in] dist Distance to be covered
458 : * @param[in] currentSpeed Actual speed of vehicle
459 : */
460 : double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
461 :
462 :
463 : /** @brief return the resulting gap if, starting with gap currentGap, two vehicles
464 : * continue with constant accelerations (velocities bounded by 0 and maxSpeed) for
465 : * a given timespan of length 'duration'.
466 : * @param[in] currentGap (pos(veh1) - pos(veh2) at start)
467 : * @param[in] v1 initial speed of vehicle 1
468 : * @param[in] v2 initial speed of vehicle 2
469 : * @param[in] a1 acceleration of vehicle 1
470 : * @param[in] a2 acceleration of vehicle 2
471 : * @param[in] maxV1 maximal speed of vehicle 1
472 : * @param[in] maxV2 maximal speed of vehicle 2
473 : * @param[in] duration time span for the process
474 : * @return estimated gap after 'duration' seconds
475 : */
476 : static double gapExtrapolation(const double duration, const double currentGap, double v1, double v2, double a1 = 0, double a2 = 0, const double maxV1 = std::numeric_limits<double>::max(), const double maxV2 = std::numeric_limits<double>::max());
477 :
478 : /**
479 : * @brief Calculates the time at which the position passedPosition has been passed
480 : * In case of a ballistic update, the possibility of a stop within a time step
481 : * requires more information about the last time-step than in case of the euler update
482 : * to determine the last position if the currentSpeed is zero.
483 : * @param[in] lastPos the position at time t=0 (must be < currentPos)
484 : * @param[in] passedPos the position for which the passing time is to be determined (has to lie within [lastPos, currentPos]!)
485 : * @param[in] currentPos the position at time t=TS (one time-step after lastPos) (must be > lastPos)
486 : * @param[in] lastSpeed the speed at moment t=0
487 : * @param[in] currentSpeed the speed at moment t=TS
488 : * @return time t in [0,TS] at which passedPos in [lastPos, currentPos] was passed.
489 : */
490 : static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
491 :
492 :
493 :
494 : /**
495 : * @brief Calculates the speed after a time t \in [0,TS]
496 : * given the initial speed and the distance traveled in an interval of step length TS.
497 : * @note If the acceleration were known, this would be much nicer, but in this way
498 : * we need to reconstruct it (for the ballistic update at least, where we assume that
499 : * a stop may occur within the interval)
500 : * @param[in] t time in [0,TS] for which the speed shall be determined
501 : * @param[in] oldSpeed speed before the last time step (referred to as t == 0)
502 : * @param[in] distance covered
503 : * @return speed at time t
504 : */
505 : static double speedAfterTime(const double t, const double oldSpeed, const double dist);
506 :
507 :
508 : /// @brief calculates the distance traveled after accelerating for time t
509 : virtual double distAfterTime(double t, double speed, double accel) const;
510 :
511 :
512 :
513 : /* @brief estimate speed while accelerating for the given distance
514 : * @param[in] dist The distance during which accelerating takes place
515 : * @param[in] v The initial speed
516 : * @param[in] accel The acceleration
517 : * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
518 : * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
519 : */
520 : double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
521 :
522 : /// @name Setter methods
523 : /// @{
524 :
525 : /** @brief Sets a new value for maximum acceleration [m/s^2]
526 : * @param[in] accel The new acceleration in m/s^2
527 : */
528 200 : virtual void setMaxAccel(double accel) {
529 200 : myAccel = accel;
530 200 : }
531 :
532 :
533 : /** @brief Sets a new value for maximal comfortable deceleration [m/s^2]
534 : * @param[in] decel The new deceleration in m/s^2
535 : */
536 115318 : virtual void setMaxDecel(double decel) {
537 115656 : myDecel = decel;
538 115318 : }
539 :
540 :
541 : /** @brief Sets a new value for maximal physically possible deceleration [m/s^2]
542 : * @param[in] decel The new deceleration in m/s^2
543 : */
544 42 : virtual void setEmergencyDecel(double decel) {
545 380 : myEmergencyDecel = decel;
546 42 : }
547 :
548 :
549 : /** @brief Sets a new value for the apparent deceleration [m/s^2]
550 : * @param[in] decel The new deceleration in m/s^2
551 : */
552 23 : virtual void setApparentDecel(double decel) {
553 23 : myApparentDecel = decel;
554 23 : }
555 :
556 : /** @brief Sets a new value for the factor of minGap that must be maintained to avoid a collision event
557 : * @param[in] factor The new minGap factor
558 : */
559 : inline void setCollisionMinGapFactor(const double factor) {
560 12 : myCollisionMinGapFactor = factor;
561 12 : }
562 :
563 : /** @brief Sets a new value for driver imperfection
564 : * @param[in] accel The new driver imperfection
565 : */
566 0 : virtual void setImperfection(double imperfection) {
567 : UNUSED_PARAMETER(imperfection);
568 0 : }
569 :
570 :
571 : /** @brief Sets a new value for desired headway [s]
572 : * @param[in] headwayTime The new desired headway (in s)
573 : */
574 8816 : virtual void setHeadwayTime(double headwayTime) {
575 9254 : myHeadwayTime = headwayTime;
576 8816 : }
577 : /// @}
578 :
579 : /** @brief Returns the maximum safe velocity for following the given leader
580 : * @param[in] gap2pred The (net) distance to the LEADER
581 : * @param[in] egoSpeed The FOLLOWERS's speed
582 : * @param[in] predSpeed The LEADER's speed
583 : * @param[in] predMaxDecel The LEADER's maximum deceleration
584 : * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
585 : * @return the safe velocity
586 : */
587 : double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
588 :
589 :
590 : /** @brief Returns the minimal deceleration for following the given leader safely
591 : * @param[in] gap The (net) distance to the LEADER
592 : * @param[in] egoSpeed The FOLLOWERS's speed
593 : * @param[in] predSpeed The LEADER's speed
594 : * @param[in] predMaxDecel The LEADER's maximum deceleration
595 : * @return The minimal deceleration b>0 that, if applied constantly until a full stop,
596 : * asserts that the vehicle does not crash into the leader.
597 : * @note If b > predMaxDecel, this function actually does not calculate the tangency for the trajectories, i.e. a double root for the gap,
598 : * but applies a simpler approach following the spirit of maximumSafeFollowSpeed, where the
599 : * leader's decel is assumed as maximum of its actual value and the followers decel.
600 : */
601 : double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
602 :
603 :
604 : /** @brief Returns the maximum next velocity for stopping within gap
605 : * @param[in] gap The (net) distance to the desired stopping point
606 : * @param[in] decel The desired deceleration rate
607 : * @param[in] currentSpeed The current speed of the ego vehicle
608 : * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
609 : * @param[in] headway The desired time headway to be included in the calculations (default argument -1 induces the use of myHeadway)
610 : * @param[in] relaxEmergency Whether emergency deceleration should be reduced (at the cost of staying in a dangerous situation for longer)
611 : */
612 : double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1, bool relaxEmergency = true) const;
613 :
614 :
615 : /** @brief Returns the maximum next velocity for stopping within gap
616 : * when using the semi-implicit Euler update
617 : * @param[in] gap The (net) distance to the LEADER
618 : * @param[in] decel The desired deceleration rate
619 : * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
620 : * @param[in] headway The desired time headway to be included in the calculations (-1 induces the use of myHeadway)
621 : */
622 : double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const;
623 :
624 :
625 : /** @brief Returns the maximum next velocity for stopping within gap
626 : * when using the ballistic positional update.
627 : * @note This takes into account the driver's reaction time tau (i.e. the desired headway) and the car's current speed.
628 : * (The latter is required to calculate the distance covered in the following timestep.)
629 : * @param[in] gap The (net) distance to the desired stopping point
630 : * @param[in] decel The desired deceleration rate
631 : * @param[in] currentSpeed The current speed of the ego vehicle
632 : * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
633 : * @param[in] headway The desired time headway to be included in the calculations (default argument -1 induces the use of myHeadway)
634 : * @return the safe velocity (to be attained at the end of the following time step) that assures the possibility of stopping within gap.
635 : * If a negative value is returned, the required stop has to take place before the end of the time step.
636 : */
637 : double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
638 :
639 : /**
640 : * @brief try to get the given parameter for this carFollowingModel
641 : *
642 : * @param[in] veh the vehicle from which the parameter must be retrieved
643 : * @param[in] key the key of the parameter
644 : * @return the value of the requested parameter
645 : */
646 0 : virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
647 : UNUSED_PARAMETER(veh);
648 : UNUSED_PARAMETER(key);
649 0 : return "";
650 : }
651 :
652 : /**
653 : * @brief try to set the given parameter for this carFollowingModel
654 : *
655 : * @param[in] veh the vehicle for which the parameter must be set
656 : * @param[in] key the key of the parameter
657 : * @param[in] value the value to be set for the given parameter
658 : */
659 5 : virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
660 : UNUSED_PARAMETER(veh);
661 : UNUSED_PARAMETER(key);
662 : UNUSED_PARAMETER(value);
663 10 : throw InvalidArgument("Setting parameter '" + key + "' is not supported by carFollowModel");
664 : }
665 :
666 : protected:
667 :
668 : /** @brief Overwrites sped by the perceived values obtained from the vehicle's driver state,
669 : * @see MSCFModel_Krauss::freeSpeed()
670 : * @param[in] veh The vehicle (EGO)
671 : * @param[in, out] speed The vehicle's speed
672 : */
673 : void applyOwnSpeedPerceptionError(const MSVehicle* const veh, double& speed) const;
674 :
675 : /** @brief Overwrites gap2pred and predSpeed by the perceived values obtained from the vehicle's driver state,
676 : * @see MSCFModel_Krauss::stopSpeed() and MSCFModel_Krauss::followSpeed() for integration into a CF model
677 : * @param[in] veh The vehicle (EGO)
678 : * @param[in] speed The vehicle's speed
679 : * @param[in, out] gap2pred The (net) distance to the LEADER
680 : * @param[in, out] predSpeed The speed of LEADER
681 : * @param[in] pred The leading vehicle (LEADER)
682 : */
683 : void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
684 :
685 : /** @brief Overwrites gap by the perceived value obtained from the vehicle's driver state
686 : * @param[in] veh The vehicle (EGO)
687 : * @param[in] speed The vehicle's speed
688 : * @param[in, out] gap The (net) distance to the obstacle
689 : */
690 : void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
691 :
692 :
693 : protected:
694 : /// @brief The type to which this model definition belongs to
695 : const MSVehicleType* myType;
696 :
697 : /// @brief The vehicle's maximum acceleration [m/s^2]
698 : double myAccel;
699 :
700 : /// @brief The vehicle's maximum deceleration [m/s^2]
701 : double myDecel;
702 : /// @brief The vehicle's maximum emergency deceleration [m/s^2]
703 : double myEmergencyDecel;
704 : /// @brief The vehicle's deceleration as expected by surrounding traffic [m/s^2]
705 : double myApparentDecel;
706 : /// @brief The factor of minGap that must be maintained to avoid a collision event
707 : double myCollisionMinGapFactor;
708 :
709 : /// @brief The driver's desired time headway (aka reaction time tau) [s]
710 : double myHeadwayTime;
711 :
712 : /// @brief The startup delay after halting [s]
713 : SUMOTime myStartupDelay;
714 :
715 :
716 :
717 : };
|