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_IDMTest.cpp
11 /// @author Jakob Erdmann
12 /// @author Michael Behrisch
13 /// @date 2013-06-05
14 /// @version $Id$
15 ///
16 // Tests the cfmodel functions
17 /****************************************************************************/
18
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23
24 #include <gtest/gtest.h>
25 #include <utils/vehicle/SUMOVTypeParameter.h>
26 #include <utils/vehicle/SUMOVehicleParameter.h>
27 #include <utils/options/OptionsCont.h>
28 #include <microsim/MSGlobals.h>
29 #include <microsim/MSFrame.h>
30 #include <microsim/MSVehicleType.h>
31 #include <microsim/MSVehicle.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSRoute.h>
34 #include <microsim/cfmodels/MSCFModel_IDM.h>
35
36
37 class MSVehicleMock : public MSVehicle {
38 public:
MSVehicleMock(SUMOVehicleParameter * pars,const MSRoute * route,MSVehicleType * type,const double speedFactor)39 MSVehicleMock(SUMOVehicleParameter* pars, const MSRoute* route,
40 MSVehicleType* type, const double speedFactor):
41 MSVehicle(pars, route, type, speedFactor) {}
42
43 };
44
45
46 class MSCFModel_IDMTest : public testing::Test {
47 protected :
48 MSVehicleType* type;
49 SUMOVehicleParameter* defs;
50 MSVehicle* veh;
51 MSRoute* route;
52 MSEdge* edge;
53 MSLane* lane;
54 double accel;
55 double decel;
56 double dawdle;
57 double tau; // headway time
58
SetUp()59 virtual void SetUp(){
60 if (!OptionsCont::getOptions().exists("step-length")) {
61 MSFrame::fillOptions();
62 }
63 MSLane::initRNGs(OptionsCont::getOptions());
64 tau = 1;
65 MSGlobals::gUnitTests = true;
66 defs = new SUMOVehicleParameter();
67 defs->departLaneProcedure = DEPART_LANE_GIVEN;
68 SUMOVTypeParameter typeDefs("t0");
69 typeDefs.cfModel = SUMO_TAG_CF_IDM;
70 //typeDefs.cfParameter[SUMO_ATTR_CF_IDM_STEPPING] = "1";
71 ConstMSEdgeVector edges;
72 MSEdge* edge = new MSEdge("dummy", 0, EDGEFUNC_NORMAL, "", "", -1);
73 MSLane* lane = new MSLane("dummy_0", 50 / 3.6, 100, edge, 0, PositionVector(), SUMO_const_laneWidth, SVCAll, 0, false);
74 std::vector<MSLane*> lanes;
75 lanes.push_back(lane);
76 edge->initialize(&lanes);
77 edges.push_back(edge);
78 route = new MSRoute("dummyRoute", edges, true, 0, defs->stops);
79 type = MSVehicleType::build(typeDefs);
80 veh = new MSVehicleMock(defs, route, type, 1);
81 veh->setTentativeLaneAndPosition(lane, 0);
82 MSGlobals::gSemiImplicitEulerUpdate = true;
83 }
84
TearDown()85 virtual void TearDown(){
86 delete veh;
87 delete type;
88 delete route;
89 }
90 };
91
92 /* Test the method 'brakeGap'.*/
93
TEST_F(MSCFModel_IDMTest,test_method_brakeGap)94 TEST_F(MSCFModel_IDMTest, test_method_brakeGap) {
95 // discrete braking model. keep driving for 1 s
96 MSCFModel& m = type->getCarFollowModel();
97 const double v = 3;
98 EXPECT_DOUBLE_EQ(tau * v, m.brakeGap(v));
99 }
100
TEST_F(MSCFModel_IDMTest,test_method_getSecureGap)101 TEST_F(MSCFModel_IDMTest, test_method_getSecureGap) {
102 // the value of getSecureGap should be consistent with followSpeed so that
103 // strong braking is avoided after lane changing (#4517)
104 MSCFModel& m = type->getCarFollowModel();
105 for (double v = 0; v < 15; v += 1) { // follower
106 for (double u = 0; u < 25; u += 1) { // leader
107 double sg = m.getSecureGap(v, u, m.getMaxDecel());
108 double vFollow = m.followSpeed(veh, v, sg, u, m.getMaxDecel(), nullptr);
109 double accel = SPEED2ACCEL(vFollow - v);
110 //std::cout << v << " " << u << " " << sg << " " << vFollow << " " << accel << "\n";
111 EXPECT_GT(accel, -2.2);
112 }
113 }
114 }
115
116
117
118