47 #define EST_REAC_THRESHOLD 3.
48 #define ClutchEngageSpeed 0.5
49 #define EIDM_POS_ACC_EPS 0.05
56 myTwoSqrtAccelDecel(double(2 * sqrt(myAccel * myDecel))),
119 x = (-b + sqrt(b * b - 4.*a * c)) / (2.*a);
129 if (origSafeDecel >
myDecel + NUMERICAL_EPS) {
136 #ifdef DEBUG_EMERGENCYDECEL
138 std::cout <<
SIMTIME <<
" initial vsafe=" << x
139 <<
" egoSpeed=" << egoSpeed <<
" (origSafeDecel=" << origSafeDecel <<
")"
140 <<
" predSpeed=" << predSpeed <<
" (predDecel=" << predMaxDecel <<
")"
141 <<
" safeDecel=" << safeDecel
148 safeDecel =
MIN2(safeDecel, origSafeDecel);
154 #ifdef DEBUG_EMERGENCYDECEL
156 std::cout <<
" -> corrected emergency deceleration: " << safeDecel << std::endl;
163 assert(!std::isnan(x));
171 const double g = gap - NUMERICAL_EPS;
186 vsafe = (-b + sqrt(b * b - 4.*a * c)) / (2.*a);
210 const double minGapStop_EPS = 0.05 + 0.20 *
MAX2(0.25,
myAccel);
214 const double criticality =
MIN2(
MAX2(s / vars->
mys_est - 0.5, -0.4), 0.0);
216 const double drivingerror =
mySigmaerror * vars->
myw_error * intensity * (2.75 * 2.75 * criticality * criticality + 1.0);
231 if (newSpeed == 0 || newSpeed <= currentSpeed) {
235 double remainingDelay = 0.0;
236 if (newSpeed != vMax) {
240 double v_corr = currentSpeed;
255 v_corr = v_corr + (newSpeed - currentSpeed) /
myIterations;
267 const double oldV = veh->
getSpeed();
274 for (
auto it = vars->
stop.cbegin(); it != vars->
stop.cend(); ++it) {
275 if (vPos > oldV +
ACCEL2SPEED(it->first) - NUMERICAL_EPS && vPos < oldV +
ACCEL2SPEED(it->first) + NUMERICAL_EPS) {
276 _vPos =
_v(veh, it->second, oldV, 0, vars->
v0_int,
false, 1, CalcReason::CURRENT);
289 vMax =
MAX2(vMin, vMax);
294 <<
" EIDM::finalizeSpeed "
295 <<
" veh=" << veh->
getID()
298 <<
" _vPos=" << _vPos
299 <<
" vStop=" << vStop
300 <<
" vMinEmergency=" << vMinEmergency
325 }
else if (vNext <= oldV && vNext < vMax - NUMERICAL_EPS && oldV >
ClutchEngageSpeed * 2) {
350 vNext =
MAX2(vNext, vMin);
365 <<
" EIDM::finalizeSpeed (2) "
366 <<
" veh=" << veh->
getID()
369 <<
" addTime=" << addTime
370 <<
" vDelay=" << vDelay
372 <<
" vNext=" << vNext
397 <<
" EIDM::finalizeSpeed (3) "
398 <<
" veh=" << veh->
getID()
399 <<
" vars->myw_gap=" << vars->
myw_gap
400 <<
" vars->myw_speed=" << vars->
myw_speed
401 <<
" vars->myw_error=" << vars->
myw_error
402 <<
" vars->lastacc=" << vars->
lastacc
452 _vUsage = CalcReason::LANE_CHANGE;
454 if (_vUsage == CalcReason::LANE_CHANGE || _vUsage == CalcReason::FUTURE) {
461 <<
" EIDM::followSpeed "
462 <<
" veh=" << veh->
getID()
463 <<
" speed=" << speed
464 <<
" gap2pred=" << gap2pred
465 <<
" predSpeed=" << predSpeed
466 <<
" vars->v0_int=" << vars->
v0_int
472 double result =
_v(veh, gap2pred, speed, predSpeed, vars->
v0_int,
true,
update, _vUsage);
491 _vUsage = CalcReason::LANE_CHANGE;
493 if (_vUsage == CalcReason::LANE_CHANGE || _vUsage == CalcReason::FUTURE || usage == CalcReason::CURRENT_WAIT) {
500 <<
" EIDM::stopSpeed "
501 <<
" veh=" << veh->
getID()
502 <<
" speed=" << speed
504 <<
" vars->v0_int=" << vars->
v0_int
510 double result =
_v(veh, gap, speed, 0, vars->
v0_int,
false,
update, _vUsage);
520 MSCFModel_EIDM::freeSpeed(
const double currentSpeed,
const double decel,
const double dist,
const double targetSpeed,
const bool onInsertion) {
536 const double y =
MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
537 const double yFull = floor(y);
538 const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
539 const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) *
ACCEL2SPEED(decel);
540 return DIST2SPEED(
MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
555 assert(currentSpeed >= 0);
556 assert(targetSpeed >= 0);
558 const double dt = onInsertion ? 0 :
TS;
559 const double v0 = currentSpeed;
560 const double vT = targetSpeed;
561 const double b = decel;
562 const double d = dist - NUMERICAL_EPS;
571 if (0.5 * (v0 + vT)*dt >= d) {
575 const double q = ((dt * v0 - 2 * d) * b - vT * vT);
576 const double p = 0.5 * b * dt;
577 return -p + sqrt(p * p - q);
597 _vUsage = CalcReason::LANE_CHANGE;
599 if (_vUsage == CalcReason::LANE_CHANGE || _vUsage == CalcReason::FUTURE) {
606 <<
" EIDM::freeSpeed "
607 <<
" veh=" << veh->
getID()
608 <<
" speed=" << speed
610 <<
" maxSpeed=" << maxSpeed
612 <<
" onInsertion=" << onInsertion
619 double vSafe, remaining_time, targetDecel;
633 targetDecel = (speed - maxSpeed) / remaining_time;
666 vSafe =
_v(veh, 500., speed, maxSpeed, vars->
v0_int,
true,
update, _vUsage);
680 const double vNext = veh->
getSpeed() + acc;
681 const double gap = (vNext - vL) * (veh->
getSpeed() + vL) / (2 *
myDecel) + vL;
693 const double delta_v = speed - leaderSpeed;
709 const double delta_v = speed - leaderSpeed;
715 if (speed <= vars->v0_int) {
716 erg = sqrt((s * s) / (
MAX2(targetDecel /
myAccel + 1.0, 1.0)));
730 double v_limcurr, v_limprev;
737 std::vector<MSLink*>::const_iterator link =
MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
749 double speedlim = 200;
789 if ((*link)->getViaLane() ==
nullptr) {
792 lane = (*link)->getViaLaneOrLane();
803 if (!(v_limprev < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS) ||
804 (v_limprev < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS && !(v_limprev < v_limcurr + NUMERICAL_EPS && v_limprev > v_limcurr - NUMERICAL_EPS))) {
806 if ((v_limcurr < v_limprev + NUMERICAL_EPS && v_limcurr < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS) ||
807 (v_limcurr > v_limprev - NUMERICAL_EPS && v_limcurr > v0 - NUMERICAL_EPS && v_limprev < v0 + NUMERICAL_EPS)) {
810 if (v_limcurr >= v0 - NUMERICAL_EPS) {
818 if (v_limcurr < v0 + NUMERICAL_EPS && v_limcurr > v0 - NUMERICAL_EPS) {
826 }
else if (!(v_limprev < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS) ||
827 (v_limprev < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS && !(v_limprev < v_limcurr + NUMERICAL_EPS && v_limprev > v_limcurr - NUMERICAL_EPS))) {
829 if ((v_limcurr < v_limprev + NUMERICAL_EPS && v_limcurr < v0 + NUMERICAL_EPS && v_limprev > v0 - NUMERICAL_EPS) ||
830 (v_limcurr > v_limprev - NUMERICAL_EPS && v_limcurr > v0 - NUMERICAL_EPS && v_limprev < v0 + NUMERICAL_EPS)) {
833 if (v_limcurr >= v0 - NUMERICAL_EPS) {
841 if (v_limcurr < v0 + NUMERICAL_EPS && v_limcurr > v0 - NUMERICAL_EPS) {
852 const double predSpeed,
const double desSpeed,
const bool respectMinGap,
const int update,
const CalcReason usage)
const {
854 double v0 =
MAX2(NUMERICAL_EPS, desSpeed);
866 double wantedacc = 0., a_free;
867 double wouldacc = 0., woulds, woulda_free;
869 double estSpeed, estleaderSpeed, estGap;
870 double current_estSpeed, current_estGap, current_estleaderSpeed;
873 double a_leader = NUMERICAL_EPS;
874 double newSpeed = egoSpeed;
875 bool lastrespectMinGap = respectMinGap;
876 const double minGapStop_EPS = 0.05 + 0.20 *
MAX2(0.25,
myAccel);
884 current_gap =
MAX2(NUMERICAL_EPS, gap2pred + minGapStop_EPS);
887 double newGap = current_gap;
892 current_estSpeed = newSpeed;
898 current_estleaderSpeed = predSpeed;
901 current_estGap = newGap;
910 if (vars->
myap_update == 0 && usage == CalcReason::CURRENT) {
911 estSpeed = current_estSpeed;
912 estleaderSpeed = current_estleaderSpeed;
913 estGap = current_estGap;
914 }
else if (usage == CalcReason::CURRENT) {
923 if (lastrespectMinGap) {
935 estSpeed = current_estSpeed;
936 estleaderSpeed = current_estleaderSpeed;
937 estGap = current_estGap;
945 if (lastrespectMinGap) {
953 if (lastrespectMinGap) {
981 if (estSpeed <= v0) {
984 wantedacc =
myAccel * (1. - (s * s) / (estGap * estGap));
986 wantedacc = a_free * (1. - pow(s / estGap, 2 *
myAccel / a_free));
991 wantedacc = a_free +
myAccel * (1. - (s * s) / (estGap * estGap));
1000 if (usage == CalcReason::CURRENT) {
1001 woulds =
MAX2(0., current_estSpeed * headwayTime + current_estSpeed * (current_estSpeed - current_estleaderSpeed) /
myTwoSqrtAccelDecel);
1002 if (respectMinGap) {
1008 if (current_estSpeed <= v0) {
1009 woulda_free =
myAccel * (1. - pow(current_estSpeed / v0,
myDelta));
1010 if (woulds >= current_estGap) {
1011 wouldacc =
myAccel * (1. - (woulds * woulds) / (current_estGap * current_estGap));
1013 wouldacc = woulda_free * (1. - pow(woulds / current_estGap, 2 *
myAccel / woulda_free));
1017 if (woulds >= current_estGap) {
1018 wouldacc = woulda_free +
myAccel * (1. - (woulds * woulds) / (current_estGap * current_estGap));
1020 wouldacc = woulda_free;
1032 double calc_gap = estGap;
1045 if (estSpeed <= v0) {
1047 if (s >= calc_gap) {
1048 acc =
myAccel * (1. - (s * s) / (calc_gap * calc_gap));
1050 acc = a_free * (1. - pow(s / calc_gap, 2 *
myAccel / a_free));
1054 if (s >= calc_gap) {
1055 acc = a_free +
myAccel * (1. - (s * s) / (calc_gap * calc_gap));
1064 if (vars->
minaccel > wantedacc - NUMERICAL_EPS && usage == CalcReason::CURRENT) {
1067 if (leader !=
nullptr && lastrespectMinGap && estleaderSpeed >= SPEED_EPS) {
1070 if (estGap > s * 3 / 2) {
1071 a_leader = a_leader * (s * 3 / 2) / estGap;
1076 if (estleaderSpeed < SPEED_EPS) {
1077 estleaderSpeed = SPEED_EPS;
1083 if (estleaderSpeed * (estSpeed - estleaderSpeed) <= -2 * estGap * a_leader) {
1084 a_cah = (estSpeed * estSpeed * a_leader) / (estleaderSpeed * estleaderSpeed - 2 * estGap * a_leader);
1086 if (estSpeed - estleaderSpeed >= 0) {
1087 a_cah = a_leader - ((estSpeed - estleaderSpeed) * (estSpeed - estleaderSpeed)) / (2 * estGap);
1133 <<
" veh=" << veh->
getID()
1134 <<
" vars->minaccel=" << vars->
minaccel
1136 <<
" vars->myv_est_l=" << vars->
myv_est_l
1137 <<
" vars->myv_est=" << vars->
myv_est
1138 <<
" vars->mys_est=" << vars->
mys_est
1139 <<
" vars->wouldacc=" << vars->
wouldacc
1140 <<
" vars->realacc=" << vars->
realacc
1144 <<
" veh=" << veh->
getID()
1145 <<
" newSpeed=" << newSpeed
1146 <<
" newGap=" << newGap
1147 <<
" predSpeed=" << predSpeed
1148 <<
" estSpeed=" << estSpeed
1149 <<
" estleaderSpeed=" << estleaderSpeed
1150 <<
" estGap=" << estGap
1151 <<
" wantedacc=" << wantedacc
1152 <<
" wouldacc=" << wouldacc
1161 if (vars->
minaccel > wantedacc - NUMERICAL_EPS && vars->
myap_update == 0 && usage == CalcReason::CURRENT) {
1172 if (usage == CalcReason::CURRENT && vars->
wouldacc > wouldacc) {
1178 if (vars->
realacc > acc && vars->
minaccel <= wantedacc - NUMERICAL_EPS && usage == CalcReason::CURRENT) {
1184 if (vars->
minaccel > wantedacc - NUMERICAL_EPS && usage == CalcReason::CURRENT) {
1193 if (vars->
minaccel > wantedacc - NUMERICAL_EPS && usage == CalcReason::CURRENT_WAIT && !respectMinGap) {
1194 vars->
stop.push_back(std::make_pair(acc, gap2pred));
1197 return MAX2(0., newSpeed);
#define EMERGENCY_DECEL_AMPLIFIER
#define ClutchEngageSpeed
#define EST_REAC_THRESHOLD
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ TURN_LEFTHAND
The link is a 180 degree turn (left-hand network)
@ PARTRIGHT
The link is a partial right direction.
@ NODIR
The link has no direction (is a dead end link)
@ SUMO_ATTR_CF_EIDM_T_ACC_MAX
@ SUMO_ATTR_CF_EIDM_EPSILON_ACC
@ SUMO_ATTR_CF_EIDM_T_LOOK_AHEAD
@ SUMO_ATTR_CF_EIDM_USEVEHDYNAMICS
@ SUMO_ATTR_CF_EIDM_C_COOLNESS
@ SUMO_ATTR_CF_EIDM_SIG_ERROR
@ SUMO_ATTR_CF_EIDM_T_REACTION
@ SUMO_ATTR_CF_EIDM_T_PERSISTENCE_ESTIMATE
@ SUMO_ATTR_CF_EIDM_SIG_GAP
@ SUMO_ATTR_CF_EIDM_JERK_MAX
@ SUMO_ATTR_CF_IDM_STEPPING
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_CF_EIDM_M_FLATNESS
@ SUMO_ATTR_CF_EIDM_M_BEGIN
@ SUMO_ATTR_CF_EIDM_T_PERSISTENCE_DRIVE
@ SUMO_ATTR_CF_EIDM_SIG_LEADER
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
virtual double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
virtual bool isSelected() const
whether this vehicle is selected in the GUI
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
std::vector< std::pair< double, double > > stop
const double myTPersEstimate
double patchSpeedBeforeLCEIDM(const MSVehicle *veh, double vMin, double vMax, const VehicleVariables *vars) const
Applies dawdling / driving error.
const double myTPersDrive
~MSCFModel_EIDM()
Destructor.
const double mySigmaleader
const double myEpsilonacc
double slowToStartTerm(MSVehicle *const veh, const double newSpeed, const double currentSpeed, const double vMax, VehicleVariables *vars) const
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Returns the maximum safe velocity for following the given leader.
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage....
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
const double myTwoSqrtAccelDecel
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle.
MSCFModel_EIDM(const MSVehicleType *vtype)
Constructor.
double insertionStopSpeed(const MSVehicle *const veh, double speed, double gap) const
Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints due to...
double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
double internalsecuregap(const MSVehicle *const veh, const double speed, const double leaderSpeed, const double targetDecel) const
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed.
void internalspeedlimit(MSVehicle *const veh, const double oldV) const
double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
const double mySigmaerror
double _v(const MSVehicle *const veh, const double gap2pred, const double mySpeed, const double predSpeed, const double desSpeed, const bool respectMinGap, const int update, const CalcReason usage) const
The car-following model abstraction.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
virtual double applyStartupDelay(const MSVehicle *veh, const double vMin, const double vMax, const SUMOTime addTime=0) const
apply speed adaptation on startup
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
SUMOTime myStartupDelay
The startup delay after halting [s].
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
CalcReason
What the return value of stop/follow/free-Speed is used for.
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
double myDecel
The vehicle's maximum deceleration [m/s^2].
double myAccel
The vehicle's maximum acceleration [m/s^2].
const MSVehicleType * myType
The type to which this model definition belongs to.
double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update.
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
static bool gSemiImplicitEulerUpdate
static bool gComputeLC
whether the simulationLoop is in the lane changing phase
Representation of a lane in the micro simulation.
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
double getLength() const
Returns the lane's length.
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Representation of a vehicle in the micro simulation.
SUMOTime getTimeSinceStartup() const
Returns the SUMOTime spent driving since startup (speed was larger than 0.1m/s)
MSAbstractLaneChangeModel & getLaneChangeModel()
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
std::pair< const MSVehicle *const, double > getLeader(double dist=0) const
Returns the leader of the vehicle looking for a fixed distance.
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
double getSpeed() const
Returns the vehicle's current speed.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
double getPositionOnLane() const
Get the vehicle's position along the lane.
const MSLane * getLane() const
Returns the lane the vehicle is on.
The car-following model and parameter.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
double getMinGap() const
Get the free space in front of vehicles of this class.
const SUMOVTypeParameter & getParameter() const
const std::string & getID() const
Returns the id.
static double randNorm(double mean, double variance, SumoRNG *rng=nullptr)
Access to a random number from a normal distribution.
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.