SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSPhaseDefinition.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // The definition of a single phase of a tls logic
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSPhaseDefinition_h
25 #define MSPhaseDefinition_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <bitset>
38 #include <string>
39 #include <utils/common/SUMOTime.h>
41 #include <microsim/MSLink.h>
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
52 public:
55 
58 
61 
64 
65 
66 public:
74  MSPhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
75  : duration(durationArg), minDuration(durationArg), maxDuration(durationArg),
76  myLastSwitch(0), state(stateArg) {
77  myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
78  }
79 
80 
88  MSPhaseDefinition(SUMOTime durationArg, SUMOTime minDurationArg, SUMOTime maxDurationArg,
89  const std::string& stateArg)
90  : duration(durationArg),
91  myLastSwitch(0), state(stateArg) {
92  myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
93  minDuration = minDurationArg < 0 ? durationArg : minDurationArg;
94  maxDuration = maxDurationArg < 0 ? durationArg : maxDurationArg;
95  }
96 
97 
99  virtual ~MSPhaseDefinition() { }
100 
101 
105  const std::string& getState() const {
106  return state;
107  }
108 
109 
117  bool isGreenPhase() const {
118  if (state.find_first_of("gG") == std::string::npos) {
119  return false;
120  }
121  if (state.find_first_of("yY") != std::string::npos) {
122  return false;
123  }
124  return true;
125  }
126 
127 
132  LinkState getSignalState(unsigned int pos) const {
133  return (LinkState) state[pos];
134  }
135 
136 
143  bool operator!=(const MSPhaseDefinition& pd) {
144  return state != pd.state;
145  }
146 
147 
148 private:
150  std::string state;
151 
152 
153 };
154 
155 #endif
156 
157 /****************************************************************************/
158