Skip to content

Commit

Permalink
fix #14664
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 9, 2024
1 parent f351a40 commit 792f1ef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/guisim/GUIVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ GUIVehicle::getParameterWindow(GUIMainWindow& app,
if (getParameter().repetitionProbability > 0) {
ret->mkItem(TL("insertion probability"), false, getParameter().repetitionProbability);
}
if (getParameter().poissonRate > 0) {
ret->mkItem(TL("poisson rate"), false, getParameter().poissonRate);
}
ret->mkItem(TL("stop info"), true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getStopInfo));
ret->mkItem(TL("line"), false, myParameter->line);
ret->mkItem(TL("CO2 [mg/s]"), true,
Expand Down
3 changes: 3 additions & 0 deletions src/mesogui/GUIMEVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ GUIMEVehicle::getParameterWindow(GUIMainWindow& app,
if (getParameter().repetitionProbability > 0) {
ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
}
if (getParameter().poissonRate > 0) {
ret->mkItem(TL("poisson rate"), false, getParameter().poissonRate);
}
//ret->mkItem("stop info", false, getStopInfo());
ret->mkItem("line", false, myParameter->line);
//ret->mkItem("CO2 [mg/s]", true,
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/MSInsertionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ MSInsertionControl::saveState(OutputDevice& out) {
}
if (flow.pars->repetitionProbability > 0) {
out.writeAttr(SUMO_ATTR_PROB, flow.pars->repetitionProbability);
} else if (flow.pars->poissonRate > 0) {
out.writeAttr(SUMO_ATTR_PERIOD, "exp(" + toString(flow.pars->poissonRate) + ")");
out.writeAttr(SUMO_ATTR_NEXT, STEPS2TIME(flow.pars->repetitionTotalOffset));
} else {
out.writeAttr(SUMO_ATTR_PERIOD, STEPS2TIME(flow.pars->repetitionOffset));
out.writeAttr(SUMO_ATTR_NEXT, STEPS2TIME(flow.pars->repetitionTotalOffset));
Expand Down
9 changes: 6 additions & 3 deletions src/netedit/elements/demand/GNEDemandElementFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ GNEDemandElementFlow::getFlowAttribute(SumoXMLAttr key) const {
case SUMO_ATTR_PERIOD:
return time2string(repetitionOffset);
case GNE_ATTR_POISSON:
return adjustDecimalValue(1 / STEPS2TIME(repetitionOffset));
return toString(poissonRate);
case SUMO_ATTR_PROB:
return adjustDecimalValue(repetitionProbability);
case SUMO_ATTR_NUMBER:
Expand Down Expand Up @@ -301,12 +301,15 @@ GNEDemandElementFlow::setFlowAttribute(const GNEDemandElement* flowElement, Sumo
case SUMO_ATTR_PERSONSPERHOUR:
case SUMO_ATTR_CONTAINERSPERHOUR:
repetitionOffset = TIME2STEPS(3600 / GNEAttributeCarrier::parse<double>(value));
poissonRate = GNEAttributeCarrier::parse<double>(value) / 3600;
break;
case SUMO_ATTR_PERIOD:
repetitionOffset = string2time(value);
poissonRate = 1 / STEPS2TIME(repetitionOffset);
break;
case GNE_ATTR_POISSON:
repetitionOffset = TIME2STEPS(1 / GNEAttributeCarrier::parse<double>(value));
poissonRate = GNEAttributeCarrier::parse<double>(value);
repetitionOffset = TIME2STEPS(1 / poissonRate);
break;
case SUMO_ATTR_PROB:
repetitionProbability = GNEAttributeCarrier::parse<double>(value);
Expand Down Expand Up @@ -403,7 +406,7 @@ GNEDemandElementFlow::setDefaultFlowAttributes(const GNEDemandElement* flowEleme
if (repetitionOffset < 0) {
toggleFlowAttribute(SUMO_ATTR_PERIOD, false);
toggleFlowAttribute(GNE_ATTR_POISSON, true);
setFlowAttribute(flowElement, GNE_ATTR_POISSON, time2string(repetitionOffset * -1, false));
setFlowAttribute(flowElement, GNE_ATTR_POISSON, toString(poissonRate));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/vehicle/SUMOVehicleParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SUMOVehicleParameter::SUMOVehicleParameter()
repetitionOffset(-1),
repetitionTotalOffset(0),
repetitionProbability(-1),
poissonRate(0),
repetitionEnd(-1),
line(), fromTaz(), toTaz(), personNumber(0), containerNumber(0),
speedFactor(-1),
Expand Down Expand Up @@ -1067,8 +1068,9 @@ SUMOVehicleParameter::incrementFlow(double scale, SumoRNG* rng) {
if (repetitionOffset >= 0) {
repetitionTotalOffset += (SUMOTime)((double)repetitionOffset / scale);
} else {
assert(poissionRate > 0);
// we need to cache this do avoid double generation of the rng in the TIME2STEPS macro
const double r = RandHelper::randExp(-STEPS2TIME(repetitionOffset), rng);
const double r = RandHelper::randExp(poissonRate, rng);
repetitionTotalOffset += TIME2STEPS(r / scale);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/vehicle/SUMOVehicleParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ class SUMOVehicleParameter : public Parameterised {
/// @brief The probability for emitting a vehicle per second
double repetitionProbability;

/// @brief The rate for emitting vehicles with a poisson distribution
double poissonRate;

/// @brief The time at which the flow ends (only needed when using repetitionProbability)
SUMOTime repetitionEnd;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/vehicle/SUMOVehicleParserHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ SUMOVehicleParserHelper::parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttrib
if (rate <= 0) {
return handleVehicleError(hardFail, flowParameter, "Invalid rate parameter for exponentially distributed period in the definition of " + toString(tag) + " '" + id + "'.");
}
flowParameter->repetitionOffset = -TIME2STEPS(rate);
flowParameter->poissonRate = rate;
poissonFlow = true;
} else {
flowParameter->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
Expand Down

0 comments on commit 792f1ef

Please sign in to comment.