Path: blob/main/unittest/src/microsim/MSCFModel_IDMTest.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MSCFModel_IDMTest.cpp14/// @author Jakob Erdmann15/// @author Michael Behrisch16/// @date 2013-06-0517///18// Tests the cfmodel functions19/****************************************************************************/2021// ===========================================================================22// included modules23// ===========================================================================24#include <config.h>2526#include <gtest/gtest.h>27#include <utils/vehicle/SUMOVTypeParameter.h>28#include <utils/vehicle/SUMOVehicleParameter.h>29#include <utils/options/OptionsCont.h>30#include <microsim/MSGlobals.h>31#include <microsim/MSFrame.h>32#include <microsim/MSVehicleType.h>33#include <microsim/MSVehicle.h>34#include <microsim/MSEdge.h>35#include <microsim/MSRoute.h>36#include <microsim/cfmodels/MSCFModel_IDM.h>373839class MSVehicleMock : public MSVehicle {40public:41MSVehicleMock(SUMOVehicleParameter* pars, ConstMSRoutePtr route,42MSVehicleType* type, const double speedFactor):43MSVehicle(pars, route, type, speedFactor) {}4445};464748class MSCFModel_IDMTest : public testing::Test {49protected :50MSVehicleType* type;51SUMOVehicleParameter* defs;52MSVehicle* veh;53ConstMSRoutePtr route;54MSEdge* edge;55MSLane* lane;56double accel;57double decel;58double dawdle;59double tau; // headway time6061virtual void SetUp() {62if (!OptionsCont::getOptions().exists("step-length")) {63MSFrame::fillOptions();64}65MSLane::initRNGs(OptionsCont::getOptions());66tau = 1;67MSGlobals::gUnitTests = true;68defs = new SUMOVehicleParameter();69defs->departLaneProcedure = DepartLaneDefinition::GIVEN;70SUMOVTypeParameter typeDefs("t0");71typeDefs.cfModel = SUMO_TAG_CF_IDM;72//typeDefs.cfParameter[SUMO_ATTR_CF_IDM_STEPPING] = "1";73ConstMSEdgeVector edges;74MSEdge* dummyEdge = new MSEdge("dummy", 0, SumoXMLEdgeFunc::NORMAL, "", "", -1, 0);75MSLane* dummyLane = new MSLane("dummy_0", 50 / 3.6, 1., 100, dummyEdge, 0, PositionVector(), SUMO_const_laneWidth, SVCAll, SVCAll, SVCAll, 0, false, "", PositionVector());76std::vector<MSLane*> lanes;77lanes.push_back(dummyLane);78dummyEdge->initialize(&lanes);79edges.push_back(dummyEdge);80route = std::make_shared<MSRoute>("dummyRoute", edges, true, nullptr, defs->stops);81MSGlobals::gActionStepLength = DELTA_T;82type = MSVehicleType::build(typeDefs);83veh = new MSVehicleMock(defs, route, type, 1);84veh->setTentativeLaneAndPosition(dummyLane, 0);85veh->initDevices();86}8788virtual void TearDown() {89delete veh;90delete type;91}92};9394/* Test the method 'brakeGap'.*/9596TEST_F(MSCFModel_IDMTest, test_method_brakeGap) {97// discrete braking model. keep driving for 1 s98MSCFModel& m = type->getCarFollowModel();99const double v = 3;100EXPECT_DOUBLE_EQ(tau * v, m.brakeGap(v));101}102103TEST_F(MSCFModel_IDMTest, test_method_getSecureGap) {104// the value of getSecureGap should be consistent with followSpeed so that105// strong braking is avoided after lane changing (#4517)106MSCFModel& m = type->getCarFollowModel();107for (double v = 0; v < 15; v += 1) { // follower108for (double u = 0; u < 25; u += 1) { // leader109double sg = m.getSecureGap(veh, nullptr, v, u, m.getMaxDecel());110double vFollow = m.followSpeed(veh, v, sg, u, m.getMaxDecel(), nullptr);111//std::cout << v << " " << u << " " << sg << " " << vFollow << " " << SPEED2ACCEL(vFollow - v) << "\n";112EXPECT_GT(SPEED2ACCEL(vFollow - v), -2.2);113}114}115}116117118