MSSimpleTrafficLightLogic Class Reference

#include <MSSimpleTrafficLightLogic.h>

Inheritance diagram for MSSimpleTrafficLightLogic:

MSTrafficLightLogic MSActuatedTrafficLightLogic MSAgentbasedTrafficLightLogic MSUnboundActuatedTrafficLightLogic

Detailed Description

A fixed traffic light logic.

The implementation of a simple traffic light which only switches between it's phases and sets the lights to red in between. Some functions are called with an information about the current step. This is needed as a single logic may be used by many junctions and so the current step is stored within them, not within the logic.

Definition at line 54 of file MSSimpleTrafficLightLogic.h.


Public Types

Structure definitions
typedef std::vector< MSLane * > LaneVector
 Definition of the list of links that participate in this tl-light.
typedef std::vector< LaneVectorLaneVectorVector
 Definition of a list that holds lists of links that do have the same attribute.
typedef std::vector< MSLink * > LinkVector
 Definition of the list of links that participate in this tl-light.
typedef std::vector< LinkVectorLinkVectorVector
 Definition of a list that holds lists of links that do have the same attribute.
typedef std::vector
< MSPhaseDefinition * > 
Phases
 Definition of a list of phases, being the junction logic.

Public Member Functions

virtual void init (NLDetectorBuilder &nb) throw (ProcessError)
 Initialises the tls with information about incoming lanes.
 MSSimpleTrafficLightLogic (MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const Phases &phases, unsigned int step, SUMOTime delay) throw ()
 Constructor.
 ~MSSimpleTrafficLightLogic () throw ()
 Destructor.
Handling of controlled links
virtual void adaptLinkInformationFrom (const MSTrafficLightLogic &logic) throw ()
 Applies information about controlled links and lanes from the given logic.
void addLink (MSLink *link, MSLane *lane, unsigned int pos) throw ()
 Adds a link on building.
std::map< MSLink *, std::pair
< MSLink::LinkState, bool > > 
collectLinkStates () const throw ()
 Returns the (uncontrolled) states of the controlled links.
void resetLinkStates (const std::map< MSLink *, std::pair< MSLink::LinkState, bool > > &vals) const throw ()
 Resets the states of controlled links.
Changing phases and phase durations
void addOverridingDuration (SUMOTime duration) throw ()
 Changes the duration of the next phase.
void setCurrentDurationIncrement (SUMOTime delay) throw ()
 Delays current phase by the given delay.
Changing phases and phase durations
void changeStepAndDuration (MSTLLogicControl &tlcontrol, SUMOTime simStep, unsigned int step, SUMOTime stepDuration) throw ()
 Changes the current phase and her duration.
Dynamic Information Retrieval
const MSPhaseDefinitiongetCurrentPhaseDef () const throw ()
 Returns the definition of the current phase.
unsigned int getCurrentPhaseIndex () const throw ()
 Returns the current index within the program.
Dynamic Information Retrieval
unsigned int getDefaultCycleTime () const throw ()
 Returns the cycle time.
SUMOTime getNextSwitchTime () const throw ()
 Returns the assumed next switch time.
Static Information Retrieval
const std::string & getID () const throw ()
 Returns this tl-logic's id.
const LaneVectorVectorgetLanes () const throw ()
 Returns the list of lists of all lanes controlled by this tls.
const LaneVectorgetLanesAt (unsigned int i) const throw ()
 Returns the list of lanes that are controlled by the signals at the given position.
int getLinkIndex (const MSLink *const link) const throw ()
 Returns the index of the given link.
const LinkVectorVectorgetLinks () const throw ()
 Returns the list of lists of all affected links.
const LinkVectorgetLinksAt (unsigned int i) const throw ()
 Returns the list of links that are controlled by the signals at the given position.
const std::string & getSubID () const throw ()
 Returns this tl-logic's id.
Conversion between time and phase
unsigned int getIndexFromOffset (unsigned int offset) const throw ()
 Returns the step (the phasenumber) of a given position of the cycle.
unsigned int getOffsetFromIndex (unsigned int index) const throw ()
 Returns the position (start of a phase during a cycle) from of a given step.
unsigned int getPhaseIndexAtTime (SUMOTime simStep) const throw ()
 Returns the index of the logic at the given simulation step.
Algorithm parameter handling
std::string getParameterValue (const std::string &key) const throw ()
 Returns a named parameter.
