Skip to content

Commit

Permalink
Add maxAccelProfile and desAccelProfile to EIDM, make it available fo…
Browse files Browse the repository at this point in the history
…r all CF-models

Signed-off-by: Dominik Salles <[email protected]>
  • Loading branch information
Domsall committed Feb 15, 2024
1 parent 835bc3c commit 7850d1a
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 53 deletions.
82 changes: 82 additions & 0 deletions src/microsim/MSVehicleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,88 @@ MSVehicleType::setApparentDecel(double apparentDecel) {
myParameter.cfParameter[SUMO_ATTR_APPARENTDECEL] = toString(apparentDecel);
}

void
MSVehicleType::setMaxAccelProfile(std::vector<std::pair<double, double> > accelProfile) {
if (myOriginalType != nullptr) {
accelProfile = myOriginalType->getCarFollowModel().getMaxAccelProfile();
} else {
if (accelProfile[0].first > 0.) {
accelProfile.insert(accelProfile.begin(), std::make_pair(0.0, accelProfile[0].second));
}
if (accelProfile.back().first < (10000 / 3.6)) {
accelProfile.push_back(std::make_pair((10000 / 3.6), accelProfile.back().second));
}
double prevSpeed = 0.0;
for (const auto& accelPair : accelProfile) {
if (accelPair.first < 0.) {
accelProfile = myOriginalType->getCarFollowModel().getMaxAccelProfile();
break;
} else if (accelPair.second < 0.) {
accelProfile = myOriginalType->getCarFollowModel().getMaxAccelProfile();
break;
} else if (accelPair.first < prevSpeed) {
accelProfile = myOriginalType->getCarFollowModel().getMaxAccelProfile();
break;
}
prevSpeed = accelPair.first;
}
}
myCarFollowModel->setMaxAccelProfile(accelProfile);

std::stringstream accelProfileString;
accelProfileString << std::fixed << std::setprecision(2);
int count = 0;
for (const auto& accelPair : accelProfile) {
if (count > 0) {
accelProfileString << " ";
}
accelProfileString << toString(accelPair.first) + "," << accelPair.second;
count++;
}
myParameter.cfParameter[SUMO_ATTR_MAXACCEL_PROFILE] = accelProfileString.str();
}

void
MSVehicleType::setDesAccelProfile(std::vector<std::pair<double, double> > accelProfile) {
if (myOriginalType != nullptr) {
accelProfile = myOriginalType->getCarFollowModel().getDesAccelProfile();
} else {
if (accelProfile[0].first > 0.) {
accelProfile.insert(accelProfile.begin(), std::make_pair(0.0, accelProfile[0].second));
}
if (accelProfile.back().first < (10000 / 3.6)) {
accelProfile.push_back(std::make_pair((10000 / 3.6), accelProfile.back().second));
}
double prevSpeed = 0.0;
for (const auto& accelPair : accelProfile) {
if (accelPair.first < 0.) {
accelProfile = myOriginalType->getCarFollowModel().getDesAccelProfile();
break;
} else if (accelPair.second < 0.) {
accelProfile = myOriginalType->getCarFollowModel().getDesAccelProfile();
break;
} else if (accelPair.first < prevSpeed) {
accelProfile = myOriginalType->getCarFollowModel().getDesAccelProfile();
break;
}
prevSpeed = accelPair.first;
}
}
myCarFollowModel->setDesAccelProfile(accelProfile);

std::stringstream accelProfileString;
accelProfileString << std::fixed << std::setprecision(2);
int count = 0;
for (const auto& accelPair : accelProfile) {
if (count > 0) {
accelProfileString << " ";
}
accelProfileString << toString(accelPair.first) + "," << accelPair.second;
count++;
}
myParameter.cfParameter[SUMO_ATTR_DESACCEL_PROFILE] = accelProfileString.str();
}

void
MSVehicleType::setImperfection(double imperfection) {
if (myOriginalType != nullptr && imperfection < 0) {
Expand Down
10 changes: 10 additions & 0 deletions src/microsim/MSVehicleType.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ class MSVehicleType {
*/
void setApparentDecel(double apparentDecel);

/** @brief Set a new value for this type's maximum acceleration profile.
* @param[in] accelProfile The new acceleration profile of this type
*/
void setMaxAccelProfile(std::vector<std::pair<double, double> > accelProfile);

/** @brief Set a new value for this type's desired acceleration profile.
* @param[in] accelProfile The new acceleration profile of this type
*/
void setDesAccelProfile(std::vector<std::pair<double, double> > accelProfile);

/** @brief Set a new value for this type's imperfection.
* @param[in] imperfection The new imperfection of this type
*/
Expand Down
24 changes: 23 additions & 1 deletion src/microsim/cfmodels/MSCFModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ MSCFModel::MSCFModel(const MSVehicleType* vtype) :
myApparentDecel(vtype->getParameter().getCFParam(SUMO_ATTR_APPARENTDECEL, myDecel)),
myCollisionMinGapFactor(vtype->getParameter().getCFParam(SUMO_ATTR_COLLISION_MINGAP_FACTOR, 1)),
myHeadwayTime(vtype->getParameter().getCFParam(SUMO_ATTR_TAU, 1.0)),
myStartupDelay(TIME2STEPS(vtype->getParameter().getCFParam(SUMO_ATTR_STARTUP_DELAY, 0.0)))
myStartupDelay(TIME2STEPS(vtype->getParameter().getCFParam(SUMO_ATTR_STARTUP_DELAY, 0.0))),
myMaxAccelProfile(vtype->getParameter().getCFProfile(SUMO_ATTR_MAXACCEL_PROFILE, SUMOVTypeParameter::getDefaultMaxAccelProfile(vtype->getParameter().vehicleClass, myAccel))),
myDesAccelProfile(vtype->getParameter().getCFProfile(SUMO_ATTR_DESACCEL_PROFILE, SUMOVTypeParameter::getDefaultDesAccelProfile(vtype->getParameter().vehicleClass, myAccel)))
{ }


Expand Down Expand Up @@ -273,6 +275,26 @@ MSCFModel::applyStartupDelay(const MSVehicle* veh, const double vMin, const doub
}


double
MSCFModel::interpolateProfile(const double speed, const std::vector<std::pair<double, double> > profile) const {
double val;
// extrapolate, means using the first/last value of the array
if (speed < profile[0].first) {
val = profile[0].second;
} else if (speed > profile.back().first) {
val = profile.back().second;
} else { // interpolate
int x = 0;
while (speed > profile[x + 1].first) {
x++;
}
double diff = (profile[x + 1].second - profile[x].second) / (profile[x + 1].first - profile[x].first);
val = profile[x].second + diff * (speed - profile[x].first);
}
return val;
}


double
MSCFModel::interactionGap(const MSVehicle* const veh, double vL) const {
// Resolve the vsafe equation to gap. Assume predecessor has
Expand Down
53 changes: 53 additions & 0 deletions src/microsim/cfmodels/MSCFModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cmath>
#include <string>
#include <vector>
#include <utils/common/StdDefs.h>
#include <utils/common/SUMOTime.h>

Expand Down Expand Up @@ -108,6 +109,9 @@ class MSCFModel {
/// @brief apply speed adaptation on startup
virtual double applyStartupDelay(const MSVehicle* veh, const double vMin, const double vMax, const SUMOTime addTime = 0) const;

/// @brief Get current interpolated value from a profile
virtual double interpolateProfile(const double speed, const std::vector<std::pair<double, double> > profile) const;


/** @brief Computes the vehicle's safe speed without a leader
*
Expand Down Expand Up @@ -281,13 +285,39 @@ class MSCFModel {
return myApparentDecel;
}


/** @brief Get the vehicle type's startupDelay
* @return The startupDelay
*/
inline SUMOTime getStartupDelay() const {
return myStartupDelay;
}


/** @brief Get the vehicle type's maximum acceleration profile depending on the velocity [m/s^2]
* @return The maximum acceleration profile (in m/s^2) of vehicles of this class
*/
inline std::vector<std::pair<double, double> > getMaxAccelProfile() const {
return myMaxAccelProfile;
}


/** @brief Get the vehicle type's desired acceleration profile depending on the velocity [m/s^2]
* @return The desired acceleration profile (in m/s^2) of vehicles of this class
*/
inline std::vector<std::pair<double, double> > getDesAccelProfile() const {
return myDesAccelProfile;
}


/** @brief Get the vehicle type's maximum acceleration [m/s^2]
* @return The maximum acceleration (in m/s^2) of vehicles of this class
*/
virtual inline double getCurrentAccel(const double speed) const {
return myAccel;
}


/** @brief Get the factor of minGap that must be maintained to avoid a collision event
*/
inline double getCollisionMinGapFactor() const {
Expand Down Expand Up @@ -553,13 +583,30 @@ class MSCFModel {
myApparentDecel = decel;
}


/** @brief Sets a new value for the factor of minGap that must be maintained to avoid a collision event
* @param[in] factor The new minGap factor
*/
inline void setCollisionMinGapFactor(const double factor) {
myCollisionMinGapFactor = factor;
}


/** @brief Sets a new value for maximum acceleration profile [m/s^2]
* @param[in] accelProfile The new acceleration profile in m/s^2
*/
virtual void setMaxAccelProfile(std::vector<std::pair<double, double> > accelProfile) {
myMaxAccelProfile = accelProfile;
}

/** @brief Sets a new value for desired acceleration profile [m/s^2]
* @param[in] accelProfile The new acceleration profile in m/s^2
*/
virtual void setDesAccelProfile(std::vector<std::pair<double, double> > accelProfile) {
myDesAccelProfile = accelProfile;
}


/** @brief Sets a new value for driver imperfection
* @param[in] accel The new driver imperfection
*/
Expand Down Expand Up @@ -712,6 +759,12 @@ class MSCFModel {
/// @brief The startup delay after halting [s]
SUMOTime myStartupDelay;

/// @brief The vehicle's maximum acceleration profile [m/s^2]
std::vector<std::pair<double, double> > myMaxAccelProfile;

/// @brief The vehicle's desired acceleration profile [m/s^2]
std::vector<std::pair<double, double> > myDesAccelProfile;



};
Loading

0 comments on commit 7850d1a

Please sign in to comment.