SUMO - Simulation of Urban MObility
Command_SaveTLSSwitchStates.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Writes the switch times of a tls into a file when the tls switches
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_SaveTLSSwitchStates.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_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(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-switch-states");
00051 }
00052 
00053 
00054 Command_SaveTLSSwitchStates::~Command_SaveTLSSwitchStates() {
00055 }
00056 
00057 
00058 SUMOTime
00059 Command_SaveTLSSwitchStates::execute(SUMOTime currentTime) {
00060     const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
00061     if (state != myPreviousState || myLogics.getActive()->getProgramID() != myPreviousProgramID) {
00062         myOutputDevice << "    <tlsstate time=\"" << time2string(currentTime)
00063                        << "\" id=\"" << myLogics.getActive()->getID()
00064                        << "\" programID=\"" << myLogics.getActive()->getProgramID()
00065                        << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
00066                        << "\" state=\"" << state << "\"/>\n";
00067         myPreviousState = state;
00068         myPreviousProgramID = myLogics.getActive()->getProgramID();
00069     }
00070     return DELTA_T;
00071 }
00072 
00073 
00074 
00075 /****************************************************************************/
00076 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines