SUMO - Simulation of Urban MObility

Command_SaveTLSSwitchStates.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Writes the switch times of a tls into a file when the tls switches
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 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_SaveTLSSwitchStates.h"
00029 #include <microsim/traffic_lights/MSTrafficLightLogic.h>
00030 #include <microsim/MSEventControl.h>
00031 #include <microsim/MSNet.h>
00032 #include <utils/common/UtilExceptions.h>
00033 #include <utils/common/MsgHandler.h>
00034 #include <utils/iodevices/OutputDevice.h>
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(const MSTLLogicControl::TLSLogicVariants& logics,
00045         OutputDevice& od)
00046     : myOutputDevice(od), myLogics(logics) {
00047     MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 0, MSEventControl::ADAPT_AFTER_EXECUTION);
00048     myOutputDevice.writeXMLHeader("tls-switch-states");
00049 }
00050 
00051 
00052 Command_SaveTLSSwitchStates::~Command_SaveTLSSwitchStates() {
00053 }
00054 
00055 
00056 SUMOTime
00057 Command_SaveTLSSwitchStates::execute(SUMOTime currentTime) {
00058     const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
00059     if (state!=myPreviousState||myLogics.getActive()->getProgramID()!=myPreviousProgramID) {
00060         myOutputDevice << "    <tlsstate time=\"" << time2string(currentTime)
00061                        << "\" id=\"" << myLogics.getActive()->getID()
00062                        << "\" programID=\"" << myLogics.getActive()->getProgramID()
00063                        << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
00064                        << "\" state=\"" << state << "\"/>\n";
00065         myPreviousState = state;
00066         myPreviousProgramID = myLogics.getActive()->getProgramID();
00067     }
00068     return DELTA_T;
00069 }
00070 
00071 
00072 
00073 /****************************************************************************/
00074 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines