SUMO - Simulation of Urban MObility
MSPhaseDefinition.h
Go to the documentation of this file.
00001 /****************************************************************************/
00011 // The definition of a single phase of a tls logic
00012 /****************************************************************************/
00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00015 /****************************************************************************/
00016 //
00017 //   This file is part of SUMO.
00018 //   SUMO is free software: you can redistribute it and/or modify
00019 //   it under the terms of the GNU General Public License as published by
00020 //   the Free Software Foundation, either version 3 of the License, or
00021 //   (at your option) any later version.
00022 //
00023 /****************************************************************************/
00024 #ifndef MSPhaseDefinition_h
00025 #define MSPhaseDefinition_h
00026 
00027 
00028 // ===========================================================================
00029 // included modules
00030 // ===========================================================================
00031 #ifdef _MSC_VER
00032 #include <windows_config.h>
00033 #else
00034 #include <config.h>
00035 #endif
00036 
00037 #include <bitset>
00038 #include <string>
00039 #include <utils/common/SUMOTime.h>
00040 #include <utils/options/OptionsCont.h>
00041 #include <microsim/MSLink.h>
00042 
00043 
00044 // ===========================================================================
00045 // class definitions
00046 // ===========================================================================
00051 class MSPhaseDefinition {
00052 public:
00054     SUMOTime duration;
00055 
00057     SUMOTime minDuration;
00058 
00060     SUMOTime maxDuration;
00061 
00063     SUMOTime myLastSwitch;
00064 
00065 
00066 public:
00074     MSPhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
00075         : duration(durationArg), minDuration(durationArg), maxDuration(durationArg),
00076           myLastSwitch(0), state(stateArg) {
00077         myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
00078     }
00079 
00080 
00088     MSPhaseDefinition(SUMOTime durationArg, SUMOTime minDurationArg, SUMOTime maxDurationArg,
00089                       const std::string& stateArg)
00090         : duration(durationArg),
00091           myLastSwitch(0), state(stateArg) {
00092         myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
00093         minDuration = minDurationArg < 0 ? durationArg : minDurationArg;
00094         maxDuration = maxDurationArg < 0 ? durationArg : maxDurationArg;
00095     }
00096 
00097 
00099     virtual ~MSPhaseDefinition() { }
00100 
00101 
00105     const std::string& getState() const {
00106         return state;
00107     }
00108 
00109 
00117     bool isGreenPhase() const {
00118         if (state.find_first_of("gG") == std::string::npos) {
00119             return false;
00120         }
00121         if (state.find_first_of("yY") != std::string::npos) {
00122             return false;
00123         }
00124         return true;
00125     }
00126 
00127 
00132     LinkState getSignalState(unsigned int pos) const {
00133         return (LinkState) state[pos];
00134     }
00135 
00136 
00143     bool operator!=(const MSPhaseDefinition& pd) {
00144         return state != pd.state;
00145     }
00146 
00147 
00148 private:
00150     std::string state;
00151 
00152 
00153 };
00154 
00155 #endif
00156 
00157 /****************************************************************************/
00158 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines