MSPhaseDefinition Class Reference

#include <MSPhaseDefinition.h>


Detailed Description

The definition of a single phase of a tls logic.

Definition at line 46 of file MSPhaseDefinition.h.


Public Member Functions

MSLink::LinkState getSignalState (unsigned int pos) const throw ()
 Returns the state of the tls signal at the given position.
const std::string & getState () const throw ()
 Returns the state within this phase.
bool isGreenPhase () const throw ()
 Returns whether this phase is a pure "green" phase.
 MSPhaseDefinition (SUMOTime durationArg, SUMOTime minDurationArg, SUMOTime maxDurationArg, const std::string &stateArg) throw ()
 Constructor.
 MSPhaseDefinition (SUMOTime durationArg, const std::string &stateArg) throw ()
 Constructor.
bool operator!= (const MSPhaseDefinition &pd)
 Comparison operator.
virtual ~MSPhaseDefinition () throw ()
 Destructor.

Static Public Member Functions

Helper methods for converting between old and new representation
static std::string new2brakeMask (const std::string &state) throw ()
 Helper method for extracting the old "brakeMask" from new tls definitions.
static std::string new2driveMask (const std::string &state) throw ()
 Helper method for extracting the old "driveMask" from new tls definitions.
static std::string new2yellowMask (const std::string &state) throw ()
 Helper method for extracting the old "yellowMask" from new tls definitions.
static std::string old2new (const std::string &driveMask, const std::string &brakeMask, const std::string &yellowMask) throw ()
 Helper method for converting old tls descriptions into new.

Data Fields

SUMOTime duration
 The duration of the phase.
SUMOTime maxDuration
 The maximum duration of the phase.
SUMOTime minDuration
 The minimum duration of the phase.
SUMOTime myLastSwitch
 Stores the timestep of the last on-switched of the phase.

Private Attributes

std::string state
 The phase definition.

Constructor & Destructor Documentation

MSPhaseDefinition::MSPhaseDefinition ( SUMOTime  durationArg,
const std::string &  stateArg 
) throw () [inline]

Constructor.

minDuration and maxDuration are set to duration.

Parameters:
[in] durationArg The duration of the phase
[in] stateArg The state in the phase

Definition at line 69 of file MSPhaseDefinition.h.

References OptionsCont::getOptions(), myLastSwitch, and string2time().

00070             : duration(durationArg), minDuration(durationArg), maxDuration(durationArg),
00071             myLastSwitch(0), state(stateArg) {
00072         myLastSwitch = string2time(OptionsCont::getOptions().getString("begin"));
00073     }

MSPhaseDefinition::MSPhaseDefinition ( SUMOTime  durationArg,
SUMOTime  minDurationArg,
SUMOTime  maxDurationArg,
const std::string &  stateArg 
) throw () [inline]

Constructor.

Parameters:
[in] durationArg The duration of the phase
[in] minDurationArg The minimum duration of the phase
[in] maxDurationArg The maximum duration of the phase
[in] stateArg The state in the phase

Definition at line 83 of file MSPhaseDefinition.h.

References OptionsCont::getOptions(), maxDuration, minDuration, myLastSwitch, and string2time().

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     }

virtual MSPhaseDefinition::~MSPhaseDefinition (  )  throw () [inline, virtual]

Destructor.

Definition at line 94 of file MSPhaseDefinition.h.

00094 { }


Member Function Documentation

MSLink::LinkState MSPhaseDefinition::getSignalState ( unsigned int  pos  )  const throw () [inline]

Returns the state of the tls signal at the given position.

Parameters:
[in] pos The position of the signal to return the state for
Returns:
The state of the signal at the given position

Definition at line 127 of file MSPhaseDefinition.h.

References state.

Referenced by traci::TraCIServer::commandGetTLStatus(), and traci::TraCIServer::handleTrafficLightDomain().

00127                                                                    {
00128         return (MSLink::LinkState) state[pos];
00129     }

const std::string& MSPhaseDefinition::getState (  )  const throw () [inline]

bool MSPhaseDefinition::isGreenPhase (  )  const throw () [inline]

Returns whether this phase is a pure "green" phase.

"pure green" means in this case that at least one stream has green and no stream has yellow. Such phases are meant to be candidates for being stretched by actuated or agentbased traffic light logics.

Returns:
Whether this phase is a "pure green" phase

Definition at line 112 of file MSPhaseDefinition.h.

References state.

Referenced by MSActuatedTrafficLightLogic::duration(), and MSActuatedTrafficLightLogic::gapControl().

00112                                       {
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     }

static std::string MSPhaseDefinition::new2brakeMask ( const std::string &  state  )  throw () [inline, static]

Helper method for extracting the old "brakeMask" from new tls definitions.

