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