Eclipse SUMO - Simulation of Urban MObility
Command_SaveTLSSwitchStates.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Writes the switch times of a tls into a file when the tls switches
16 /****************************************************************************/
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
25 #include <microsim/MSNet.h>
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
35  OutputDevice& od)
36  : myOutputDevice(od), myLogics(logics) {
38  myOutputDevice.writeXMLHeader("tlsStates", "tlsstates_file.xsd");
39 }
40 
41 
43 }
44 
45 
48  const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
50  myOutputDevice << " <tlsState time=\"" << time2string(currentTime)
51  << "\" id=\"" << myLogics.getActive()->getID()
52  << "\" programID=\"" << myLogics.getActive()->getProgramID()
53  << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
54  << "\" state=\"" << state << "\"/>\n";
55  myPreviousState = state;
57  }
58  return DELTA_T;
59 }
60 
61 
62 
63 /****************************************************************************/
64 
Command_SaveTLSSwitchStates::myPreviousState
std::string myPreviousState
Storage for prior state.
Definition: Command_SaveTLSSwitchStates.h:88
Command_SaveTLSSwitchStates.h
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
MSNet.h
Command_SaveTLSSwitchStates::myLogics
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
Definition: Command_SaveTLSSwitchStates.h:85
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSTrafficLightLogic::getProgramID
const std::string & getProgramID() const
Returns this tl-logic's id.
Definition: MSTrafficLightLogic.h:174
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36
MsgHandler.h
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSTrafficLightLogic::getCurrentPhaseIndex
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
MSTLLogicControl::TLSLogicVariants::getActive
MSTrafficLightLogic * getActive() const
Definition: MSTLLogicControl.cpp:200
MSTrafficLightLogic.h
MSNet::getEndOfTimestepEvents
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:439
MSPhaseDefinition::getState
const std::string & getState() const
Returns the state within this phase.
Definition: MSPhaseDefinition.h:199
OutputDevice.h
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
UtilExceptions.h
Command_SaveTLSSwitchStates::~Command_SaveTLSSwitchStates
~Command_SaveTLSSwitchStates()
Destructor.
Definition: Command_SaveTLSSwitchStates.cpp:42
Command_SaveTLSSwitchStates::execute
SUMOTime execute(SUMOTime currentTime)
Writes the state of the tls if a change occurred.
Definition: Command_SaveTLSSwitchStates.cpp:47
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates
Command_SaveTLSSwitchStates(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
Definition: Command_SaveTLSSwitchStates.cpp:34
MSTLLogicControl::TLSLogicVariants
Storage for all programs of a single tls.
Definition: MSTLLogicControl.h:85
config.h
MSEventControl.h
OutputDevice::writeXMLHeader
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Definition: OutputDevice.cpp:227
Command_SaveTLSSwitchStates::myPreviousProgramID
std::string myPreviousProgramID
Storage for prior sub-id.
Definition: Command_SaveTLSSwitchStates.h:91
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
Command_SaveTLSSwitchStates::myOutputDevice
OutputDevice & myOutputDevice
The device to write to.
Definition: Command_SaveTLSSwitchStates.h:82
MSTrafficLightLogic::getCurrentPhaseDef
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.