Parameters:
[in] state Definition of the phase
Returns:
The brakeMask

Definition at line 202 of file MSPhaseDefinition.h.

References state.

Referenced by TraCIServerAPI_TLS::processGet().

00202                                                                    {
00203         std::string mask;
00204         for (int i=(int) state.length()-1; i>=0; --i) {
00205             if (state[i]>='a'&&state[i]<='z') {
00206                 mask += '0';
00207             } else {
00208                 mask += '1';
00209             }
00210         }
00211         return mask;
00212     }

static std::string MSPhaseDefinition::new2driveMask ( const std::string &  state  )  throw () [inline, static]

Helper method for extracting the old "driveMask" from new tls definitions.

Parameters:
[in] state Definition of the phase
Returns:
The driveMask

Definition at line 185 of file MSPhaseDefinition.h.

References state.

Referenced by TraCIServerAPI_TLS::processGet().

00185                                                                    {
00186         std::string mask;
00187         for (int i=(int) state.length()-1; i>=0; --i) {
00188             if (state[i]=='g'||state[i]=='G') {
00189                 mask += '1';
00190             } else {
00191                 mask += '0';
00192             }
00193         }
00194         return mask;
00195     }

static std::string MSPhaseDefinition::new2yellowMask ( const std::string &  state  )  throw () [inline, static]

Helper method for extracting the old "yellowMask" from new tls definitions.

Parameters:
[in] state Definition of the phase
Returns:
The yellowMask

Definition at line 219 of file MSPhaseDefinition.h.

References state.

Referenced by TraCIServerAPI_TLS::processGet().

00219                                                                     {
00220         std::string mask;
00221         for (int i=(int) state.length()-1; i>=0; --i) {
00222             if (state[i]=='y'||state[i]=='Y') {
00223                 mask += '1';
00224             } else {
00225                 mask += '0';
00226             }
00227         }
00228         return mask;
00229     }

static std::string MSPhaseDefinition::old2new ( const std::string &  driveMask,
const std::string &  brakeMask,
const std::string &  yellowMask 
) throw () [inline, static]

Helper method for converting old tls descriptions into new.

Parameters:
[in] driveMask Information which vehicles (links) may drive
[in] brakeMask Information which vehicles (links) have to brake
[in] yellowMask Information which vehicles (links) have yellow
Returns:
The new phase definition

Definition at line 152 of file MSPhaseDefinition.h.

References state.

Referenced by NLHandler::addPhase(), and TraCIServerAPI_TLS::processSet().

00152                                                                                                                           {
00153         std::string state;
00154         for (int i=(int) driveMask.length()-1; i>=0; --i) {
00155             if (driveMask[i]=='1') {
00156                 state += 'g';
00157             } else {
00158                 if (yellowMask[i]=='1') {
00159                     state += 'y';
00160                 } else {
00161                     state += 'r';
00162                 }
00163             }
00164         }
00165         //  brake needs then
00166         int j = 0;
00167         for (int i=(int) driveMask.length()-1; i>=0; --i, ++j) {
00168             if (brakeMask[i]=='0') {
00169                 if (state[j]=='g') {
00170                     state[j] = 'G';
00171                 }
00172                 if (state[j]=='y') {
00173                     state[j] = 'Y';
00174                 }
00175             }
00176         }
00177         return state;
00178     }

bool MSPhaseDefinition::operator!= ( const MSPhaseDefinition pd  )  [inline]

Comparison operator.

Note that only the state must differ, not the duration!

Parameters:
[in] pd The phase definition to compare against
Returns:
Whether the given phase definition differs

Definition at line 138 of file MSPhaseDefinition.h.

References state.

00138                                                  {
00139         return state!=pd.state;
00140     }


Field Documentation

The maximum duration of the phase.

Definition at line 55 of file MSPhaseDefinition.h.

Referenced by MSActuatedTrafficLightLogic::duration(), MSPhaseDefinition(), and TraCIServerAPI_TLS::processGet().

The minimum duration of the phase.

Definition at line 52 of file MSPhaseDefinition.h.

Referenced by MSActuatedTrafficLightLogic::duration(), MSPhaseDefinition(), and TraCIServerAPI_TLS::processGet().

Stores the timestep of the last on-switched of the phase.

Definition at line 58 of file MSPhaseDefinition.h.

Referenced by MSSimpleTrafficLightLogic::getPhaseIndexAtTime(), and MSPhaseDefinition().

std::string MSPhaseDefinition::state [private]

The phase definition.

Definition at line 236 of file MSPhaseDefinition.h.

Referenced by getSignalState(), getState(), isGreenPhase(), new2brakeMask(), new2driveMask(), new2yellowMask(), old2new(), and operator!=().


The documentation for this class was generated from the following file:

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