50 : myCurrentProgram(0) {
55 std::map<std::string, MSTrafficLightLogic*>::const_iterator j;
56 for (std::map<std::string, MSTrafficLightLogic*>::iterator j =
myVariants.begin(); j !=
myVariants.end(); ++j) {
67 bool hadErrors =
false;
68 for (std::map<std::string, MSTrafficLightLogic*>::const_iterator j =
myVariants.begin(); j !=
myVariants.end(); ++j) {
70 int linkNo = (int)(*j).second->getLinks().size();
71 bool hadProgramErrors =
false;
72 for (MSTrafficLightLogic::Phases::const_iterator i = phases.begin(); i != phases.end(); ++i) {
73 if ((
int)(*i)->getState().length() < linkNo) {
74 hadProgramErrors =
true;
77 if (hadProgramErrors) {
78 WRITE_ERROR(
"Mismatching phase size in tls '" + (*j).second->getID() +
"', program '" + (*j).first +
"'.");
102 throw ProcessError(
"No initial signal plan loaded for tls '" + logic->
getID() +
"'.");
106 throw ProcessError(
"Mismatching phase size in tls '" + logic->
getID() +
"', program '" + programID +
"'.");
134 const std::string& programID) {
136 if (programID ==
"off") {
153 const std::string& state) {
158 std::vector<MSPhaseDefinition*> phases;
159 phases.push_back(phase);
162 std::map<std::string, std::string>());
163 addLogic(
"online", logic,
true,
true);
179 std::vector<MSTrafficLightLogic*>
181 std::vector<MSTrafficLightLogic*> ret;
182 std::map<std::string, MSTrafficLightLogic*>::const_iterator i;
184 ret.push_back((*i).second);
221 for (std::map<std::string, MSTrafficLightLogic*>::iterator i =
myVariants.begin(); i !=
myVariants.end(); ++i) {
222 (*i).second->addLink(link, lane, pos);
237 if (val.length() == 0) {
249 return gspTime == programTime;
257 assert(toTime >= startOfPhase);
258 return toTime - startOfPhase;
265 SUMOTime diff = getDiffToStartOfPhase(logic, toTime);
327 if (gspTo == cycleTimeTo) {
336 if (gspTo >= currentPosTo) {
337 deltaToStretch = (gspTo - currentPosTo);
339 deltaToStretch = (cycleTimeTo - currentPosTo + gspTo);
385 if (posAfterSyn < gspTo) {
386 deltaToCut = posAfterSyn + cycleTime - gspTo;
388 deltaToCut = posAfterSyn - gspTo;
393 for (
int i = 0; i < areasNo; i++) {
399 deltaPossible = stretchUmlaufAnz * deltaPossible;
400 if ((deltaPossible > deltaToCut) && (deltaToCut < (cycleTime / 2))) {
403 SUMOTime deltaToStretch = (cycleTime - deltaToCut) % cycleTime;
415 for (
int i = 0; i < areasNo; i++) {
420 if (stepOfBegin == actStep) {
421 if (begin < startPos) {
422 toCut = end - startPos;
426 toCut =
MIN2(allCutTime, toCut);
427 allCutTime = allCutTime - toCut;
431 SUMOTime newDur = remainingDur - toCut;
435 int currStep = (actStep + 1) % (
int)
myTo->
getPhases().size();
436 while (allCutTime > 0) {
437 for (
int i = currStep; i < (int)
myTo->
getPhases().size(); i++) {
440 SUMOTime endOfPhase = beginOfPhase + durOfPhase;
441 for (
int i = 0; i < areasNo; i++) {
445 if ((beginOfPhase <= begin) && (endOfPhase >= end)) {
447 allCutTime = allCutTime - maxCutOfPhase;
448 durOfPhase = durOfPhase - maxCutOfPhase;
461 SUMOTime remainingStretchTime = allStretchTime;
466 for (
int x = 0; x < areasNo; x++) {
470 facSum *= stretchUmlaufAnz;
474 for (
int x = 0; x < areasNo; x++) {
477 SUMOTime endOfPhase = (startPos + durOfPhase - diffToStart);
478 if (end <= endOfPhase && end >= startPos) {
479 double fac = def.
fac;
480 double actualfac = fac / facSum;
481 facSum = facSum - fac;
483 remainingStretchTime = allStretchTime - StretchTimeOfPhase;
490 durOfPhase = durOfPhase - diffToStart + StretchTimeOfPhase;
495 while (remainingStretchTime > 0) {
496 for (
int i = currStep; i < (int)
myTo->
getPhases().size() && remainingStretchTime > 0; i++) {
499 SUMOTime endOfPhase = beginOfPhase + durOfPhase;
500 for (
int j = 0; j < areasNo && remainingStretchTime > 0; j++) {
503 double fac = def.
fac;
504 if ((beginOfPhase <= end) && (endOfPhase >= end)) {
505 double actualfac = fac / facSum;
508 durOfPhase += StretchTimeOfPhase;
509 remainingStretchTime -= StretchTimeOfPhase;
548 for (std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.begin(); i !=
myLogics.end(); ++i) {
552 for (std::map<std::string, WAUT*>::const_iterator i =
myWAUTs.begin(); i !=
myWAUTs.end(); ++i) {
560 for (std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.begin(); i !=
myLogics.end(); ++i) {
561 (*i).second->getActive()->setTrafficLightSignals(t);
566 std::vector<MSTrafficLightLogic*>
568 std::vector<MSTrafficLightLogic*> ret;
569 std::map<std::string, TLSLogicVariants*>::const_iterator i;
571 std::vector<MSTrafficLightLogic*> s = (*i).second->getAllLogics();
572 copy(s.begin(), s.end(), back_inserter(ret));
579 std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.find(
id);
589 std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.find(
id);
593 return (*i).second->getLogic(programID);
597 std::vector<std::string>
599 std::vector<std::string> ret;
600 for (std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.begin(); i !=
myLogics.end(); ++i) {
601 ret.push_back((*i).first);
613 std::map<std::string, TLSLogicVariants*>::iterator i =
myLogics.find(
id);
621 std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.find(
id);
631 bool hadErrors =
false;
632 for (std::map<std::string, TLSLogicVariants*>::iterator i =
myLogics.begin(); i !=
myLogics.end(); ++i) {
633 hadErrors |= !(*i).second->checkOriginalTLS();
634 (*i).second->saveInitialStates();
643 std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.find(tl->
getID());
647 return (*i).second->isActive(tl);
653 std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.find(
id);
657 return (*i).second->getActive();
664 std::map<std::string, TLSLogicVariants*>::iterator i =
myLogics.find(
id);
667 throw ProcessError(
"Could not switch tls '" +
id +
"' to program '" + programID +
"': No such tls exists.");
669 (*i).second->switchTo(*
this, programID);
675 const std::string& startProg) {
691 SUMOTime when,
const std::string& to) {
700 s.
when = (
myWAUTs[wautid]->refTime + when) % 86400000;
701 myWAUTs[wautid]->switches.push_back(s);
707 const std::string& tls,
708 const std::string& proc,
718 throw InvalidArgument(
"TLS '" + tls +
"' to switch in WAUT '" + wautid +
"' was not yet defined.");
724 myWAUTs[wautid]->junctions.push_back(j);
726 std::string initProg =
myWAUTs[wautid]->startProg;
727 std::vector<WAUTSwitch>::const_iterator first =
myWAUTs[wautid]->switches.end();
729 for (std::vector<WAUTSwitch>::const_iterator i =
myWAUTs[wautid]->switches.begin(); i !=
myWAUTs[wautid]->switches.end(); ++i) {
731 minExecTime = (*i).when;
734 if (first !=
myWAUTs[wautid]->switches.begin()) {
735 initProg = (*(first - 1)).to;
751 std::string initProg =
myWAUTs[wautid]->startProg;
753 std::vector<WAUTSwitch>::const_iterator first = w->
switches.end();
755 for (std::vector<WAUTSwitch>::const_iterator i = w->
switches.begin(); i != w->
switches.end(); ++i) {
757 minExecTime = (*i).when;
763 std::vector<WAUTSwitch>::const_iterator mbegin = w->
switches.begin();
779 const std::string& wautid = cmd.
getWAUTID();
782 for (std::vector<WAUTJunction>::iterator i =
myWAUTs[wautid]->junctions.begin(); i !=
myWAUTs[wautid]->junctions.end(); ++i) {
788 if ((*i).procedure ==
"GSP") {
790 }
else if ((*i).procedure ==
"Stretch") {
805 if (index == static_cast<int>(
myWAUTs[wautid]->switches.size())) {
818 switchTo((*i).to->getID(), (*i).to->getProgramID());
827 std::pair<SUMOTime, MSPhaseDefinition>
836 for (std::map<std::string, TLSLogicVariants*>::const_iterator i =
myLogics.begin(); i !=
myLogics.end(); ++i) {
TLSLogicVariants()
Constructor.
double end
The end of a stretch/cut area (time, in s)
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
bool add(const std::string &id, const std::string &programID, MSTrafficLightLogic *logic, bool newDefault=true)
Adds a tls program to the container.
~WAUTSwitchProcedure_GSP()
Destructor.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
const std::string & getState() const
Returns the state within this phase.
void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime)
Cuts the logic to synchronize.
void switchOffAll()
switch all logic variants to 'off'
std::map< MSLink *, LinkState > myOriginalLinkStates
Originally loaded link states.
int & getIndex()
Returns a reference to the index.
void executeOnSwitchActions() const
std::map< std::string, TLSLogicVariants * > myLogics
A map from ids to the corresponding variants.
Storage for all programs of a single tls.
double fac
The weight factor of a stretch/cut area.
virtual SUMOTime getOffsetFromIndex(int index) const =0
Returns the position (start of a phase during a cycle) from of a given step.
Base class for things to execute if a tls switches to a new phase.
~TLSLogicVariants()
Destructor.
int getGSPValue(const MSTrafficLightLogic &logic) const
Returns the GSP-value.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
std::map< std::string, MSTrafficLightLogic * > myVariants
A map of subkeys to programs.
~WAUTSwitchProcedure_Stretch()
Destructor.
~WAUTSwitchProcedure_JustSwitch()
Destructor.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)=0
Changes the current phase and her duration.
virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const =0
Returns the index of the logic at the given simulation step.
~MSTLLogicControl()
Destructor.
WAUTSwitchProcedure_GSP(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
A definition of a stretch - Bereich.
virtual const MSPhaseDefinition & getPhase(int givenstep) const =0
Returns the definition of the phase from the given position within the plan.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
double begin
The begin of a stretch/cut area (time, in s)
virtual void createTLWrapper(MSTrafficLightLogic *)
creates a wrapper for the given logic (see GUINet)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
std::string junction
The id of the junction to switch.
std::string procedure
The procedure to switch the junction with.
MSTrafficLightLogic * myTo
The program to switch the tls to.
WAUTSwitchProcedure_Stretch(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
void addLink(MSLink *link, MSLane *lane, int pos)
const std::string & getID() const
Returns the id.
MSTLLogicControl()
Constructor.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
WAUT & myWAUT
The WAUT responsible for switching.
void closeWAUT(const std::string &wautid)
Closes loading of a WAUT.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
SUMOTime initWautSwitch(SwitchInitCommand &cmd)
Initialises switching a WAUT.
bool myNetWasLoaded
Information whether the net was completely loaded.
Storage for a junction assigned to a WAUT.
#define WRITE_WARNING(msg)
A fixed traffic light logic.
A traffic lights logic which represents a tls in an off-mode.
A class that stores and controls tls and switching of their programs.
bool mySwitchSynchron
Information whether to switch synchron (?)
SUMOTime getDefaultCycleTime() const
Returns the cycle time (in ms)
MSTLLogicControl & myControl
The control the logic belongs to.
SUMOTime duration
The duration of the phase.
std::vector< MSTrafficLightLogic * > getAllLogics() const
bool addLogic(const std::string &programID, MSTrafficLightLogic *logic, bool netWasLoaded, bool isNewDefault=true)
Adds a logic (program)
void addSwitchCommand(OnSwitchAction *c)
StretchBereichDef getStretchBereichDef(MSTrafficLightLogic *from, int index) const
Returns the numbered Stretch-area for the given program.
MSTrafficLightLogic * getLogicInstantiatingOff(MSTLLogicControl &tlc, const std::string &programID)
std::pair< SUMOTime, MSPhaseDefinition > getPhaseDef(const std::string &tlid) const
return the complete phase definition for a named traffic lights logic
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
WAUTSwitchProcedure * proc
The used procedure.
void adaptLogic(SUMOTime step)
Stretches the destination program's phase to which the tls was switched.
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
This class simply switches to the next program.
bool synchron
Information whether this junction shall be switched synchron.
void adaptLogic(SUMOTime step)
Determines the destination program's changes and applies them.
virtual bool trySwitch(SUMOTime step)=0
Determines whether a switch is possible.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
MSTrafficLightLogic * to
The program to switch the tls to.
This class switches using the Stretch algorithm.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
int getStretchAreaNo(MSTrafficLightLogic *from) const
Returns the number of given Stretch-areas for the given program.
bool checkOriginalTLS() const
Verifies traffic lights loaded from the network.
std::map< MSLink *, LinkState > collectLinkStates() const
Returns the (uncontrolled) states of the controlled links.
SUMOTime when
The time the WAUT shall switch the TLS.
void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime)
Stretches the logic to synchronize.
std::vector< OnSwitchAction * > mySwitchActions
The list of actions/commands to execute on switch.
void setStateInstantiatingOnline(MSTLLogicControl &tlc, const std::string &state)
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
std::string startProg
The name of the start program.
WAUTSwitchProcedure_JustSwitch(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
void addWAUTJunction(const std::string &wautid, const std::string &tls, const std::string &proc, bool synchron)
Adds a tls to the list of tls to be switched by the named WAUT.
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
std::vector< WAUTSwitchProcess > myCurrentlySwitched
A list of currently running switching procedures.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
bool closeNetworkReading()
Lets MSTLLogicControl know that the network has been loaded.
void addOverridingDuration(SUMOTime duration)
Changes the duration of the next phase.
An initialised switch process.
void switchTo(MSTLLogicControl &tlc, const std::string &programID)
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
std::vector< WAUTSwitch > switches
The list of switches to be done by the WAUT.
void switchToPos(SUMOTime simStep, MSTrafficLightLogic &logic, SUMOTime toTime)
switches the given logic directly to the given position
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
This event-class is used to initialise a WAUT switch at a certain time.
void addWAUT(SUMOTime refTime, const std::string &id, const std::string &startProg)
Adds a WAUT definition.
This class switches using the GSP algorithm.
SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic &logic, SUMOTime toTime)
Returns the difference between a given time and the start of the phase.
SUMOTime refTime
The reference time (offset to the switch times)
This is the abstract base class for switching from one tls program to another.
const std::string & getWAUTID() const
Returns the WAUT-id.
std::string id
The id of the WAUT.
bool isActive(const MSTrafficLightLogic *tl) const
static double _2double(const E *const data)
converts a char-type array into the double value described by it
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
std::map< std::string, WAUT * > myWAUTs
A map of ids to corresponding WAUTs.
bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic &logic)
Checks, whether the position of a signal programm is at the GSP ("GuenstigerUmschaltPunkt") ...
The parent class for traffic light logics.
Storage for a WAUTs switch point.
void addWAUTSwitch(const std::string &wautid, SUMOTime when, const std::string &to)
Adds a WAUT switch step to a previously built WAUT.
std::string to
The program name the WAUT shall switch the TLS to.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
MSTrafficLightLogic * getActive() const
MSTrafficLightLogic * from
The current program of the tls.
std::vector< std::string > getAllTLIds() const
MSTrafficLightLogic * getLogic(const std::string &programID) const
void setTrafficLightSignals(SUMOTime t) const
Lets all running (current) tls programs apply their current signal states to links they control...
MSTrafficLightLogic * myFrom
The current program of the tls to switch.
Representation of a lane in the micro simulation.
The definition of a single phase of a tls logic.
MSTrafficLightLogic * myCurrentProgram
The currently used program.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
virtual int getIndexFromOffset(SUMOTime offset) const =0
Returns the step (the phasenumber) of a given position of the cycle.
std::string junction
The junction name.