SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Command_SaveTLSState.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Writes the state of the tls to a file (in each second)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include "Command_SaveTLSState.h"
33 #include <microsim/MSNet.h>
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  OutputDevice& od)
48  : myOutputDevice(od), myLogics(logics) {
50  myOutputDevice.writeXMLHeader("tls-states");
51 }
52 
53 
55 }
56 
57 
60  myOutputDevice << " <tlsState time=\"" << time2string(currentTime)
61  << "\" id=\"" << myLogics.getActive()->getID()
62  << "\" programID=\"" << myLogics.getActive()->getProgramID()
63  << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
64  << "\" state=\"" << myLogics.getActive()->getCurrentPhaseDef().getState() << "\"/>\n";
65  return DELTA_T;
66 }
67 
68 
69 
70 /****************************************************************************/
OutputDevice & myOutputDevice
The device to write to.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
const std::string & getState() const
Returns the state within this phase.
virtual unsigned int getCurrentPhaseIndex() const =0
Returns the current index within the program.
Storage for all programs of a single tls.
MSEventControl & getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:350
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
SUMOTime execute(SUMOTime currentTime)
Writes the current state of the tls.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
MSTrafficLightLogic * getActive() const
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
~Command_SaveTLSState()
Destructor.
Command_SaveTLSState(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
int SUMOTime
Definition: SUMOTime.h:43
Patch the time in a way that it is at least as high as the simulation begin time. ...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
const std::string & getProgramID() const
Returns this tl-logic's id.
#define DELTA_T
Definition: SUMOTime.h:50