void setParameter (const std::map< std::string, std::string > &params) throw ()
 Inserts read parameter.
Static Information Retrieval
const MSPhaseDefinitiongetPhase (unsigned int givenstep) const throw ()
 Returns the definition of the phase from the given position within the plan.
unsigned int getPhaseNumber () const throw ()
 Returns the number of phases.
PhasesgetPhases () throw ()
 Returns the phases of this tls program.
const PhasesgetPhases () const throw ()
 Returns the phases of this tls program.
Switching and setting current rows
void setLinkPriorities () const throw ()
 Applies the priorities resulting from the current phase to controlled links.
bool setTrafficLightSignals () const throw ()
 Clears all incoming vehicle information on links that have red.
SUMOTime trySwitch (bool isActive) throw ()
 Switches to the next phase.

Protected Attributes

SUMOTime myCurrentDurationIncrement
 A value for enlarge the current duration.
unsigned int myDefaultCycleTime
 The cycle time (without changes).
std::string myID
 The id of the logic.
LaneVectorVector myLanes
 The list of links which do participate in this traffic light.
LinkVectorVector myLinks
 The list of links which do participate in this traffic light.
std::vector< SUMOTimemyOverridingTimes
 A list of duration overrides.
std::map< std::string,
std::string > 
myParameter
 Given parameter.
Phases myPhases
 The list of phases this logic uses.
unsigned int myStep
 The current step.
std::string mySubID
SwitchCommandmySwitchCommand
 The current switch command.

Member Typedef Documentation

typedef std::vector<MSLane*> MSTrafficLightLogic::LaneVector [inherited]

Definition of the list of links that participate in this tl-light.

Definition at line 72 of file MSTrafficLightLogic.h.

typedef std::vector<LaneVector> MSTrafficLightLogic::LaneVectorVector [inherited]

Definition of a list that holds lists of links that do have the same attribute.

Definition at line 75 of file MSTrafficLightLogic.h.

typedef std::vector<MSLink*> MSTrafficLightLogic::LinkVector [inherited]

Definition of the list of links that participate in this tl-light.

Definition at line 66 of file MSTrafficLightLogic.h.

typedef std::vector<LinkVector> MSTrafficLightLogic::LinkVectorVector [inherited]

Definition of a list that holds lists of links that do have the same attribute.

Definition at line 69 of file MSTrafficLightLogic.h.

typedef std::vector<MSPhaseDefinition*> MSTrafficLightLogic::Phases [inherited]

Definition of a list of phases, being the junction logic.

Definition at line 63 of file MSTrafficLightLogic.h.


Constructor & Destructor Documentation

MSSimpleTrafficLightLogic::MSSimpleTrafficLightLogic ( MSTLLogicControl tlcontrol,
const std::string &  id,
const std::string &  subid,
const Phases phases,
unsigned int  step,
SUMOTime  delay 
) throw ()

Constructor.

Parameters:
[in] tlcontrol The tls control responsible for this tls
[in] id This tls' id
[in] subid This tls' sub-id (program id)
[in] phases Definitions of the phases
[in] step The initial phase index
[in] delay The time to wait before the first switch

Definition at line 47 of file MSSimpleTrafficLightLogic.cpp.

00050         : MSTrafficLightLogic(tlcontrol, id, subid, delay), myPhases(phases),
00051         myStep(step) {
00052     for (size_t i=0; i<myPhases.size(); i++) {
00053         myDefaultCycleTime += myPhases[i]->duration;
00054     }
00055 }

MSSimpleTrafficLightLogic::~MSSimpleTrafficLightLogic (  )  throw ()

Destructor.

Definition at line 58 of file MSSimpleTrafficLightLogic.cpp.

References myPhases.

00058                                                               {
00059     for (size_t i=0; i<myPhases.size(); i++) {
00060         delete myPhases[i];
00061     }
00062 }


Member Function Documentation

void MSTrafficLightLogic::adaptLinkInformationFrom ( const MSTrafficLightLogic logic  )  throw () [virtual, inherited]

Applies information about controlled links and lanes from the given logic.

If we load a logic after the network has been loaded, we do not get the information about controlled links afterwards. We have to copy them from a previously loaded logic.

Parameters:
[in] logic The logic to use the information about controlled links/lanes from

Reimplemented in MSOffTrafficLightLogic.

Definition at line 139 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLanes, and MSTrafficLightLogic::myLinks.

Referenced by MSOffTrafficLightLogic::adaptLinkInformationFrom().

00139                                                                                       {
00140     myLinks = logic.myLinks;
00141     myLanes = logic.myLanes;
00142 }

void MSTrafficLightLogic::addLink ( MSLink link,
MSLane lane,
unsigned int  pos 
) throw () [inherited]

Adds a link on building.

Parameters:
[in] link The controlled link
[in] lane The lane this link starts at
[in] pos The link's index (signal group) within this program

Definition at line 122 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLanes, and MSTrafficLightLogic::myLinks.

00122                                                                                  {
00123     // !!! should be done within the loader (checking necessary)
00124     myLinks.reserve(pos+1);
00125     while (myLinks.size()<=pos) {
00126         myLinks.push_back(LinkVector());
00127     }
00128     myLinks[pos].push_back(link);
00129     //
00130     myLanes.reserve(pos+1);
00131     while (myLanes.size()<=pos) {
00132         myLanes.push_back(LaneVector());
00133     }
00134     myLanes[pos].push_back(lane);
00135 }

void MSTrafficLightLogic::addOverridingDuration ( SUMOTime  duration  )  throw () [inherited]

Changes the duration of the next phase.

Parameters:
[in] duration The new duration

Definition at line 198 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myOverridingTimes.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic(), and MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic().

00198                                                                     {
00199     myOverridingTimes.push_back(duration);
00200 }

void MSSimpleTrafficLightLogic::changeStepAndDuration ( MSTLLogicControl tlcontrol,
SUMOTime  simStep,
unsigned int  step,
SUMOTime  stepDuration 
) throw () [virtual]

Changes the current phase and her duration.

Parameters:
[in] tlcontrol The responsible traffic lights control
[in] simStep The current simulation step
[in] step Index of the phase to use
[in] stepDuration The left duration of the phase
See also:
MSTrafficLightLogic::changeStepAndDuration

Implements MSTrafficLightLogic.

Definition at line 218 of file MSSimpleTrafficLightLogic.cpp.

References MSEventControl::ADAPT_AFTER_EXECUTION, MSEventControl::addEvent(), MSTrafficLightLogic::SwitchCommand::deschedule(), MSNet::getBeginOfTimestepEvents(), MSNet::getInstance(), myStep, and MSTrafficLightLogic::mySwitchCommand.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), GUIViewTraffic::onGamingClick(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

00219                                                                             {
00220     mySwitchCommand->deschedule(this);
00221     mySwitchCommand = new SwitchCommand(tlcontrol, this, stepDuration+simStep);
00222     myStep = step;
00223     MSNet::getInstance()->getBeginOfTimestepEvents().addEvent(
00224         mySwitchCommand, stepDuration+simStep,
00225         MSEventControl::ADAPT_AFTER_EXECUTION);
00226 }

std::map< MSLink *, std::pair< MSLink::LinkState, bool > > MSTrafficLightLogic::collectLinkStates (  )  const throw () [inherited]

Returns the (uncontrolled) states of the controlled links.

Returns:
The controlled link's states

Definition at line 146 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks.

Referenced by MSTLLogicControl::TLSLogicVariants::saveInitialStates().

00146                                                      {
00147     std::map<MSLink*, std::pair<MSLink::LinkState, bool> > ret;
00148     for (LinkVectorVector::const_iterator i1=myLinks.begin(); i1!=myLinks.end(); ++i1) {
00149         const LinkVector &l = (*i1);
00150         for (LinkVector::const_iterator i2=l.begin(); i2!=l.end(); ++i2) {
00151             ret[*i2] = std::make_pair((*i2)->getState(), (*i2)->havePriority());
00152         }
00153     }
00154     return ret;
00155 }

const MSPhaseDefinition & MSSimpleTrafficLightLogic::getCurrentPhaseDef (  )  const throw () [virtual]

Returns the definition of the current phase.

Returns:
The current phase
See also:
MSTrafficLightLogic::getCurrentPhaseDef

Implements MSTrafficLightLogic.

Definition at line 159 of file MSSimpleTrafficLightLogic.cpp.

References myPhases, and myStep.

Referenced by MSAgentbasedTrafficLightLogic::collectData(), MSActuatedTrafficLightLogic::duration(), MSActuatedTrafficLightLogic::gapControl(), and MSAgentbasedTrafficLightLogic::trySwitch().

00159                                                             {
00160     return *myPhases[myStep];
00161 }

unsigned int MSSimpleTrafficLightLogic::getCurrentPhaseIndex (  )  const throw () [virtual]

Returns the current index within the program.

Returns:
The index of the current phase within the tls
See also:
MSTrafficLightLogic::getCurrentPhaseIndex

Implements MSTrafficLightLogic.

Definition at line 153 of file MSSimpleTrafficLightLogic.cpp.

References myStep.

00153                                                               {
00154     return myStep;
00155 }

unsigned int MSTrafficLightLogic::getDefaultCycleTime (  )  const throw () [inline, inherited]

Returns the cycle time.

Returns:
The (maybe changing) cycle time of this tls

Definition at line 261 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myDefaultCycleTime.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), and MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP().

