SUMO - Simulation of Urban MObility
Command_SaveTLSSwitches.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Writes information about the green durations of a tls
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLink.h>
36 #include <microsim/MSLane.h>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
46  OutputDevice& od)
47  : myOutputDevice(od), myLogics(logics) {
49  myOutputDevice.writeXMLHeader("tlsSwitches", "tlsswitches_file.xsd");
50 }
51 
52 
54 }
55 
56 
60  const MSTrafficLightLogic::LinkVectorVector& links = light->getLinks();
61  const std::string& state = light->getCurrentPhaseDef().getState();
62  for (int i = 0; i < (int) links.size(); i++) {
63  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
64  if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) {
65  // was not saved before
66  myPreviousLinkStates[i] = currentTime;
67  continue;
68  }
69  } else {
70  if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) {
71  // was not yet green
72  continue;
73  }
74  const MSTrafficLightLogic::LinkVector& currLinks = links[i];
75  const MSTrafficLightLogic::LaneVector& currLanes = light->getLanesAt(i);
76  SUMOTime lastOn = myPreviousLinkStates[i];
77  for (int j = 0; j < (int) currLinks.size(); j++) {
78  MSLink* link = currLinks[j];
79  myOutputDevice << " <tlsSwitch id=\"" << light->getID()
80  << "\" programID=\"" << light->getProgramID()
81  << "\" fromLane=\"" << currLanes[j]->getID()
82  << "\" toLane=\"" << link->getLane()->getID()
83  << "\" begin=\"" << time2string(lastOn)
84  << "\" end=\"" << time2string(currentTime)
85  << "\" duration=\"" << time2string(currentTime - lastOn)
86  << "\"/>\n";
87  }
89  }
90  }
91  return DELTA_T;
92 }
93 
94 
95 
96 /****************************************************************************/
97 
The link has green light, may pass.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
const std::string & getState() const
Returns the state within this phase.
Command_SaveTLSSwitches(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
Storage for all programs of a single tls.
SUMOTime execute(SUMOTime currentTime)
Writes the output if a change occured.
The link has green light, has to brake.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
const std::string & getID() const
Returns the id.
Definition: Named.h:66
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
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:413
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
std::map< int, SUMOTime > myPreviousLinkStates
Storage for prior states; map from signal group to last green time begin.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
OutputDevice & myOutputDevice
The device to write to.
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
The parent class for traffic light logics.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
long long int SUMOTime
Definition: TraCIDefs.h:52
MSTrafficLightLogic * getActive() const