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