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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Writes the switch times of a tls into a file when the tls switches
19 /****************************************************************************/
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
32 #include <microsim/MSNet.h>
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  OutputDevice& od)
43  : myOutputDevice(od), myLogics(logics) {
45  myOutputDevice.writeXMLHeader("tlsStates", "tlsstates_file.xsd");
46 }
47 
48 
50 }
51 
52 
55  const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
57  myOutputDevice << " <tlsState time=\"" << time2string(currentTime)
58  << "\" id=\"" << myLogics.getActive()->getID()
59  << "\" programID=\"" << myLogics.getActive()->getProgramID()
60  << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
61  << "\" state=\"" << state << "\"/>\n";
62  myPreviousState = state;
64  }
65  return DELTA_T;
66 }
67 
68 
69 
70 /****************************************************************************/
71 
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
std::string myPreviousState
Storage for prior state.
const std::string & getState() const
Returns the state within this phase.
Storage for all programs of a single tls.
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
const std::string & getProgramID() const
Returns this tl-logic&#39;s id.
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.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:409
SUMOTime execute(SUMOTime currentTime)
Writes the state of the tls if a change occured.
Command_SaveTLSSwitchStates(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
std::string myPreviousProgramID
Storage for prior sub-id.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
long long int SUMOTime
Definition: TraCIDefs.h:51
MSTrafficLightLogic * getActive() const
OutputDevice & myOutputDevice
The device to write to.