SUMO - Simulation of Urban MObility
Command_SaveTLSState.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Writes the state of the tls to a file (in each second)
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include "Command_SaveTLSState.h"
00031 #include <microsim/traffic_lights/MSTrafficLightLogic.h>
00032 #include <microsim/MSEventControl.h>
00033 #include <microsim/MSNet.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_SaveTLSState::Command_SaveTLSState(const MSTLLogicControl::TLSLogicVariants& logics,
00047         OutputDevice& od)
00048     : myOutputDevice(od), myLogics(logics) {
00049     MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 0, MSEventControl::ADAPT_AFTER_EXECUTION);
00050     myOutputDevice.writeXMLHeader("tls-states");
00051 }
00052 
00053 
00054 Command_SaveTLSState::~Command_SaveTLSState() {
00055 }
00056 
00057 
00058 SUMOTime
00059 Command_SaveTLSState::execute(SUMOTime currentTime) {
00060     myOutputDevice << "    <tlsState time=\"" << time2string(currentTime)
00061                    << "\" id=\"" << myLogics.getActive()->getID()
00062                    << "\" programID=\"" << myLogics.getActive()->getProgramID()
00063                    << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
00064                    << "\" state=\"" << myLogics.getActive()->getCurrentPhaseDef().getState() << "\"/>\n";
00065     return DELTA_T;
00066 }
00067 
00068 
00069 
00070 /****************************************************************************/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines