SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2014 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 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
50  OutputDevice& od)
51  : myOutputDevice(od), myLogics(logics) {
53  myOutputDevice.writeXMLHeader("tls-switches");
54 }
55 
56 
58 }
59 
60 
64  const MSTrafficLightLogic::LinkVectorVector& links = light->getLinks();
65  const std::string& state = light->getCurrentPhaseDef().getState();
66  for (unsigned int i = 0; i < (unsigned int) links.size(); i++) {
67  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
68  if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) {
69  // was not saved before
70  myPreviousLinkStates[i] = currentTime;
71  continue;
72  }
73  } else {
74  if (myPreviousLinkStates.find(i) == myPreviousLinkStates.end()) {
75  // was not yet green
76  continue;
77  }
78  const MSTrafficLightLogic::LinkVector& currLinks = links[i];
79  const MSTrafficLightLogic::LaneVector& currLanes = light->getLanesAt(i);
80  SUMOTime lastOn = myPreviousLinkStates[i];
81  for (int j = 0; j < (int) currLinks.size(); j++) {
82  MSLink* link = currLinks[j];
83  myOutputDevice << " <tlsSwitch id=\"" << light->getID()
84  << "\" programID=\"" << light->getProgramID()
85  << "\" fromLane=\"" << currLanes[j]->getID()
86  << "\" toLane=\"" << link->getLane()->getID()
87  << "\" begin=\"" << time2string(lastOn)
88  << "\" end=\"" << time2string(currentTime)
89  << "\" duration=\"" << time2string(currentTime - lastOn)
90  << "\"/>\n";
91  }
93  }
94  }
95  return DELTA_T;
96 }
97 
98 
99 
100 /****************************************************************************/
101