SUMO - Simulation of Urban MObility
NBTrafficLightLogic.h
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A SUMO-compliant built logic for a traffic light
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 #ifndef NBTrafficLightLogic_h
00023 #define NBTrafficLightLogic_h
00024 
00025 
00026 // ===========================================================================
00027 // included modules
00028 // ===========================================================================
00029 #ifdef _MSC_VER
00030 #include <windows_config.h>
00031 #else
00032 #include <config.h>
00033 #endif
00034 
00035 #include <vector>
00036 #include <string>
00037 #include <bitset>
00038 #include <utility>
00039 #include <set>
00040 #include "NBConnectionDefs.h"
00041 #include <utils/common/SUMOTime.h>
00042 #include <utils/common/Named.h>
00043 
00044 
00045 // ===========================================================================
00046 // class declarations
00047 // ===========================================================================
00048 class OutputDevice;
00049 
00050 
00051 // ===========================================================================
00052 // class definitions
00053 // ===========================================================================
00058 class NBTrafficLightLogic : public Named {
00059 public:
00064     class PhaseDefinition {
00065     public:
00067         SUMOTime duration;
00068 
00070         std::string state;
00071 
00076         PhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
00077             : duration(durationArg), state(stateArg) { }
00078 
00080         ~PhaseDefinition() { }
00081 
00086         bool operator!=(const PhaseDefinition& pd) const {
00087             return pd.duration != duration || pd.state != state;
00088         }
00089 
00090     };
00091 
00092 
00098     NBTrafficLightLogic(const std::string& id, const std::string& subid, unsigned int noLinks) ;
00099 
00100 
00104     NBTrafficLightLogic(const NBTrafficLightLogic* logic);
00105 
00106 
00108     ~NBTrafficLightLogic() ;
00109 
00110 
00119     void addStep(SUMOTime duration, const std::string& state, int index = -1);
00120 
00121 
00127     void setPhaseState(unsigned int phaseIndex, int tlIndex, LinkState linkState);
00128 
00133     void setPhaseDuration(unsigned int phaseIndex, SUMOTime duration);
00134 
00135     /* @brief deletes the phase at the given index
00136      * @note thhrows InvalidArgument on out-of range index
00137     */
00138     void deletePhase(unsigned int index);
00139 
00140     /* @brief deletes all phases and reset the expect number of links
00141     */
00142     void resetPhases();
00143 
00148     void closeBuilding() ;
00149 
00150 
00154     SUMOTime getDuration() const ;
00155 
00156 
00160     void setOffset(SUMOTime offset) {
00161         myOffset = offset;
00162     }
00163 
00164 
00168     const std::string& getProgramID() const {
00169         return mySubID;
00170     };
00171 
00172 
00176     const std::vector<PhaseDefinition> &getPhases() const {
00177         return myPhases;
00178     }
00179 
00180 
00184     SUMOTime getOffset() const {
00185         return myOffset;
00186     };
00187 
00188 
00191     unsigned int getNumLinks() {
00192         return myNumLinks;
00193     }
00194 
00195 
00196 private:
00198     unsigned int myNumLinks;
00199 
00201     const std::string mySubID;
00202 
00204     SUMOTime myOffset;
00205 
00207     typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
00208 
00210     PhaseDefinitionVector myPhases;
00211 
00213     static const char allowedStatesInitializer[];
00214     static const std::string ALLOWED_STATES;
00215 
00216 
00217 };
00218 
00219 
00220 #endif
00221 
00222 /****************************************************************************/
00223 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines