Command_SaveTLSSwitches Class Reference

#include <Command_SaveTLSSwitches.h>

Inheritance diagram for Command_SaveTLSSwitches:

Command

Detailed Description

Writes information about the green durations of a tls.

Todo:
Revalidate this - as tls are not seting the link information directly ater being switched, the computed information may be delayed

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_SaveTLSSwitchesoperator= (const Command_SaveTLSSwitches &)
 Invalidated assignment operator.

Private Attributes

const
MSTLLogicControl::TLSLogicVariants
myLogics
 The traffic light logic to use.
OutputDevicemyOutputDevice
 The device to write to.
std::map< int, SUMOTimemyPreviousLinkStates
 Storage for prior states; map from signal group to last green time begin.

Constructor & Destructor Documentation

Command_SaveTLSSwitches::Command_SaveTLSSwitches ( const MSTLLogicControl::TLSLogicVariants logics,
OutputDevice od 
) throw ()

Constructor.

Parameters:
[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 ()

Destructor.

Definition at line 55 of file Command_SaveTLSSwitches.cpp.

00055                                                           {
00056 }

Command_SaveTLSSwitches::Command_SaveTLSSwitches ( const Command_SaveTLSSwitches  )  [private]

Invalidated copy constructor.


Member Function Documentation

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".

Parameters:
[in] currentTime The current simulation time
Returns:
Always 1 (will be executed in next time step)
Exceptions:
ProcessError not here
See also:
Command

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.


Field Documentation

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().

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().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:40 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6