Skip to content

Commit

Permalink
fix #4529
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Sep 6, 2018
1 parent 80cf23b commit 136dd4b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/microsim/MSFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ MSFrame::fillOptions() {
oc.doRegister("collision.check-junctions", new Option_Bool(false));
oc.addDescription("collision.check-junctions", "Processing", "Enables collisions checks on junctions");

oc.doRegister("collision.mingap-factor", new Option_Float(1.0));
oc.addDescription("collision.mingap-factor", "Processing", "Sets the fraction of minGap that must be maintained to avoid collision detection.");
oc.doRegister("collision.mingap-factor", new Option_Float(-1));
oc.addDescription("collision.mingap-factor", "Processing", "Sets the fraction of minGap that must be maintained to avoid collision detection. If a negative value is given, the carFollowModel parameter is used");

oc.doRegister("max-num-vehicles", new Option_Integer(-1));
oc.addDescription("max-num-vehicles", "Processing", "Delay vehicle insertion to stay within the given maximum number");
Expand Down
3 changes: 2 additions & 1 deletion src/microsim/MSLane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,8 @@ MSLane::detectCollisionBetween(SUMOTime timestep, const std::string& stage, MSVe
std::swap(victim, collider);
}
const double colliderPos = colliderOpposite ? collider->getBackPositionOnLane(this) : collider->getPositionOnLane(this);
double gap = victim->getBackPositionOnLane(this) - colliderPos - myCollisionMinGapFactor * collider->getVehicleType().getMinGap();
double minGapFactor = myCollisionMinGapFactor >= 0 ? myCollisionMinGapFactor : collider->getCarFollowModel().getCollisionMinGapFactor();
double gap = victim->getBackPositionOnLane(this) - colliderPos - minGapFactor * collider->getVehicleType().getMinGap();
if (bothOpposite) {
gap = -gap - 2 * myCollisionMinGapFactor * collider->getVehicleType().getMinGap();
}
Expand Down
1 change: 1 addition & 0 deletions src/microsim/cfmodels/MSCFModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ MSCFModel::MSCFModel(const MSVehicleType* vtype) :
myEmergencyDecel(vtype->getParameter().getCFParam(SUMO_ATTR_EMERGENCYDECEL,
SUMOVTypeParameter::getDefaultEmergencyDecel(vtype->getParameter().vehicleClass, myDecel, MSGlobals::gDefaultEmergencyDecel))),
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)) {
}

Expand Down
8 changes: 8 additions & 0 deletions src/microsim/cfmodels/MSCFModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ class MSCFModel {
return myApparentDecel;
}

/** @brief Get the factor of minGap that must be maintained to avoid a collision event
*/
inline double getCollisionMinGapFactor() const {
return myCollisionMinGapFactor;
}


