double MSCFModel::finalizeSpeed(MSVehicle* const veh, double vPos) const { // save old v for optional acceleration computation const double oldV = veh->getSpeed(); // process stops (includes update of stopping state) const double vStop = MIN2(vPos, veh->processNextStop(vPos)); // apply deceleration bounds const double vMinEmergency = minNextSpeedEmergency(oldV, veh); // vPos contains the uppper bound on safe speed. allow emergency braking here const double vMin = MIN2(minNextSpeed(oldV, veh), MAX2(vPos, vMinEmergency)); // aMax: Maximal admissible acceleration until the next action step, such that the vehicle's maximal // desired speed on the current lane will not be exceeded when the // acceleration is maintained until the next action step. double aMax = (veh->getLane()->getVehicleMaxSpeed(veh) - oldV) / veh->getActionStepLengthSecs(); // apply planned speed constraints and acceleration constraints double vMax = MIN3(oldV + ACCEL2SPEED(aMax), maxNextSpeed(oldV, veh), vStop); // do not exceed max decel even if it is unsafe #ifdef _DEBUG //if (vMin > vMax) { // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ")."); //} #endif #ifdef DEBUG_FINALIZE_SPEED if DEBUG_COND { std::cout << "\n" << SIMTIME << " FINALIZE_SPEED\n"; } #endif vMax = MAX2(vMin, vMax); // apply further speed adaptations double vNext = patchSpeedBeforeLC(veh, vMin, vMax); #ifdef DEBUG_FINALIZE_SPEED double vDawdle = vNext; #endif assert(vNext >= vMin); assert(vNext <= vMax); // apply lane-changing related speed adaptations vNext = veh->getLaneChangeModel().patchSpeed(vMin, vNext, vMax, *this); assert(vNext >= vMin); assert(vNext <= vMax); #ifdef DEBUG_FINALIZE_SPEED if DEBUG_COND { std::cout << std::setprecision(gPrecision) << "veh '" << veh->getID() << "' oldV=" << oldV << " vPos" << vPos << " vMin=" << vMin << " vMax=" << vMax << " vStop=" << vStop << " vDawdle=" << vDawdle << " vNext=" << vNext << "\n"; } #endif return vNext; }
double MSCFModel_ACC::finalizeSpeed(MSVehicle* const veh, double vPos) const { const double oldV = veh->getSpeed(); // save old v for optional acceleration computation const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops // we need the acceleration for emission computation; // in this case, we neglect dawdling, nonetheless, using // vSafe does not incorporate speed reduction due to interaction // on lane changing // const double vMin = getSpeedAfterMaxDecel(oldV); const double vMin = minNextSpeed(oldV); const double vMax = MAX2(vMin, MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe)); #ifdef _DEBUG //if (vMin > vMax) { // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ")."); //} #endif return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, vMax), vMax, *this); }