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