Eclipse SUMO - Simulation of Urban MObility
Command_SaveTLSProgram.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 /****************************************************************************/
14 // Writes the switch times of a tls into a file when the tls switches
15 /****************************************************************************/
16 // ===========================================================================
17 // included modules
18 // ===========================================================================
19 #include <config.h>
20 
21 #include "Command_SaveTLSProgram.h"
24 #include <microsim/MSNet.h>
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
34  myOutputDevice(od),
35  myLogics(logics) {
37  myOutputDevice.writeXMLHeader("additional", "additional_file.xsd");
38 }
39 
40 
42  writeCurrent();
43 }
44 
45 
48  const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
50  writeCurrent();
53  }
54  if (myPreviousStates.size() == 0 || myPreviousStates.back().getState() != state) {
55  myPreviousStates.push_back(MSPhaseDefinition(0, state));
56  }
57  myPreviousStates.back().duration += DELTA_T;
58  return DELTA_T;
59 }
60 
61 void
63  if (myPreviousStates.size() > 0) {
68  // write the phases
69  for (const MSPhaseDefinition& p : myPreviousStates) {
72  if (p.duration < TIME2STEPS(10)) {
74  }
77  }
78  // write params
80  myPreviousStates.clear();
81  }
82 }
83 
84 
85 /****************************************************************************/
86 
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
Command_SaveTLSProgram::Command_SaveTLSProgram
Command_SaveTLSProgram(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
Definition: Command_SaveTLSProgram.cpp:33
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
MSNet.h
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
Command_SaveTLSProgram::execute
SUMOTime execute(SUMOTime currentTime)
Writes the state of the tls if a change occurred.
Definition: Command_SaveTLSProgram.cpp:47
Command_SaveTLSProgram.h
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
Command_SaveTLSProgram::myTLSID
std::string myTLSID
Storage for the tls ID (needed in destructor)
Definition: Command_SaveTLSProgram.h:97
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
Command_SaveTLSProgram::myLogics
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
Definition: Command_SaveTLSProgram.h:88
SUMO_TAG_PHASE
a single phase description
Definition: SUMOXMLDefinitions.h:143
Command_SaveTLSProgram::myPreviousProgramID
std::string myPreviousProgramID
Storage for prior sub-id.
Definition: Command_SaveTLSProgram.h:94
MSTLLogicControl::TLSLogicVariants::getActive
MSTrafficLightLogic * getActive() const
Definition: MSTLLogicControl.cpp:200
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSTrafficLightLogic.h
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
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
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
OutputDevice.h
Command_SaveTLSProgram::~Command_SaveTLSProgram
~Command_SaveTLSProgram()
Destructor.
Definition: Command_SaveTLSProgram.cpp:41
UtilExceptions.h
Command_SaveTLSProgram::writeCurrent
void writeCurrent()
Write the current program.
Definition: Command_SaveTLSProgram.cpp:62
SUMO_TAG_TLLOGIC
a traffic light logic
Definition: SUMOXMLDefinitions.h:141
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
SUMO_ATTR_STATE
The state of a link.
Definition: SUMOXMLDefinitions.h:708
SUMO_ATTR_DURATION
Definition: SUMOXMLDefinitions.h:667
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Command_SaveTLSProgram::myPreviousStates
std::vector< MSPhaseDefinition > myPreviousStates
Storage for prior state.
Definition: Command_SaveTLSProgram.h:91
MSTLLogicControl::TLSLogicVariants
Storage for all programs of a single tls.
Definition: MSTLLogicControl.h:85
Command_SaveTLSProgram::myOutputDevice
OutputDevice & myOutputDevice
The device to write to.
Definition: Command_SaveTLSProgram.h:85
config.h
SUMO_ATTR_PROGRAMID
Definition: SUMOXMLDefinitions.h:412
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
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSTrafficLightLogic::getCurrentPhaseDef
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
OutputDevice::writePadding
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
Definition: OutputDevice.h:307