SUMO - Simulation of Urban MObility

MSPhaseDefinition.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The definition of a single phase of a tls logic
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 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 #ifndef MSPhaseDefinition_h
00020 #define MSPhaseDefinition_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <bitset>
00033 #include <string>
00034 #include <utils/common/SUMOTime.h>
00035 #include <utils/options/OptionsCont.h>
00036 #include <microsim/MSLink.h>
00037 
00038 
00039 // ===========================================================================
00040 // class definitions
00041 // ===========================================================================
00046 class MSPhaseDefinition {
00047 public:
00049     SUMOTime duration;
00050 
00052     SUMOTime minDuration;
00053 
00055     SUMOTime maxDuration;
00056 
00058     SUMOTime myLastSwitch;
00059 
00060 
00061 public:
00069     MSPhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
00070         : duration(durationArg), minDuration(durationArg), maxDuration(durationArg),
00071           myLastSwitch(0), state(stateArg) {
00072         myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
00073     }
00074 
00075 
00083     MSPhaseDefinition(SUMOTime durationArg, SUMOTime minDurationArg, SUMOTime maxDurationArg,
00084                       const std::string& stateArg)
00085         : duration(durationArg),
00086           myLastSwitch(0), state(stateArg) {
00087         myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
00088         minDuration = minDurationArg<0 ? durationArg : minDurationArg;
00089         maxDuration = maxDurationArg<0 ? durationArg : maxDurationArg;
00090     }
00091 
00092 
00094     virtual ~MSPhaseDefinition() { }
00095 
00096 
00100     const std::string& getState() const {
00101         return state;
00102     }
00103 
00104 
00112     bool isGreenPhase() const {
00113         if (state.find_first_of("gG")==std::string::npos) {
00114             return false;
00115         }
00116         if (state.find_first_of("yY")!=std::string::npos) {
00117             return false;
00118         }
00119         return true;
00120     }
00121 
00122 
00127     LinkState getSignalState(unsigned int pos) const {
00128         return (LinkState) state[pos];
00129     }
00130 
00131 
00138     bool operator!=(const MSPhaseDefinition& pd) {
00139         return state!=pd.state;
00140     }
00141 
00142 
00143 private:
00145     std::string state;
00146 
00147 
00148 };
00149 
00150 #endif
00151 
00152 /****************************************************************************/
00153 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines