00001 /****************************************************************************/ 00007 // Writes information about the green durations of a tls 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 // =========================================================================== 00020 // included modules 00021 // =========================================================================== 00022 #ifdef _MSC_VER 00023 #include <windows_config.h> 00024 #else 00025 #include <config.h> 00026 #endif 00027 00028 #include "Command_SaveTLSSwitches.h" 00029 #include <microsim/traffic_lights/MSTrafficLightLogic.h> 00030 #include <microsim/MSEventControl.h> 00031 #include <microsim/MSNet.h> 00032 #include <microsim/MSLink.h> 00033 #include <microsim/MSLane.h> 00034 #include <utils/common/UtilExceptions.h> 00035 #include <utils/common/MsgHandler.h> 00036 #include <utils/iodevices/OutputDevice.h> 00037 00038 #ifdef CHECK_MEMORY_LEAKS 00039 #include <foreign/nvwa/debug_new.h> 00040 #endif // CHECK_MEMORY_LEAKS 00041 00042 00043 // =========================================================================== 00044 // method definitions 00045 // =========================================================================== 00046 Command_SaveTLSSwitches::Command_SaveTLSSwitches(const MSTLLogicControl::TLSLogicVariants &logics, 00047 OutputDevice &od) throw() 00048 : myOutputDevice(od), myLogics(logics) { 00049 MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 00050 0, MSEventControl::ADAPT_AFTER_EXECUTION); 00051 myOutputDevice.writeXMLHeader("tls-switches"); 00052 } 00053 00054 00055 Command_SaveTLSSwitches::~Command_SaveTLSSwitches() throw() { 00056 } 00057 00058 00059 SUMOTime 00060 Command_SaveTLSSwitches::execute(SUMOTime currentTime) throw(ProcessError) { 00061 MSTrafficLightLogic *light = myLogics.getActive(); 00062 const MSTrafficLightLogic::LinkVectorVector &links = light->getLinks(); 00063 const std::string &state = light->getCurrentPhaseDef().getState(); 00064 for (unsigned int i=0; i<(unsigned int) links.size(); i++) { 00065 if (state[i]==MSLink::LINKSTATE_TL_GREEN_MAJOR||state[i]==MSLink::LINKSTATE_TL_GREEN_MINOR) { 00066 if (myPreviousLinkStates.find(i)==myPreviousLinkStates.end()) { 00067 // was not saved before 00068 myPreviousLinkStates[i] = currentTime; 00069 continue; 00070 } 00071 } else { 00072 if (myPreviousLinkStates.find(i)==myPreviousLinkStates.end()) { 00073 // was not yet green 00074 continue; 00075 } 00076 const MSTrafficLightLogic::LinkVector &currLinks = links[i]; 00077 const MSTrafficLightLogic::LaneVector &currLanes = light->getLanesAt(i); 00078 SUMOTime lastOn = myPreviousLinkStates[i]; 00079 for (int j=0; j<(int) currLinks.size(); j++) { 00080 MSLink *link = currLinks[j]; 00081 myOutputDevice << " <tlsswitch id=\"" << light->getID() 00082 << "\" subid=\"" << light->getSubID() 00083 << "\" fromLane=\"" << currLanes[j]->getID() 00084 << "\" toLane=\"" << link->getLane()->getID() 00085 << "\" begin=\"" << time2string(lastOn) 00086 << "\" end=\"" << time2string(currentTime) 00087 << "\" duration=\"" << time2string(currentTime-lastOn) 00088 << "\"/>\n"; 00089 } 00090 myPreviousLinkStates.erase(myPreviousLinkStates.find(i)); 00091 } 00092 } 00093 return DELTA_T; 00094 } 00095 00096 00097 00098 /****************************************************************************/ 00099
1.5.6