#include <Command_SaveTLSSwitches.h>

Definition at line 54 of file Command_SaveTLSSwitches.h.
Public Member Functions | |
| Command_SaveTLSSwitches (const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od) throw () | |
| Constructor. | |
| ~Command_SaveTLSSwitches () throw () | |
| Destructor. | |
Derived from Command | |
| SUMOTime | execute (SUMOTime currentTime) throw (ProcessError) |
| Writes the output if a change occured. | |
Private Member Functions | |
| Command_SaveTLSSwitches (const Command_SaveTLSSwitches &) | |
| Invalidated copy constructor. | |
| Command_SaveTLSSwitches & | operator= (const Command_SaveTLSSwitches &) |
| Invalidated assignment operator. | |
Private Attributes | |
| const MSTLLogicControl::TLSLogicVariants & | myLogics |
| The traffic light logic to use. | |
| OutputDevice & | myOutputDevice |
| The device to write to. | |
| std::map< int, SUMOTime > | myPreviousLinkStates |
| Storage for prior states; map from signal group to last green time begin. | |
| Command_SaveTLSSwitches::Command_SaveTLSSwitches | ( | const MSTLLogicControl::TLSLogicVariants & | logics, | |
| OutputDevice & | od | |||
| ) | throw () |
Constructor.
| [in] | tlls | The logic to write state of |
| [in] | od | The output device to write the state into |
Definition at line 46 of file Command_SaveTLSSwitches.cpp.
References MSEventControl::ADAPT_AFTER_EXECUTION, MSEventControl::addEvent(), MSNet::getEndOfTimestepEvents(), and MSNet::getInstance().
00048 : myOutputDevice(od), myLogics(logics) { 00049 MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 00050 0, MSEventControl::ADAPT_AFTER_EXECUTION); 00051 myOutputDevice.writeXMLHeader("tls-switches"); 00052 }
| Command_SaveTLSSwitches::~Command_SaveTLSSwitches | ( | ) | throw () |
| Command_SaveTLSSwitches::Command_SaveTLSSwitches | ( | const Command_SaveTLSSwitches & | ) | [private] |
Invalidated copy constructor.
| SUMOTime Command_SaveTLSSwitches::execute | ( | SUMOTime | currentTime | ) | throw (ProcessError) [virtual] |
Writes the output if a change occured.
Called in each tme step, this class computes which link have red since the last tls switch and writes the information about their green duration into the given stream.
Information whether a link had green and since when is stored in "myPreviousLinkStates".
| [in] | currentTime | The current simulation time |
| ProcessError | not here |
Implements Command.
Definition at line 60 of file Command_SaveTLSSwitches.cpp.
References DELTA_T, MSTLLogicControl::TLSLogicVariants::getActive(), MSTrafficLightLogic::getCurrentPhaseDef(), MSLane::getID(), MSTrafficLightLogic::getID(), MSLink::getLane(), MSTrafficLightLogic::getLanesAt(), MSTrafficLightLogic::getLinks(), MSPhaseDefinition::getState(), MSTrafficLightLogic::getSubID(), MSLink::LINKSTATE_TL_GREEN_MAJOR, MSLink::LINKSTATE_TL_GREEN_MINOR, myLogics, myOutputDevice, myPreviousLinkStates, and time2string().
00060 { 00061 MSTrafficLightLogic *light = myLogics.getActive(); 00062 const MSTrafficLightLogic::LinkVectorVector &links = light->getLinks(); 00063 const std::string &state = light->getCurrentPhaseDef().getState(); 00064 for (unsigned int i=0; i<(unsigned int) links.size(); i++) { 00065 if (state[i]==MSLink::LINKSTATE_TL_GREEN_MAJOR||state[i]==MSLink::LINKSTATE_TL_GREEN_MINOR) { 00066 if (myPreviousLinkStates.find(i)==myPreviousLinkStates.end()) { 00067 // was not saved before 00068 myPreviousLinkStates[i] = currentTime; 00069 continue; 00070 } 00071 } else { 00072 if (myPreviousLinkStates.find(i)==myPreviousLinkStates.end()) { 00073 // was not yet green 00074 continue; 00075 } 00076 const MSTrafficLightLogic::LinkVector &currLinks = links[i]; 00077 const MSTrafficLightLogic::LaneVector &currLanes = light->getLanesAt(i); 00078 SUMOTime lastOn = myPreviousLinkStates[i]; 00079 for (int j=0; j<(int) currLinks.size(); j++) { 00080 MSLink *link = currLinks[j]; 00081 myOutputDevice << " <tlsswitch id=\"" << light->getID() 00082 << "\" subid=\"" << light->getSubID() 00083 << "\" fromLane=\"" << currLanes[j]->getID() 00084 << "\" toLane=\"" << link->getLane()->getID() 00085 << "\" begin=\"" << time2string(lastOn) 00086 << "\" end=\"" << time2string(currentTime) 00087 << "\" duration=\"" << time2string(currentTime-lastOn) 00088 << "\"/>\n"; 00089 } 00090 myPreviousLinkStates.erase(myPreviousLinkStates.find(i)); 00091 } 00092 } 00093 return DELTA_T; 00094 }
| Command_SaveTLSSwitches& Command_SaveTLSSwitches::operator= | ( | const Command_SaveTLSSwitches & | ) | [private] |
Invalidated assignment operator.
const MSTLLogicControl::TLSLogicVariants& Command_SaveTLSSwitches::myLogics [private] |
The traffic light logic to use.
Definition at line 95 of file Command_SaveTLSSwitches.h.
Referenced by execute().
The device to write to.
Definition at line 92 of file Command_SaveTLSSwitches.h.
Referenced by execute().
std::map<int, SUMOTime> Command_SaveTLSSwitches::myPreviousLinkStates [private] |
Storage for prior states; map from signal group to last green time begin.
Definition at line 98 of file Command_SaveTLSSwitches.h.
Referenced by execute().
1.5.6