1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSCFModel_KraussX.cpp
11 /// @author  Tobias Mayer
12 /// @author  Daniel Krajzewicz
13 /// @author  Jakob Erdmann
14 /// @author  Michael Behrisch
15 /// @author  Laura Bieker
16 /// @date    Mon, 04 Aug 2009
17 /// @version $Id$
18 ///
19 // Krauss car-following model, changing accel and speed by slope
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
29 #include <microsim/MSVehicle.h>
30 #include <microsim/MSNet.h>
31 #include "MSCFModel_KraussX.h"
32 
33 
34 #define OVERBRAKING_THRESHOLD -3
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
MSCFModel_KraussX(const MSVehicleType * vtype)39 MSCFModel_KraussX::MSCFModel_KraussX(const MSVehicleType* vtype):
40     MSCFModel_Krauss(vtype),
41     myTmp1(vtype->getParameter().getCFParam(SUMO_ATTR_TMP1, 0.0)),
42     myTmp2(vtype->getParameter().getCFParam(SUMO_ATTR_TMP2, 0.0)) {
43 }
44 
45 
~MSCFModel_KraussX()46 MSCFModel_KraussX::~MSCFModel_KraussX() {}
47 
48 
49 MSCFModel*
duplicate(const MSVehicleType * vtype) const50 MSCFModel_KraussX::duplicate(const MSVehicleType* vtype) const {
51     return new MSCFModel_KraussX(vtype);
52 }
53 
54 
55 double
patchSpeedBeforeLC(const MSVehicle * veh,double vMin,double vMax) const56 MSCFModel_KraussX::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
57     return dawdleX(veh->getSpeed(), vMin, vMax, veh->getRNG());
58 }
59 
60 
61 double
dawdleX(double vOld,double vMin,double vMax,std::mt19937 * rng) const62 MSCFModel_KraussX::dawdleX(double vOld, double vMin, double vMax, std::mt19937* rng) const {
63     double speed = vMax;
64     if (!MSGlobals::gSemiImplicitEulerUpdate) {
65         // in case of the ballistic update, negative speeds indicate
66         // a desired stop before the completion of the next timestep.
67         // We do not allow dawdling to overwrite this indication
68         if (speed < 0) {
69             return speed;
70         }
71     }
72     // extra slow to start
73     if (vOld < myAccel) {
74         speed -= ACCEL2SPEED(myTmp1 * myAccel);
75     }
76     const double random = RandHelper::rand(rng);
77     speed -= ACCEL2SPEED(myDawdle * myAccel * random);
78     // overbraking
79     if (vOld > vMax) {
80         speed -= ACCEL2SPEED(myTmp2 * myAccel * random);
81         //std::cout << " vMin=" << vMin << " vMax=" << vMax << "speed=" << speed << " d1=" << ACCEL2SPEED(myDawdle * myAccel * random) << " d2=" << ACCEL2SPEED(myTmp2 * myAccel * random) << " unexpectedDecel=" << (speed < vMin) << "\n";
82         if (MSGlobals::gSemiImplicitEulerUpdate) {
83             speed = MAX2(0.0, speed);
84         }
85     }
86     speed = MAX2(vMin, speed);
87     return speed;
88 }
89 
90 
91 
92 /****************************************************************************/
93