Skip to content

Commit

Permalink
fix #12357
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jan 20, 2023
1 parent 27b7fb0 commit e346acc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/microsim/traffic_lights/MSPhasedTrafficLightLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ MSPhasedTrafficLightLogic::MSPhasedTrafficLightLogic(MSTLLogicControl& tlcontrol
const Parameterised::Map& parameters)
: MSTrafficLightLogic(tlcontrol, id, programID, offset, logicType, delay, parameters), myPhases(phases),
myStep(step) {
for (int i = 0; i < (int)myPhases.size(); i++) {
myDefaultCycleTime += myPhases[i]->duration;
}
myDefaultCycleTime = computeCycleTime(myPhases);
}


Expand Down Expand Up @@ -198,6 +196,7 @@ MSPhasedTrafficLightLogic::setPhases(const Phases& phases, int step) {
deletePhases();
myPhases = phases;
myStep = step;
myDefaultCycleTime = computeCycleTime(myPhases);
}


Expand Down
5 changes: 2 additions & 3 deletions src/microsim/traffic_lights/MSSimpleTrafficLightLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ MSSimpleTrafficLightLogic::MSSimpleTrafficLightLogic(MSTLLogicControl& tlcontrol
MSTrafficLightLogic(tlcontrol, id, programID, offset, logicType, delay, parameters),
myPhases(phases),
myStep(step) {
for (const MSPhaseDefinition* phase : myPhases) {
myDefaultCycleTime += phase->duration;
}
myDefaultCycleTime = computeCycleTime(myPhases);
if (myStep < (int)myPhases.size()) {
myPhases[myStep]->myLastSwitch = SIMSTEP;
}
Expand Down Expand Up @@ -308,6 +306,7 @@ MSSimpleTrafficLightLogic::setPhases(const Phases& phases, int step) {
deletePhases();
myPhases = phases;
myStep = step;
myDefaultCycleTime = computeCycleTime(myPhases);
}


Expand Down
12 changes: 12 additions & 0 deletions src/microsim/traffic_lights/MSTrafficLightLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,16 @@ MSTrafficLightLogic::loadState(MSTLLogicControl& tlcontrol, SUMOTime t, int step
setTrafficLightSignals(t - spentDuration);
}


SUMOTime
MSTrafficLightLogic::computeCycleTime(const Phases& phases) {
SUMOTime result = 0;
for (const MSPhaseDefinition* p : phases) {
result += p->duration;
}
return result;
}



/****************************************************************************/
2 changes: 2 additions & 0 deletions src/microsim/traffic_lights/MSTrafficLightLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ class MSTrafficLightLogic : public Named, public Parameterised {

};

SUMOTime computeCycleTime(const Phases& phases);


protected:
/// @brief The id of the logic
Expand Down

0 comments on commit e346acc

Please sign in to comment.