NBTrafficLightLogic.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A SUMO-compliant built logic for a traffic light
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 
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 <vector>
00031 #include <bitset>
00032 #include <utility>
00033 #include <string>
00034 #include <sstream>
00035 #include <cassert>
00036 #include "NBEdge.h"
00037 #include "NBEdgeCont.h"
00038 #include "NBTrafficLightLogic.h"
00039 #include <utils/options/OptionsCont.h>
00040 #include <utils/options/Option.h>
00041 #include <utils/common/StringTokenizer.h>
00042 #include <utils/iodevices/OutputDevice.h>
00043 
00044 #ifdef CHECK_MEMORY_LEAKS
00045 #include <foreign/nvwa/debug_new.h>
00046 #endif // CHECK_MEMORY_LEAKS
00047 
00048 
00049 // ===========================================================================
00050 // member method definitions
00051 // ===========================================================================
00052 NBTrafficLightLogic::NBTrafficLightLogic(const std::string &id,
00053         const std::string &subid, unsigned int noLinks) throw()
00054         : Named(id), myNoLinks(noLinks), mySubID(subid),
00055         myOffset(0) {}
00056 
00057 
00058 NBTrafficLightLogic::~NBTrafficLightLogic() throw() {}
00059 
00060 
00061 void
00062 NBTrafficLightLogic::addStep(SUMOTime duration, const std::string &state) throw() {
00063     myPhases.push_back(PhaseDefinition(duration, state));
00064 }
00065 
00066 
00067 void
00068 NBTrafficLightLogic::writeXML(OutputDevice &into) const throw() {
00069     into << "   <tl-logic id=\"" << getID() << "\" type=\"static\""
00070     << " programID=\"" << mySubID << "\" offset=\"" << myOffset << "\">\n";
00071     // write the phases
00072     for (PhaseDefinitionVector::const_iterator i=myPhases.begin(); i!=myPhases.end(); i++) {
00073         into << "      <phase duration=\"" << (*i).duration << "\" state=\"" << (*i).state << "\"/>\n";
00074     }
00075     into << "   </tl-logic>\n\n";
00076 }
00077 
00078 
00079 SUMOTime
00080 NBTrafficLightLogic::getDuration() const throw() {
00081     SUMOTime duration = 0;
00082     for (PhaseDefinitionVector::const_iterator i=myPhases.begin(); i!=myPhases.end(); ++i) {
00083         duration += (*i).duration;
00084     }
00085     return duration;
00086 }
00087 
00088 
00089 void
00090 NBTrafficLightLogic::closeBuilding() throw() {
00091     for (unsigned int i=0; i<myPhases.size()-1;) {
00092         if (myPhases[i].state!=myPhases[i+1].state) {
00093             ++i;
00094             continue;
00095         }
00096         myPhases[i].duration += myPhases[i+1].duration;
00097         myPhases.erase(myPhases.begin()+i+1);
00098     }
00099 }
00100 
00101 
00102 
00103 /****************************************************************************/
00104 

Generated on Wed May 5 00:06:33 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6