00261                                                      {
00262         return myDefaultCycleTime;
00263     }

const std::string& MSTrafficLightLogic::getID (  )  const throw () [inline, inherited]

unsigned int MSSimpleTrafficLightLogic::getIndexFromOffset ( unsigned int  offset  )  const throw () [virtual]

Returns the step (the phasenumber) of a given position of the cycle.

Parameters:
[in] offset The offset (time) for which the according phase shall be returned
Returns:
The according phase
See also:
MSTrafficLightLogic::getIndexFromOffset

Implements MSTrafficLightLogic.

Definition at line 195 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, getPhase(), MSTrafficLightLogic::myDefaultCycleTime, and myPhases.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic(), MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

00195                                                                                {
00196     assert(offset <= myDefaultCycleTime);
00197     if (offset == myDefaultCycleTime) {
00198         return 0;
00199     }
00200     unsigned int pos = offset;
00201     unsigned int testPos = 0;
00202     for (unsigned int i=0; i < myPhases.size(); i++)    {
00203         testPos = testPos + getPhase(i).duration;
00204         if (testPos > pos) {
00205             return i;
00206         }
00207         if (testPos == pos) {
00208             assert(myPhases.size() > (i+1));
00209             return (i+1);
00210         }
00211     }
00212     return 0;
00213 }

const LaneVectorVector& MSTrafficLightLogic::getLanes (  )  const throw () [inline, inherited]

Returns the list of lists of all lanes controlled by this tls.

Returns:
All lanes controlled by this tls, sorted by the signal index

Definition at line 184 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLanes.

Referenced by GUITrafficLightLogicWrapper::getCenteringBoundary(), and TraCIServerAPI_TLS::processGet().

00184                                                      {
00185         return myLanes;
00186     }

const LaneVector& MSTrafficLightLogic::getLanesAt ( unsigned int  i  )  const throw () [inline, inherited]

Returns the list of lanes that are controlled by the signals at the given position.

Parameters:
[in] i The index of the signal
Returns:
The lanes controlled by the signal at the given index

Definition at line 193 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLanes.

Referenced by MSAgentbasedTrafficLightLogic::collectData(), traci::TraCIServer::commandGetTLStatus(), MSUnboundActuatedTrafficLightLogic::duration(), MSActuatedTrafficLightLogic::duration(), Command_SaveTLSSwitches::execute(), MSUnboundActuatedTrafficLightLogic::gapControl(), MSActuatedTrafficLightLogic::gapControl(), traci::TraCIServer::handleTrafficLightDomain(), and GUIViewTraffic::onGamingClick().

00193                                                                {
00194         return myLanes[i];
00195     }

int MSTrafficLightLogic::getLinkIndex ( const MSLink *const   link  )  const throw () [inherited]

Returns the index of the given link.

Parameters:
[in] link The link to retrieve the index for
Returns:
The index of the given link (-1 if it is not controlled by this tls)

Definition at line 174 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks.

Referenced by GUITrafficLightLogicWrapper::getLinkIndex().

00174                                                                          {
00175     int index = 0;
00176     for (LinkVectorVector::const_iterator i1=myLinks.begin(); i1!=myLinks.end(); ++i1, ++index) {
00177         const LinkVector &l = (*i1);
00178         for (LinkVector::const_iterator i2=l.begin(); i2!=l.end(); ++i2) {
00179             if ((*i2)==link) {
00180                 return index;
00181             }
00182         }
00183     }
00184     return -1;
00185 }

const LinkVectorVector& MSTrafficLightLogic::getLinks (  )  const throw () [inline, inherited]

const LinkVector& MSTrafficLightLogic::getLinksAt ( unsigned int  i  )  const throw () [inline, inherited]

Returns the list of links that are controlled by the signals at the given position.

Parameters:
[in] i The index of the signal
Returns:
The links controlled by the signal at the given index

Definition at line 210 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLinks.

00210                                                                {
00211         return myLinks[i];
00212     }

SUMOTime MSTrafficLightLogic::getNextSwitchTime (  )  const throw () [inherited]

Returns the assumed next switch time.

The time may change in case of adaptive/actuated traffic lights.

Returns:
The assumed next switch time (simulation time)

Definition at line 191 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::SwitchCommand::getNextSwitchTime(), and MSTrafficLightLogic::mySwitchCommand.

Referenced by TraCIServerAPI_TLS::processGet().

00191                                                      {
00192     return mySwitchCommand!=0 ? mySwitchCommand->getNextSwitchTime() : -1;
00193 }

unsigned int MSSimpleTrafficLightLogic::getOffsetFromIndex ( unsigned int  index  )  const throw () [virtual]

Returns the position (start of a phase during a cycle) from of a given step.

Parameters:
[in] index The index of the phase to return the begin of
Returns:
The begin time of the phase
See also:
MSTrafficLightLogic::getOffsetFromIndex

Implements MSTrafficLightLogic.

Definition at line 181 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, getPhase(), and myPhases.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic(), MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), and MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic().

00181                                                                               {
00182     assert(index < myPhases.size());
00183     if (index == 0) {
00184         return 0;
00185     }
00186     unsigned int pos = 0;
00187     for (unsigned int i=0; i < index; i++)  {
00188         pos += getPhase(i).duration;
00189     }
00190     return pos;
00191 }

std::string MSTrafficLightLogic::getParameterValue ( const std::string &  key  )  const throw () [inherited]

Returns a named parameter.

Parameters:
[in] key The name of the parameter
Returns:
The value of the parameter, "" if the parameter is not known

Definition at line 219 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myParameter.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereichDef(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereicheNo(), and MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic().

00219                                                                          {
00220     if (myParameter.find(key)==myParameter.end()) {
00221         return "";
00222     }
00223     return myParameter.find(key)->second;
00224 }

const MSPhaseDefinition & MSSimpleTrafficLightLogic::getPhase ( unsigned int  givenstep  )  const throw () [virtual]

Returns the definition of the phase from the given position within the plan.

Parameters:
[in] givenstep The index of the phase within the plan
Returns:
The definition of the phase at the given position
See also:
MSTrafficLightLogic::getPhase

Implements MSTrafficLightLogic.

Definition at line 145 of file MSSimpleTrafficLightLogic.cpp.

References myPhases.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic(), MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), getIndexFromOffset(), getOffsetFromIndex(), getPhaseIndexAtTime(), GUIViewTraffic::onGamingClick(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

00145                                                                         {
00146     assert(myPhases.size()>givenStep);
00147     return *myPhases[givenStep];
00148 }

unsigned int MSSimpleTrafficLightLogic::getPhaseIndexAtTime ( SUMOTime  simStep  )  const throw () [virtual]

Returns the index of the logic at the given simulation step.

Returns:
The (estimated) index of the tls at the given simulation time step
See also:
MSTrafficLightLogic::getPhaseIndexAtTime

Implements MSTrafficLightLogic.

Definition at line 166 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, getPhase(), MSTrafficLightLogic::myDefaultCycleTime, MSPhaseDefinition::myLastSwitch, and myStep.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::adaptLogic(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic().

00166                                                                              {
00167     unsigned int position = 0;
00168     if (myStep > 0) {
00169         for (unsigned int i=0; i < myStep; i++) {
00170             position = position + getPhase(i).duration;
00171         }
00172     }
00173     position = position + simStep - getPhase(myStep).myLastSwitch;
00174     position = position % myDefaultCycleTime;
00175     assert(position <= myDefaultCycleTime);
00176     return position;
00177 }

unsigned int MSSimpleTrafficLightLogic::getPhaseNumber (  )  const throw () [virtual]

Returns the number of phases.

Returns:
The number of this tls program's phases
See also:
MSTrafficLightLogic::getPhaseNumber

Implements MSTrafficLightLogic.

Definition at line 127 of file MSSimpleTrafficLightLogic.cpp.

References myPhases.

00127                                                         {
00128     return (unsigned int) myPhases.size();
00129 }

MSSimpleTrafficLightLogic::Phases & MSSimpleTrafficLightLogic::getPhases (  )  throw ()

Returns the phases of this tls program.

Returns:
The phases of this tls program
Todo:
Recheck!

Definition at line 139 of file MSSimpleTrafficLightLogic.cpp.

References myPhases.

00139                                              {
00140     return myPhases;
00141 }

const MSSimpleTrafficLightLogic::Phases & MSSimpleTrafficLightLogic::getPhases (  )  const throw () [virtual]

Returns the phases of this tls program.

Returns:
The phases of this tls program
See also:
MSTrafficLightLogic::getPhases

Implements MSTrafficLightLogic.

Definition at line 133 of file MSSimpleTrafficLightLogic.cpp.

References myPhases.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic(), and MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic().

00133                                                    {
00134     return myPhases;
00135 }

const std::string& MSTrafficLightLogic::getSubID (  )  const throw () [inline, inherited]

Returns this tl-logic's id.

Returns:
This program's id

Definition at line 176 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::mySubID.

Referenced by Command_SaveTLSSwitchStates::execute(), Command_SaveTLSSwitches::execute(), Command_SaveTLSState::execute(), GUIViewTraffic::onGamingClick(), and TraCIServerAPI_TLS::processGet().

00176                                               {
00177         return mySubID;
00178     }

void MSTrafficLightLogic::init ( NLDetectorBuilder nb  )  throw (ProcessError) [virtual, inherited]

Initialises the tls with information about incoming lanes.

Parameters:
[in] nb The detector builder
[in] edgeContinuations Information about edge predecessors/successors
Exceptions:
ProcessError If something fails on initialisation

Reimplemented in MSActuatedTrafficLightLogic, MSAgentbasedTrafficLightLogic, and MSOffTrafficLightLogic.

Definition at line 111 of file MSTrafficLightLogic.cpp.

00111                                                                  {
00112 }

void MSTrafficLightLogic::resetLinkStates ( const std::map< MSLink *, std::pair< MSLink::LinkState, bool > > &  vals  )  const throw () [inherited]

Resets the states of controlled links.

Parameters:
[in] The state of controlled links to use

Definition at line 159 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks.

Referenced by MSTLLogicControl::TLSLogicVariants::switchTo().

00159                                                                                                                {
00160     for (LinkVectorVector::const_iterator i1=myLinks.begin(); i1!=myLinks.end(); ++i1) {
00161         const LinkVector &l = (*i1);
00162         for (LinkVector::const_iterator i2=l.begin(); i2!=l.end(); ++i2) {
00163             assert(vals.find(*i2)!=vals.end());
00164             const std::pair<MSLink::LinkState, bool> &lvals = vals.find(*i2)->second;
00165             (*i2)->setTLState(lvals.first);
00166             (*i2)->setPriority(lvals.second);
00167         }
00168     }
00169 }

void MSTrafficLightLogic::setCurrentDurationIncrement ( SUMOTime  delay  )  throw () [inherited]

Delays current phase by the given delay.

Parameters:
[in] delay The time by which the current phase shall be delayed

Definition at line 204 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myCurrentDurationIncrement.

00204                                                                        {
00205     myCurrentDurationIncrement = delay;
00206 }

void MSSimpleTrafficLightLogic::setLinkPriorities (  )  const throw () [virtual]

Applies the priorities resulting from the current phase to controlled links.

Todo:
Check whether this can be integrated into "setTrafficLightSignals"
See also:
MSTrafficLightLogic::setLinkPriorities

Implements MSTrafficLightLogic.

Definition at line 97 of file MSSimpleTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks, myPhases, and myStep.

00097                                                            {
00098     const std::string &state = myPhases[myStep]->getState();
00099     for (size_t i=0; i<myLinks.size(); i++) {
00100         bool hasPriority = (state[i]>='A'&&state[i]<='Z');
00101         const LinkVector &currGroup = myLinks[i];
00102         for (LinkVector::const_iterator j=currGroup.begin(); j!=currGroup.end(); j++) {
00103             (*j)->setPriority(hasPriority);
00104         }
00105     }
00106 }

void MSTrafficLightLogic::setParameter ( const std::map< std::string, std::string > &  params  )  throw () [inherited]

Inserts read parameter.

Parameters:
[in] params The parameter to use

Definition at line 213 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myParameter.

Referenced by NLJunctionControlBuilder::closeTrafficLightLogic().

00213                                                                                     {
00214     myParameter = params;
00215 }

bool MSSimpleTrafficLightLogic::setTrafficLightSignals (  )  const throw () [virtual]

Clears all incoming vehicle information on links that have red.

Returns:
Always true

Implements MSTrafficLightLogic.

Definition at line 110 of file MSSimpleTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks, myPhases, and myStep.

00110                                                                 {
00111     // get the current traffic light signal combination
00112     const std::string &state = myPhases[myStep]->getState();
00113     // go through the links
00114     for (size_t i=0; i<myLinks.size(); i++) {
00115         const LinkVector &currGroup = myLinks[i];
00116         MSLink::LinkState ls = (MSLink::LinkState) state[i];
00117         for (LinkVector::const_iterator j=currGroup.begin(); j!=currGroup.end(); j++) {
00118             (*j)->setTLState(ls);
00119         }
00120     }
00121     return true;
00122 }

SUMOTime MSSimpleTrafficLightLogic::trySwitch ( bool  isActive  )  throw () [virtual]

Switches to the next phase.

Parameters:
[in] isActive Whether this program is the currently used one
Returns:
The time of the next switch
See also:
MSTrafficLightLogic::trySwitch

Implements MSTrafficLightLogic.

Reimplemented in MSActuatedTrafficLightLogic, MSAgentbasedTrafficLightLogic, and MSUnboundActuatedTrafficLightLogic.

Definition at line 67 of file MSSimpleTrafficLightLogic.cpp.

References MSNet::getCurrentTimeStep(), MSNet::getInstance(), MSTrafficLightLogic::myCurrentDurationIncrement, MSTrafficLightLogic::myOverridingTimes, myPhases, and myStep.

00067                                                  {
00068     // check whether the current duration shall be increased
00069     if (myCurrentDurationIncrement>0) {
00070         SUMOTime delay = myCurrentDurationIncrement;
00071         myCurrentDurationIncrement = 0;
00072         return delay;
00073     }
00074 
00075     // increment the index
00076     myStep++;
00077     // if the last phase was reached ...
00078     if (myStep==myPhases.size()) {
00079         // ... set the index to the first phase
00080         myStep = 0;
00081     }
00082     assert(myPhases.size()>myStep);
00083     //stores the time the phase started
00084     myPhases[myStep]->myLastSwitch = MSNet::getInstance()->getCurrentTimeStep();
00085     // check whether the next duration was overridden
00086     if (myOverridingTimes.size()>0) {
00087         SUMOTime nextDuration = myOverridingTimes[0];
00088         myOverridingTimes.erase(myOverridingTimes.begin());
00089         return nextDuration;
00090     }
00091     // return offset to the next switch
00092     return myPhases[myStep]->duration;
00093 }


Field Documentation

A value for enlarge the current duration.

Definition at line 427 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::setCurrentDurationIncrement(), and trySwitch().

unsigned int MSTrafficLightLogic::myDefaultCycleTime [protected, inherited]

The cycle time (without changes).

Definition at line 433 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::getDefaultCycleTime(), getIndexFromOffset(), and getPhaseIndexAtTime().

std::string MSTrafficLightLogic::myID [protected, inherited]

The id of the logic.

Definition at line 415 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::getID().

The list of links which do participate in this traffic light.

Definition at line 421 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::adaptLinkInformationFrom(), MSTrafficLightLogic::addLink(), MSTrafficLightLogic::getLanes(), and MSTrafficLightLogic::getLanesAt().

std::vector<SUMOTime> MSTrafficLightLogic::myOverridingTimes [protected, inherited]

A list of duration overrides.

Definition at line 424 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::addOverridingDuration(), and trySwitch().

std::map<std::string, std::string> MSTrafficLightLogic::myParameter [protected, inherited]

Given parameter.

Definition at line 412 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::getParameterValue(), and MSTrafficLightLogic::setParameter().

unsigned int MSSimpleTrafficLightLogic::myStep [protected]

std::string MSTrafficLightLogic::mySubID [protected, inherited]

Definition at line 415 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::getSubID().


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

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