/// @name Virtual methods with default implementation
/// @{
Expand Down Expand Up @@ -589,6 +595,8 @@ class MSCFModel {
double myEmergencyDecel;
/// @brief The vehicle's deceleration as expected by surrounding traffic [m/s^2]
double myApparentDecel;
/// @brief The factor of minGap that must be maintained to avoid a collision event
double myCollisionMinGapFactor;

/// @brief The driver's desired time headway (aka reaction time tau) [s]
double myHeadwayTime;
Expand Down
5 changes: 4 additions & 1 deletion src/microsim/cfmodels/MSCFModel_IDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ MSCFModel_IDM::MSCFModel_IDM(const MSVehicleType* vtype, bool idmm) :
myAdaptationFactor(idmm ? vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR, 1.8) : 1.0),
myAdaptationTime(idmm ? vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.0) : 0.0),
myIterations(MAX2(1, int(TS / vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDM_STEPPING, .25) + .5))),
myTwoSqrtAccelDecel(double(2 * sqrt(myAccel * myDecel))) {
myTwoSqrtAccelDecel(double(2 * sqrt(myAccel * myDecel)))
{
// IDM does not drive very precise and may violate minGap on occasion
myCollisionMinGapFactor = vtype->getParameter().getCFParam(SUMO_ATTR_COLLISION_MINGAP_FACTOR, 0.5);
}

MSCFModel_IDM::~MSCFModel_IDM() {}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/xml/SUMOVehicleParserHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
kraussParams.insert(SUMO_ATTR_DECEL);
kraussParams.insert(SUMO_ATTR_APPARENTDECEL);
kraussParams.insert(SUMO_ATTR_EMERGENCYDECEL);
kraussParams.insert(SUMO_ATTR_EMERGENCYDECEL);
kraussParams.insert(SUMO_ATTR_SIGMA);
kraussParams.insert(SUMO_ATTR_TAU);
allowedCFModelAttrs[SUMO_TAG_CF_KRAUSS] = kraussParams;
Expand All @@ -576,6 +577,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
smartSKParams.insert(SUMO_ATTR_ACCEL);
smartSKParams.insert(SUMO_ATTR_DECEL);
smartSKParams.insert(SUMO_ATTR_EMERGENCYDECEL);
smartSKParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
smartSKParams.insert(SUMO_ATTR_SIGMA);
smartSKParams.insert(SUMO_ATTR_TAU);
smartSKParams.insert(SUMO_ATTR_TMP1);
Expand All @@ -590,6 +592,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
daniel1Params.insert(SUMO_ATTR_ACCEL);
daniel1Params.insert(SUMO_ATTR_DECEL);
daniel1Params.insert(SUMO_ATTR_EMERGENCYDECEL);
daniel1Params.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
daniel1Params.insert(SUMO_ATTR_SIGMA);
daniel1Params.insert(SUMO_ATTR_TAU);
daniel1Params.insert(SUMO_ATTR_TMP1);
Expand All @@ -604,6 +607,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
pwagParams.insert(SUMO_ATTR_ACCEL);
pwagParams.insert(SUMO_ATTR_DECEL);
pwagParams.insert(SUMO_ATTR_EMERGENCYDECEL);
pwagParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
pwagParams.insert(SUMO_ATTR_SIGMA);
pwagParams.insert(SUMO_ATTR_TAU);
pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
Expand All @@ -615,6 +619,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
idmParams.insert(SUMO_ATTR_ACCEL);
idmParams.insert(SUMO_ATTR_DECEL);
idmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
idmParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
idmParams.insert(SUMO_ATTR_TAU);
idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
Expand All @@ -625,6 +630,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
idmmParams.insert(SUMO_ATTR_ACCEL);
idmmParams.insert(SUMO_ATTR_DECEL);
idmmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
idmmParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
idmmParams.insert(SUMO_ATTR_TAU);
idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
Expand All @@ -636,6 +642,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
bkernerParams.insert(SUMO_ATTR_ACCEL);
bkernerParams.insert(SUMO_ATTR_DECEL);
bkernerParams.insert(SUMO_ATTR_EMERGENCYDECEL);
bkernerParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
bkernerParams.insert(SUMO_ATTR_TAU);
bkernerParams.insert(SUMO_ATTR_K);
bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
Expand All @@ -646,6 +653,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
wiedemannParams.insert(SUMO_ATTR_ACCEL);
wiedemannParams.insert(SUMO_ATTR_DECEL);
wiedemannParams.insert(SUMO_ATTR_EMERGENCYDECEL);
wiedemannParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
Expand All @@ -660,6 +668,7 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
ACCParams.insert(SUMO_ATTR_ACCEL);
ACCParams.insert(SUMO_ATTR_DECEL);
ACCParams.insert(SUMO_ATTR_EMERGENCYDECEL);
ACCParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
ACCParams.insert(SUMO_ATTR_TAU);
ACCParams.insert(SUMO_ATTR_SC_GAIN);
ACCParams.insert(SUMO_ATTR_GCC_GAIN_SPEED);
Expand Down
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ StringBijection<int>::Entry SUMOXMLDefinitions::attrs[] = {
{ "laneChangeModel", SUMO_ATTR_LANE_CHANGE_MODEL },
{ "carFollowModel", SUMO_ATTR_CAR_FOLLOW_MODEL },
{ "minGap", SUMO_ATTR_MINGAP },
{ "collisionMinGapFactor", SUMO_ATTR_COLLISION_MINGAP_FACTOR },
{ "boardingDuration", SUMO_ATTR_BOARDING_DURATION },
{ "loadingDuration", SUMO_ATTR_LOADING_DURATION },
// Charging Station
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 @@ -413,6 +413,7 @@ enum SumoXMLAttr {
SUMO_ATTR_LANE_CHANGE_MODEL,
SUMO_ATTR_CAR_FOLLOW_MODEL,
SUMO_ATTR_MINGAP,
SUMO_ATTR_COLLISION_MINGAP_FACTOR,
SUMO_ATTR_BOARDING_DURATION,
SUMO_ATTR_LOADING_DURATION,
/// @}
Expand Down

0 comments on commit 136dd4b

Please sign in to comment.