bool MSTLLogicControl::TLSLogicVariants::addLogic(const std::string& programID, MSTrafficLightLogic* logic, bool netWasLoaded, bool isNewDefault) { if (myVariants.find(programID) != myVariants.end()) { return false; } // assert the links are set if (netWasLoaded) { // this one has not yet its links set if (myCurrentProgram == 0) { throw ProcessError("No initial signal plan loaded for tls '" + logic->getID() + "'."); } logic->adaptLinkInformationFrom(*myCurrentProgram); if (logic->getLinks().size() > logic->getPhase(0).getState().size()) { throw ProcessError("Mismatching phase size in tls '" + logic->getID() + "', program '" + programID + "'."); } } // add to the list of active if (myVariants.size() == 0 || isNewDefault) { myCurrentProgram = logic; } // add to the list of logic myVariants[programID] = logic; if (myVariants.size() == 1 || isNewDefault) { logic->setTrafficLightSignals(MSNet::getInstance()->getCurrentTimeStep()); executeOnSwitchActions(); } return true; }
void MSTLLogicControl::TLSLogicVariants::switchTo(MSTLLogicControl& tlc, const std::string& programID) { // set the found wished sub-program as this tls' current one myCurrentProgram = getLogicInstantiatingOff(tlc, programID); myCurrentProgram->setTrafficLightSignals(MSNet::getInstance()->getCurrentTimeStep()); executeOnSwitchActions(); }