Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 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_KraussOrig1.cpp 15 : /// @author Tobias Mayer 16 : /// @author Daniel Krajzewicz 17 : /// @author Jakob Erdmann 18 : /// @author Michael Behrisch 19 : /// @author Laura Bieker 20 : /// @date Mon, 04 Aug 2009 21 : /// 22 : // The original Krauss (1998) car-following model and parameter 23 : /****************************************************************************/ 24 : #include <config.h> 25 : 26 : #include <microsim/MSVehicle.h> 27 : #include <microsim/MSLane.h> 28 : #include "MSCFModel_KraussOrig1.h" 29 : #include <microsim/lcmodels/MSAbstractLaneChangeModel.h> 30 : #include <utils/common/RandHelper.h> 31 : #include <microsim/MSGlobals.h> 32 : 33 : // =========================================================================== 34 : // DEBUG constants 35 : // =========================================================================== 36 : //#define DEBUG_COND (veh->getID()=="disabled") 37 : 38 : // =========================================================================== 39 : // method definitions 40 : // =========================================================================== 41 262359 : MSCFModel_KraussOrig1::MSCFModel_KraussOrig1(const MSVehicleType* vtype) : 42 : MSCFModel(vtype), 43 262359 : myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))), 44 262359 : myTauDecel(myDecel * myHeadwayTime) { 45 262359 : } 46 : 47 : 48 259483 : MSCFModel_KraussOrig1::~MSCFModel_KraussOrig1() {} 49 : 50 : double 51 5850263 : MSCFModel_KraussOrig1::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const { 52 : UNUSED_PARAMETER(veh); 53 5850263 : const double vDawdle = MAX2(vMin, dawdle(vMax, veh->getRNG())); 54 5850263 : return vDawdle; 55 : } 56 : 57 : 58 : double 59 34248669 : MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const { 60 34248669 : if (MSGlobals::gSemiImplicitEulerUpdate) { 61 33460434 : return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo) 62 : } else { 63 788235 : return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed)); 64 : } 65 : } 66 : 67 : 68 : double 69 14979285 : MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason /*usage*/) const { 70 14979285 : if (MSGlobals::gSemiImplicitEulerUpdate) { 71 14215972 : return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh)); 72 : } else { 73 : // XXX: using this here is probably in the spirit of Krauss, but we should consider, 74 : // if the original vsafe should be kept instead (Leo), refs. #2575 75 763313 : return MIN2(maximumSafeStopSpeedBallistic(gap, decel, speed), maxNextSpeed(speed, veh)); 76 : } 77 : } 78 : 79 : 80 : double 81 5850263 : MSCFModel_KraussOrig1::dawdle(double speed, SumoRNG* rng) const { 82 5850263 : if (!MSGlobals::gSemiImplicitEulerUpdate) { 83 : // in case of the ballistic update, negative speeds indicate 84 : // a desired stop before the completion of the next timestep. 85 : // We do not allow dawdling to overwrite this indication 86 389449 : if (speed < 0) { 87 : return speed; 88 : } 89 : } 90 5841158 : return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng))); 91 : } 92 : 93 : 94 : /** Returns the SK-vsafe. */ 95 47676406 : double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const { 96 47676406 : if (predSpeed == 0 && gap < 0.01) { 97 : return 0; 98 47506926 : } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) { 99 : // workaround for #2310 100 1550289 : return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap)); 101 : } 102 : double vsafe = (double)(-1. * myTauDecel 103 45956637 : + sqrt( 104 45956637 : myTauDecel * myTauDecel 105 45956637 : + (predSpeed * predSpeed) 106 45956637 : + (2. * myDecel * gap) 107 45956637 : )); 108 : assert(vsafe >= 0); 109 45956637 : return vsafe; 110 : } 111 : 112 : 113 : MSCFModel* 114 0 : MSCFModel_KraussOrig1::duplicate(const MSVehicleType* vtype) const { 115 0 : return new MSCFModel_KraussOrig1(vtype); 116 : } 117 : 118 : 119 : /****************************************************************************/