50 : myType(vtype), myAccel(accel), myDecel(decel), myHeadwayTime(headwayTime) {
66 const int steps = int(speed / speedReduction);
67 return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * headwayTime;
73 return speed * (headwayTime + 0.5 * speed / decel);
98 const SUMOReal y =
MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
100 const SUMOReal exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
117 assert(currentSpeed >= 0);
118 assert(targetSpeed >= 0);
133 if (0.5 * (v0 + vT)*dt >= d) {
137 const SUMOReal q = ((dt * v0 - 2 * d) * b - vT * vT);
139 return -p + sqrt(p * p - q);
167 vNext =
MAX2(vNext, vMin);
236 const SUMOReal accelTime = (arrivalSpeed - currentSpeed) / accel;
237 const SUMOReal accelWay = accelTime * (arrivalSpeed + currentSpeed) * 0.5;
242 return TIME2STEPS(accelTime + nonAccelWay / nonAccelSpeed);
258 if (dist < currentSpeed) {
266 return arrivalSpeedBraking;
278 for (
unsigned int steps = 1; steps *
TS <= duration; ++steps) {
281 newGap += TS * (v1 - v2);
286 SUMOReal t1 = 0, t2 = 0, t3 = 0, t4 = 0;
289 if (a1 < 0 && v1 > 0) {
290 const SUMOReal leaderStopTime = - v1 / a1;
291 t1 =
MIN2(leaderStopTime, duration);
292 }
else if (a1 >= 0) {
296 if (a2 < 0 && v2 > 0) {
297 const SUMOReal followerStopTime = -v2 / a2;
298 t2 =
MIN2(followerStopTime, duration);
299 }
else if (a2 >= 0) {
303 if (a1 > 0 && v1 < maxV1) {
304 const SUMOReal leaderMaxSpeedTime = (maxV1 - v1) / a1;
305 t3 =
MIN2(leaderMaxSpeedTime, duration);
306 }
else if (a1 <= 0) {
310 if (a2 > 0 && v2 < maxV2) {
311 const SUMOReal followerMaxSpeedTime = (maxV2 - v2) / a2;
312 t4 =
MIN2(followerMaxSpeedTime, duration);
313 }
else if (a2 <= 0) {
319 std::list<SUMOReal> l;
325 std::list<SUMOReal>::const_iterator i;
327 for (i = l.begin(); i != l.end(); ++i) {
332 newGap += dv * dt + da * dt * dt / 2.;
336 if (*i == t1 || *i == t3) {
341 if (*i == t2 || *i == t4) {
346 tLast =
MIN2(*i, duration);
347 if (tLast == duration) {
352 if (duration != tLast) {
354 assert(a1 == 0. && a2 == 0.);
369 assert(passedPos <= currentPos && passedPos >= lastPos && currentPos > lastPos);
370 assert(currentSpeed >= 0);
372 if (passedPos > currentPos || passedPos < lastPos) {
373 std::stringstream ss;
377 ss <<
"passingTime(): given argument passedPos = " << passedPos <<
" doesn't lie within [lastPos, currentPos] = [" << lastPos <<
", " << currentPos <<
"]\nExtrapolating...";
378 std::cout << ss.str() <<
"\n";
381 const SUMOReal lastCoveredDist = currentPos - lastPos;
382 const SUMOReal extrapolated = passedPos > currentPos ?
TS * (passedPos - lastPos) / lastCoveredDist :
TS * (currentPos - passedPos) / lastCoveredDist;
384 }
else if (currentSpeed < 0) {
385 WRITE_ERROR(
"passingTime(): given argument 'currentSpeed' is negative. This case is not handled yet.");
389 const SUMOReal distanceOldToPassed = passedPos - lastPos;
393 const SUMOReal t = distanceOldToPassed / currentSpeed;
401 if (currentSpeed > 0) {
406 assert(currentSpeed == 0 && lastSpeed != 0);
410 a = lastSpeed * lastSpeed / (2 * (lastPos - currentPos));
419 const SUMOReal t = 2 * distanceOldToPassed / (lastSpeed + currentSpeed);
424 const SUMOReal t = -va + sqrt(va * va + 2 * distanceOldToPassed / a);
425 assert(t < 1 && t >= 0);
430 const SUMOReal t = -va - sqrt(va * va + 2 * distanceOldToPassed / a);
431 assert(t < 1 && t >= 0);
441 assert(t >= 0 && t <=
TS);
449 if (dist <
TS * v0 / 2) {
452 const SUMOReal accel = - v0 * v0 / (2 * dist);
454 return v0 + accel * t;
459 return v0 + accel * t;
471 (
SUMOReal)sqrt(2 * dist * accel + v * v)));
505 const SUMOReal n = floor(.5 - ((t + (sqrt(((s * s) + (4.0 * ((s * (2.0 * g / b - t)) + (t * t))))) * -0.5)) / s));
506 const SUMOReal h = 0.5 * n * (n - 1) * b * s + n * b * t;
510 const SUMOReal r = (g - h) / (n * s + t);
549 if (v0 * tau >= 2 * g) {
561 const SUMOReal a = -v0 * v0 / (2 * g);
577 const SUMOReal v1 = -btau2 + sqrt(btau2 * btau2 +
myDecel * (2 * g - tau * v0));
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Representation of a vehicle in the micro simulation.
const MSVehicleType * myType
The type to which this model definition belongs to.
virtual SUMOReal insertionFollowSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage...
SUMOReal maximumSafeStopSpeedBallistic(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion=false, SUMOReal headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update...
virtual ~VehicleVariables()
MSLane * getLane() const
Returns the lane the vehicle is on.
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
MSCFModel(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime)
Constructor.
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
SUMOReal processNextStop(SUMOReal currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
SUMOReal maximumSafeStopSpeedEuler(SUMOReal gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
SUMOReal minNextSpeed(SUMOReal speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
The car-following model and parameter.
MSAbstractLaneChangeModel & getLaneChangeModel()
SUMOReal getMinimalArrivalSpeedEuler(SUMOReal dist, SUMOReal currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
static SUMOReal speedAfterTime(const SUMOReal t, const SUMOReal oldSpeed, const SUMOReal dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
SUMOTime getMinimalArrivalTime(SUMOReal dist, SUMOReal currentSpeed, SUMOReal arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
virtual SUMOReal getHeadwayTime() const
Get the driver's reaction time [s].
virtual SUMOReal freeSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed, const bool onInsertion=false) const
Computes the vehicle's safe speed without a leader.
static SUMOReal passingTime(const SUMOReal lastPos, const SUMOReal passedPos, const SUMOReal currentPos, const SUMOReal lastSpeed, const SUMOReal currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
SUMOReal getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
SUMOReal maximumSafeStopSpeed(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion=false, SUMOReal headway=-1) const
Returns the maximum next velocity for stopping within gap.
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time, assuming that during...
virtual ~MSCFModel()
Destructor.
SUMOReal estimateSpeedAfterDistance(const SUMOReal dist, const SUMOReal v, const SUMOReal accel) const
SUMOReal getMinimalArrivalSpeed(SUMOReal dist, SUMOReal currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change.
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
const SUMOReal SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
static bool gSemiImplicitEulerUpdate
static SUMOReal gapExtrapolation(const SUMOReal duration, const SUMOReal currentGap, SUMOReal v1, SUMOReal v2, SUMOReal a1=0, SUMOReal a2=0, const SUMOReal maxV1=std::numeric_limits< SUMOReal >::max(), const SUMOReal maxV2=std::numeric_limits< SUMOReal >::max())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual SUMOReal interactionGap(const MSVehicle *const veh, SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
SUMOReal getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
virtual SUMOReal insertionStopSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap) const
Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints due to...