Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/unittest/src/microsim/MSCFModel_IDMTest.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
MSVehicleMock(SUMOVehicleParameter* pars, ConstMSRoutePtr route,
43
MSVehicleType* type, const double speedFactor):
44
MSVehicle(pars, route, type, speedFactor) {}
45
46
};
47
48
49
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
virtual void SetUp() {
63
if (!OptionsCont::getOptions().exists("step-length")) {
64
MSFrame::fillOptions();
65
}
66
MSLane::initRNGs(OptionsCont::getOptions());
67
tau = 1;
68
MSGlobals::gUnitTests = true;
69
defs = new SUMOVehicleParameter();
70
defs->departLaneProcedure = DepartLaneDefinition::GIVEN;
71
SUMOVTypeParameter typeDefs("t0");
72
typeDefs.cfModel = SUMO_TAG_CF_IDM;
73
//typeDefs.cfParameter[SUMO_ATTR_CF_IDM_STEPPING] = "1";
74
ConstMSEdgeVector edges;
75
MSEdge* dummyEdge = new MSEdge("dummy", 0, SumoXMLEdgeFunc::NORMAL, "", "", -1, 0);
76
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
lanes.push_back(dummyLane);
79
dummyEdge->initialize(&lanes);
80
edges.push_back(dummyEdge);
81
route = std::make_shared<MSRoute>("dummyRoute", edges, true, nullptr, defs->stops);
82
MSGlobals::gActionStepLength = DELTA_T;
83
type = MSVehicleType::build(typeDefs);
84
veh = new MSVehicleMock(defs, route, type, 1);
85
veh->setTentativeLaneAndPosition(dummyLane, 0);
86
veh->initDevices();
87
}
88
89
virtual void TearDown() {
90
delete veh;
91
delete type;
92
}
93
};
94
95
/* Test the method 'brakeGap'.*/
96
97
TEST_F(MSCFModel_IDMTest, test_method_brakeGap) {
98
// discrete braking model. keep driving for 1 s
99
MSCFModel& m = type->getCarFollowModel();
100
const double v = 3;
101
EXPECT_DOUBLE_EQ(tau * v, m.brakeGap(v));
102
}
103
104
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
MSCFModel& m = type->getCarFollowModel();
108
for (double v = 0; v < 15; v += 1) { // follower
109
for (double u = 0; u < 25; u += 1) { // leader
110
double sg = m.getSecureGap(veh, nullptr, v, u, m.getMaxDecel());
111
double vFollow = m.followSpeed(veh, v, sg, u, m.getMaxDecel(), nullptr);
112
//std::cout << v << " " << u << " " << sg << " " << vFollow << " " << SPEED2ACCEL(vFollow - v) << "\n";
113
EXPECT_GT(SPEED2ACCEL(vFollow - v), -2.2);
114
}
115
}
116
}
117
118