Skip to content

Commit

Permalink
add platoon-aware lane change model (MSLCM_LC2013_CC)
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-segata authored and namdre committed May 2, 2024
1 parent 7d6cd2f commit 073b489
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/microsim/cfmodels/CC_VehicleVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ CC_VehicleVariables::CC_VehicleVariables() :
engine(0), engineModel(CC_ENGINE_MODEL_FOLM),
usePrediction(false),
autoLaneChange(false),
platoonFixedLane(-1) {
platoonFixedLane(-1),
commitToLaneChange(true), noCommitReason(0), laneChangeCommitTime(-1) {
fakeData.frontAcceleration = 0;
fakeData.frontControllerAcceleration = 0;
fakeData.frontDistance = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/microsim/cfmodels/CC_VehicleVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,14 @@ class CC_VehicleVariables : public MSCFModel::VehicleVariables {

/// @brief whole platoon lane change (not automatic). -1 indicates no need to change lane (mechanism disabled)
int platoonFixedLane;

/// @brief when followers asks whether to actually change lane or not, what should the leader tell them?¬
bool commitToLaneChange;

/// @brief if a follower asks and we don't commit, what should be the blocked state to return?
int noCommitReason;

/// @brief timestep for which the above commit is valid¬
SUMOTime laneChangeCommitTime;

};
28 changes: 28 additions & 0 deletions src/microsim/cfmodels/MSCFModel_CC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ MSCFModel_CC::setLeader(MSVehicle* veh, MSVehicle* const leader) const {
int
MSCFModel_CC::isPlatoonLaneChangeSafe(const MSVehicle* veh, bool left) const {
CC_VehicleVariables* vars = (CC_VehicleVariables*) veh->getCarFollowVariables();
if (!vars->isLeader) {
return isPlatoonLaneChangeSafe(vars->leaderVehicle, left);
}
int result = 0;
std::pair<int, int> state = libsumo::Vehicle::getLaneChangeState(veh->getID(), left ? +1 : -1);
// bit 1: query lateral direction (left:0, right:1)
Expand Down Expand Up @@ -229,6 +232,31 @@ MSCFModel_CC::getSecureGap(const MSVehicle* const veh, const MSVehicle* const pr
}
}

int
MSCFModel_CC::commitToLaneChange(const MSVehicle* veh, bool left) const {
auto vars = (CC_VehicleVariables*)veh->getCarFollowVariables();
if (isLeader(veh)) {
SUMOTime timestep = MSNet::getInstance()->getCurrentTimeStep();
if (vars->laneChangeCommitTime == timestep) {
if (vars->commitToLaneChange)
return 0;
else
return vars->noCommitReason;
}
else {
int blocked = isPlatoonLaneChangeSafe(veh, left);
if (blocked == 0) {
vars->commitToLaneChange = true;
vars->laneChangeCommitTime = timestep;
}
return blocked;
}
}
else {
return commitToLaneChange(vars->leaderVehicle, left);
}
}

double
MSCFModel_CC::finalizeSpeed(MSVehicle* const veh, double vPos) const {
double vNext;
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/cfmodels/MSCFModel_CC.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ class MSCFModel_CC : public MSCFModel {

bool isLeader(const MSVehicle* veh) const;

int commitToLaneChange(const MSVehicle* veh, bool left) const;

/**
* @brief returns the number of lanes set in the configuration file
*/
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/lcmodels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(microsim_lcmodels_STAT_SRCS
MSLCM_DK2008.h
MSLCM_LC2013.cpp
MSLCM_LC2013.h
MSLCM_LC2013_CC.cpp
MSLCM_LC2013_CC.h
MSLCM_SL2015.cpp
MSLCM_SL2015.h
)
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/lcmodels/MSAbstractLaneChangeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <microsim/devices/MSDevice_Bluelight.h>
#include "MSLCM_DK2008.h"
#include "MSLCM_LC2013.h"
#include "MSLCM_LC2013_CC.h"
#include "MSLCM_SL2015.h"
#include "MSAbstractLaneChangeModel.h"

Expand Down Expand Up @@ -86,6 +87,8 @@ MSAbstractLaneChangeModel::build(LaneChangeModel lcm, MSVehicle& v) {
return new MSLCM_DK2008(v);
case LaneChangeModel::LC2013:
return new MSLCM_LC2013(v);
case LaneChangeModel::LC2013_CC:
return new MSLCM_LC2013_CC(v);
case LaneChangeModel::SL2015:
return new MSLCM_SL2015(v);
case LaneChangeModel::DEFAULT:
Expand Down
50 changes: 50 additions & 0 deletions src/microsim/lcmodels/MSLCM_LC2013_CC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file MSLCM_LC2013.cpp
/// @author Daniel Krajzewicz
/// @author Jakob Erdmann
/// @author Friedemann Wesner
/// @author Sascha Krieg
/// @author Michael Behrisch
/// @author Laura Bieker
/// @author Leonhard Luecken
/// @date Fri, 08.10.2013
///
// A lane change model developed by J. Erdmann
// based on the model of D. Krajzewicz developed between 2004 and 2011 (MSLCM_DK2004)
/****************************************************************************/
#include "MSLCM_LC2013_CC.h"
#include <microsim/cfmodels/MSCFModel_CC.h>

// ===========================================================================
// member method definitions
// ===========================================================================
MSLCM_LC2013_CC::MSLCM_LC2013_CC(MSVehicle& v) : MSLCM_LC2013(v) {}

MSLCM_LC2013_CC::~MSLCM_LC2013_CC() {}

int MSLCM_LC2013_CC::checkChangeBeforeCommitting(const MSVehicle *veh, int state) const {

if (state & LCA_WANTS_LANECHANGE) {
auto *cfm = dynamic_cast<const MSCFModel_CC *>(&veh->getCarFollowModel());

if (cfm) {
bool left = (state & LCA_LEFT) != 0;
return cfm->commitToLaneChange(veh, left);
}
}
return 0;
}

/****************************************************************************/
50 changes: 50 additions & 0 deletions src/microsim/lcmodels/MSLCM_LC2013_CC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file MSLCM_LC2013.h
/// @author Daniel Krajzewicz
/// @author Jakob Erdmann
/// @author Friedemann Wesner
/// @author Sascha Krieg
/// @author Michael Behrisch
/// @date Fri, 08.10.2013
///
// A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
/****************************************************************************/
#pragma once

#include "MSLCM_LC2013.h"

// ===========================================================================
// class definitions
// ===========================================================================
/**
* @class MSLCM_LC2013_CC
* @brief A lane change model developed by D. Krajzewicz, J. Erdmann
* et al. between 2004 and 2013, extended for atomic lane change for platoons
*/
class MSLCM_LC2013_CC : public MSLCM_LC2013 {
public:

MSLCM_LC2013_CC(MSVehicle& v);

virtual ~MSLCM_LC2013_CC();

/// @brief Returns the model's id
LaneChangeModel getModelID() const override {
return LaneChangeModel::LC2013_CC;
}

int checkChangeBeforeCommitting(const MSVehicle* veh, int state) const override;

};
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ StringBijection<InsertionCheck>::Entry SUMOXMLDefinitions::insertionCheckValues[
StringBijection<LaneChangeModel>::Entry SUMOXMLDefinitions::laneChangeModelValues[] = {
{ "DK2008", LaneChangeModel::DK2008 },
{ "LC2013", LaneChangeModel::LC2013 },
{ "LC2013_CC", LaneChangeModel::LC2013_CC },
{ "SL2015", LaneChangeModel::SL2015 },
{ "default", LaneChangeModel::DEFAULT } //< must be the last one
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,7 @@ enum LaneChangeAction {
enum class LaneChangeModel {
DK2008,
LC2013,
LC2013_CC,
SL2015,
DEFAULT
};
Expand Down

0 comments on commit 073b489

Please sign in to comment.