49 double decel,
double emergencyDecel,
double apparentDecel,
double headwayTime) :
53 myEmergencyDecel(emergencyDecel),
54 myApparentDecel(apparentDecel),
55 myHeadwayTime(headwayTime) {
71 const int steps = int(speed / speedReduction);
72 return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * headwayTime;
78 return speed * (headwayTime + 0.5 * speed / decel);
85 MSCFModel::freeSpeed(
const double currentSpeed,
const double decel,
const double dist,
const double targetSpeed,
const bool onInsertion) {
101 const double y =
MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
102 const double yFull = floor(y);
103 const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
104 const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) *
ACCEL2SPEED(decel);
105 return DIST2SPEED(
MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
120 assert(currentSpeed >= 0);
121 assert(targetSpeed >= 0);
123 const double dt = onInsertion ? 0 :
TS;
124 const double v0 = currentSpeed;
125 const double vT = targetSpeed;
126 const double b = decel;
136 if (0.5 * (v0 + vT)*dt >= d) {
140 const double q = ((dt * v0 - 2 * d) * b - vT * vT);
141 const double p = 0.5 * b * dt;
142 return -p + sqrt(p * p - q);
148 const double oldV = veh->
getSpeed();
170 vNext =
MAX2(vNext, vMin);
183 const double gap = (vNext - vL) *
241 const double accelTime = (arrivalSpeed - currentSpeed) / accel;
242 const double accelWay = accelTime * (arrivalSpeed + currentSpeed) * 0.5;
243 const double nonAccelWay =
MAX2(0., dist - accelWay);
247 return TIME2STEPS(accelTime + nonAccelWay / nonAccelSpeed);
260 double arrivalSpeedBraking;
263 if (dist < currentSpeed) {
271 return arrivalSpeedBraking;
278 MSCFModel::gapExtrapolation(
const double duration,
const double currentGap,
double v1,
double v2,
double a1,
double a2,
const double maxV1,
const double maxV2) {
280 double newGap = currentGap;
283 for (
unsigned int steps = 1; steps *
TS <= duration; ++steps) {
284 v1 =
MIN2(
MAX2(v1 + a1, 0.), maxV1);
285 v2 =
MIN2(
MAX2(v2 + a2, 0.), maxV2);
286 newGap += TS * (v1 - v2);
291 double t1 = 0, t2 = 0, t3 = 0, t4 = 0;
294 if (a1 < 0 && v1 > 0) {
295 const double leaderStopTime = - v1 / a1;
296 t1 =
MIN2(leaderStopTime, duration);
297 }
else if (a1 >= 0) {
301 if (a2 < 0 && v2 > 0) {
302 const double followerStopTime = -v2 / a2;
303 t2 =
MIN2(followerStopTime, duration);
304 }
else if (a2 >= 0) {
308 if (a1 > 0 && v1 < maxV1) {
309 const double leaderMaxSpeedTime = (maxV1 - v1) / a1;
310 t3 =
MIN2(leaderMaxSpeedTime, duration);
311 }
else if (a1 <= 0) {
315 if (a2 > 0 && v2 < maxV2) {
316 const double followerMaxSpeedTime = (maxV2 - v2) / a2;
317 t4 =
MIN2(followerMaxSpeedTime, duration);
318 }
else if (a2 <= 0) {
330 std::list<double>::const_iterator i;
332 for (i = l.begin(); i != l.end(); ++i) {
334 double dt =
MIN2(*i, duration) - tLast;
337 newGap += dv * dt + da * dt * dt / 2.;
341 if (*i == t1 || *i == t3) {
346 if (*i == t2 || *i == t4) {
351 tLast =
MIN2(*i, duration);
352 if (tLast == duration) {
357 if (duration != tLast) {
359 assert(a1 == 0. && a2 == 0.);
360 double dt = duration - tLast;
372 MSCFModel::passingTime(
const double lastPos,
const double passedPos,
const double currentPos,
const double lastSpeed,
const double currentSpeed) {
374 assert(passedPos <= currentPos && passedPos >= lastPos && currentPos > lastPos);
375 assert(currentSpeed >= 0);
377 if (passedPos > currentPos || passedPos < lastPos) {
378 std::stringstream ss;
382 ss <<
"passingTime(): given argument passedPos = " << passedPos <<
" doesn't lie within [lastPos, currentPos] = [" << lastPos <<
", " << currentPos <<
"]\nExtrapolating...";
383 std::cout << ss.str() <<
"\n";
386 const double lastCoveredDist = currentPos - lastPos;
387 const double extrapolated = passedPos > currentPos ?
TS * (passedPos - lastPos) / lastCoveredDist :
TS * (currentPos - passedPos) / lastCoveredDist;
389 }
else if (currentSpeed < 0) {
390 WRITE_ERROR(
"passingTime(): given argument 'currentSpeed' is negative. This case is not handled yet.");
394 const double distanceOldToPassed = passedPos - lastPos;
398 const double t = distanceOldToPassed / currentSpeed;
406 if (currentSpeed > 0) {
411 assert(currentSpeed == 0 && lastSpeed != 0);
415 a = lastSpeed * lastSpeed / (2 * (lastPos - currentPos));
424 const double t = 2 * distanceOldToPassed / (lastSpeed + currentSpeed);
428 const double va = lastSpeed / a;
429 const double t = -va + sqrt(va * va + 2 * distanceOldToPassed / a);
430 assert(t < 1 && t >= 0);
434 const double va = lastSpeed / a;
435 const double t = -va - sqrt(va * va + 2 * distanceOldToPassed / a);
436 assert(t < 1 && t >= 0);
446 assert(t >= 0 && t <=
TS);
454 if (dist <
TS * v0 / 2) {
457 const double accel = - v0 * v0 / (2 * dist);
459 return v0 + accel * t;
462 const double accel = 2 * (dist /
TS - v0) /
TS;
464 return v0 + accel * t;
476 (double)sqrt(2 * dist * accel + v * v)));
500 const double g = gap;
510 const double n = floor(.5 - ((t + (sqrt(((s * s) + (4.0 * ((s * (2.0 * g / b - t)) + (t * t))))) * -0.5)) / s));
511 const double h = 0.5 * n * (n - 1) * b * s + n * b * t;
515 const double r = (g - h) / (n * s + t);
516 const double x = n * b + r;
541 const double btau =
myDecel * headway;
542 const double v0 = -btau + sqrt(btau * btau + 2 *
myDecel * g);
551 const double tau = headway;
552 const double v0 =
MAX2(0., v);
554 if (v0 * tau >= 2 * g) {
566 const double a = -v0 * v0 / (2 * g);
581 const double btau2 =
myDecel * tau / 2;
582 const double v1 = -btau2 + sqrt(btau2 * btau2 +
myDecel * (2 * g - tau * v0));
583 const double a = (v1 - v0) / tau;
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time, assuming that during...
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false) const
Computes the vehicle's safe speed without a leader.
Representation of a vehicle in the micro simulation.
const MSVehicleType * myType
The type to which this model definition belongs to.
virtual ~VehicleVariables()
MSLane * getLane() const
Returns the lane the vehicle is on.
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...
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
virtual 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...
virtual double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage...
The car-following model and parameter.
MSAbstractLaneChangeModel & getLaneChangeModel()
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
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.
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
double getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
double myDecel
The vehicle's maximum deceleration [m/s^2].
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())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
virtual ~MSCFModel()
Destructor.
static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
double maximumSafeStopSpeedEuler(double gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update...
virtual double getHeadwayTime() const
Get the driver's reaction time [s].
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
MSCFModel(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime)
Constructor.
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
static bool gSemiImplicitEulerUpdate
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
double getSpeed() const
Returns the vehicle's current speed.
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...