MSUnboundActuatedTrafficLightLogic Class Reference

#include <MSUnboundActuatedTrafficLightLogic.h>

Inheritance diagram for MSUnboundActuatedTrafficLightLogic:

MSSimpleTrafficLightLogic MSTrafficLightLogic

Detailed Description

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 61 of file MSUnboundActuatedTrafficLightLogic.h.


Public Types

typedef std::map< MSLane
*, MSInductLoop * > 
InductLoopMap
 Definition of a map from lanes to induct loops lying on them.
typedef std::map< MSLane
*, MSLaneState * > 
LaneStateMap
 Definition of a map from lanes to lane state detectors lying on them.
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

SUMOTime duration () const
 Returns the duration of the given step.
bool gapControl ()
 Desides, whether a phase should be continued by checking the gaps of vehicles having green.
virtual void init (NLDetectorBuilder &nb) throw (ProcessError)
 Initialises the tls with information about incoming lanes.
void init (NLDetectorBuilder &nb, const std::vector< MSLane * > &lanes, std::map< std::string, std::vector< std::string > > &edgeContinuations, SUMOReal det_offset)
 Initialises the tls with information about incoming lanes.
bool isGreenPhase () const
 MSUnboundActuatedTrafficLightLogic (const std::string &id, const MSSimpleTrafficLightLogic::Phases &phases, size_t step, size_t delay, SUMOReal maxGap, SUMOReal passingTime, SUMOReal detectorGap)
 constructor
SUMOTime trySwitch (bool isActive)
 Switches to the next phase Returns the time of the next switch.
 ~MSUnboundActuatedTrafficLightLogic ()
 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.

Protected Member Functions

MSActuatedPhaseDefinition * currentPhaseDef () const
 Returns the definition of the current phase.

Protected Attributes

bool myContinue
 information whether the current phase should be lenghtend
SUMOTime myCurrentDurationIncrement
 A value for enlarge the current duration.
unsigned int myDefaultCycleTime
 The cycle time (without changes).
SUMOReal myDetectorGap
 The detector distance.
std::string myID
 The id of the logic.
InductLoopMap myInductLoops
 A map from lanes to induct loops lying on them.
LaneVectorVector myLanes
 The list of links which do participate in this traffic light.
LaneStateMap myLaneStates
 A map from lanes to lane states lying on them.
LinkVectorVector myLinks
 The list of links which do participate in this traffic light.
SUMOReal myMaxGap
 The maximum gap to check.
std::vector< SUMOTimemyOverridingTimes
 A list of duration overrides.
std::map< std::string,
std::string > 
myParameter
 Given parameter.
SUMOReal myPassingTime
 The passing time used.
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

Definition of a map from lanes to induct loops lying on them.

Definition at line 65 of file MSUnboundActuatedTrafficLightLogic.h.

typedef std::map<MSLane*, MSLaneState*> MSUnboundActuatedTrafficLightLogic::LaneStateMap

Definition of a map from lanes to lane state detectors lying on them.

Definition at line 68 of file MSUnboundActuatedTrafficLightLogic.h.

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

MSUnboundActuatedTrafficLightLogic::MSUnboundActuatedTrafficLightLogic ( const std::string &  id,
const MSSimpleTrafficLightLogic::Phases phases,
size_t  step,
size_t  delay,
SUMOReal  maxGap,
SUMOReal  passingTime,
SUMOReal  detectorGap 
)

constructor

MSUnboundActuatedTrafficLightLogic::~MSUnboundActuatedTrafficLightLogic (  ) 

destructor

Definition at line 113 of file MSUnboundActuatedTrafficLightLogic.cpp.

00113 {}


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, inherited]

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(), MSSimpleTrafficLightLogic::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 }

MSActuatedPhaseDefinition * MSUnboundActuatedTrafficLightLogic::currentPhaseDef (  )  const [protected]

Returns the definition of the current phase.

Definition at line 225 of file MSUnboundActuatedTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::myStep.

Referenced by duration(), gapControl(), and isGreenPhase().

00225                                                           {
00226     assert(myPhases.size()>myStep);
00227     return static_cast<MSActuatedPhaseDefinition*>(myPhases[myStep]);
00228 }

SUMOTime MSUnboundActuatedTrafficLightLogic::duration (  )  const

Returns the duration of the given step.

Definition at line 117 of file MSUnboundActuatedTrafficLightLogic.cpp.

References currentPhaseDef(), MSTrafficLightLogic::getLanesAt(), isGreenPhase(), myContinue, myLaneStates, myPassingTime, MSSimpleTrafficLightLogic::myPhases, MSSimpleTrafficLightLogic::myStep, and SUMOReal.

Referenced by trySwitch().

00117                                                    {
00118     if (myContinue) {
00119         return 1;
00120     }
00121     assert(myPhases.size()>myStep);
00122     if (!isGreenPhase()) {
00123         return currentPhaseDef()->duration;
00124     }
00125     // define the duration depending from the number of waiting vehicles of the actual phase
00126     int newduration = currentPhaseDef()->minDuration;
00127     const std::bitset<64> &isgreen = currentPhaseDef()->getDriveMask();
00128     for (size_t i=0; i<isgreen.size(); i++)  {
00129         if (isgreen.test(i))  {
00130             const std::vector<MSLane*> &lanes = getLanesAt(i);
00131             if (lanes.empty())    {
00132                 break;
00133             }
00134             for (LaneVector::const_iterator j=lanes.begin(); j!=lanes.end(); j++) {
00135                 LaneStateMap::const_iterator k = myLaneStates.find(*j);
00136                 SUMOReal waiting = (*k).second->getCurrentNumberOfWaiting();
00137                 SUMOReal tmpdur =  myPassingTime * waiting;
00138                 if (tmpdur > newduration) {
00139                     // here we cut the decimal places, because we have to return an integer
00140                     newduration = (int) tmpdur;
00141                 }
00142                 if (newduration > (int) currentPhaseDef()->maxDuration)  {
00143                     return currentPhaseDef()->maxDuration;
00144                 }
00145             }
00146         }
00147     }
00148     return newduration;
00149 }

bool MSUnboundActuatedTrafficLightLogic::gapControl (  ) 

Desides, whether a phase should be continued by checking the gaps of vehicles having green.

Definition at line 186 of file MSUnboundActuatedTrafficLightLogic.cpp.

References currentPhaseDef(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), MSTrafficLightLogic::getLanesAt(), isGreenPhase(), myContinue, myInductLoops, myMaxGap, MSSimpleTrafficLightLogic::myPhases, MSSimpleTrafficLightLogic::myStep, and SUMOReal.

Referenced by trySwitch().

00186                                                {
00187     //intergreen times should not be lenghtend
00188     assert(myPhases.size()>myStep);
00189     if (!isGreenPhase()) {
00190         return myContinue = false;
00191     }
00192 
00193     // Checks, if the maxDuration is kept. No phase should longer send than maxDuration.
00194     SUMOTime actDuration =
00195         MSNet::getInstance()->getCurrentTimeStep() - static_cast<MSActuatedPhaseDefinition*>(myPhases[myStep])->myLastSwitch;
00196     if (actDuration >= currentPhaseDef()->maxDuration) {
00197         return myContinue = false;
00198     }
00199 
00200     // now the gapcontrol starts
00201     const std::bitset<64> &isgreen = currentPhaseDef()->getDriveMask();
00202     for (size_t i=0; i<isgreen.size(); i++)  {
00203         if (isgreen.test(i))  {
00204             const std::vector<MSLane*> &lanes = getLanesAt(i);
00205             if (lanes.empty())    {
00206                 break;
00207             }
00208             for (LaneVector::const_iterator j=lanes.begin(); j!=lanes.end(); j++) {
00209                 if (myInductLoops.find(*j)==myInductLoops.end()) {
00210                     continue;
00211                 }
00212                 SUMOReal actualGap =
00213                     myInductLoops.find(*j)->second->getTimestepsSinceLastDetection();
00214                 if (actualGap < myMaxGap) {
00215                     return myContinue = true;
00216                 }
00217             }
00218         }
00219     }
00220     return myContinue = false;
00221 }

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

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

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 MSSimpleTrafficLightLogic::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, inherited]

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, MSSimpleTrafficLightLogic::getPhase(), MSTrafficLightLogic::myDefaultCycleTime, and MSSimpleTrafficLightLogic::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(), duration(), MSActuatedTrafficLightLogic::duration(), Command_SaveTLSSwitches::execute(), 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, inherited]

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, MSSimpleTrafficLightLogic::getPhase(), and MSSimpleTrafficLightLogic::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, inherited]

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

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, MSSimpleTrafficLightLogic::getPhase(), MSTrafficLightLogic::myDefaultCycleTime, MSPhaseDefinition::myLastSwitch, and MSSimpleTrafficLightLogic::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, inherited]

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 MSSimpleTrafficLightLogic::myPhases.

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

MSSimpleTrafficLightLogic::Phases & MSSimpleTrafficLightLogic::getPhases (  )  throw () [inherited]

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 MSSimpleTrafficLightLogic::myPhases.

00139                                              {
00140     return myPhases;
00141 }

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

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 MSSimpleTrafficLightLogic::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 MSUnboundActuatedTrafficLightLogic::init ( NLDetectorBuilder nb,
const std::vector< MSLane * > &  lanes,
std::map< std::string, std::vector< std::string > > &  edgeContinuations,
SUMOReal  det_offset 
)

Initialises the tls with information about incoming lanes.

Definition at line 61 of file MSUnboundActuatedTrafficLightLogic.cpp.

References NLDetectorBuilder::createInductLoop(), MSLane::getID(), myDetectorGap, myInductLoops, myLaneStates, and SUMOReal.

00064                              {
00065     // change values for setting the loops and lanestate-detectors, here
00066     SUMOTime inductLoopInterval = 1; //
00067     // as the laneStateDetector shall end at the end of the lane, the position
00068     // is calculated, not given
00069     SUMOTime laneStateDetectorInterval = 1; //
00070 
00071     std::vector<MSLane*>::const_iterator i;
00072     // build the induct loops
00073     for (i=lanes.begin(); i!=lanes.end(); i++) {
00074         MSLane *lane = (*i);
00075         SUMOReal length = lane->length();
00076         SUMOReal speed = lane->maxSpeed();
00077         SUMOReal inductLoopPosition = myDetectorGap * speed;
00078         // check whether the lane is long enough
00079         SUMOReal ilpos = length - inductLoopPosition;
00080         if (ilpos<0) {
00081             ilpos = 0;
00082         }
00083         // Build the induct loop and set it into the container
00084         std::string id = "TLS" + myId + "_InductLoopOn_" + lane->getID();
00085         if (myInductLoops.find(lane)==myInductLoops.end()) {
00086             myInductLoops[lane] =
00087                 nb.createInductLoop(id, lane, ilpos, inductLoopInterval);
00088         }
00089     }
00090     // build the lane state-detectors
00091     for (i=lanes.begin(); i!=lanes.end(); i++) {
00092         MSLane *lane = (*i);
00093         SUMOReal length = lane->length();
00094         // check whether the position is o.k. (not longer than the lane)
00095         SUMOReal lslen = det_offset;
00096         if (lslen>length) {
00097             lslen = length;
00098         }
00099         SUMOReal lspos = length - lslen;
00100         // Build the lane state detetcor and set it into the container
00101         std::string id = "TLS" + myId + "_LaneStateOff_" + lane->getID();
00102         if (myLaneStates.find(lane)==myLaneStates.end()) {
00103             MSLaneState* loop =
00104                 new MSLaneState(id, lane, lspos, lslen,
00105                                 laneStateDetectorInterval);
00106             myLaneStates[lane] = loop;
00107         }
00108     }
00109 }

bool MSUnboundActuatedTrafficLightLogic::isGreenPhase (  )  const

Definition at line 174 of file MSUnboundActuatedTrafficLightLogic.cpp.

References currentPhaseDef().

Referenced by duration(), and gapControl().

00174                                                        {
00175     if (currentPhaseDef()->getDriveMask().none()) {
00176         return false;
00177     }
00178     if (currentPhaseDef()->getYellowMask().any()) {
00179         return false;
00180     }
00181     return true;
00182 }

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, inherited]

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, MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::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, inherited]

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, MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::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 MSUnboundActuatedTrafficLightLogic::trySwitch ( bool  isActive  )  [virtual]

Switches to the next phase Returns the time of the next switch.

Reimplemented from MSSimpleTrafficLightLogic.

Definition at line 153 of file MSUnboundActuatedTrafficLightLogic.cpp.

References duration(), gapControl(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), myContinue, MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::myStep.

00153                                                   {
00154     // checks if the actual phase should be continued
00155     gapControl();
00156     if (myContinue) {
00157         return duration();
00158     }
00159     // increment the index to the current phase
00160     myStep++;
00161     assert(myStep<=myPhases.size());
00162     if (myStep==myPhases.size()) {
00163         myStep = 0;
00164     }
00165     //stores the time the phase started
00166     static_cast<MSActuatedPhaseDefinition*>(myPhases[myStep])->myLastSwitch =
00167         MSNet::getInstance()->getCurrentTimeStep();
00168     // set the next event
00169     return duration();
00170 }


Field Documentation

information whether the current phase should be lenghtend

Definition at line 111 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by duration(), gapControl(), and trySwitch().

A value for enlarge the current duration.

Definition at line 427 of file MSTrafficLightLogic.h.

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

unsigned int MSTrafficLightLogic::myDefaultCycleTime [protected, inherited]

The detector distance.

Definition at line 120 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by init().

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

The id of the logic.

Definition at line 415 of file MSTrafficLightLogic.h.

Referenced by MSTrafficLightLogic::getID().

A map from lanes to induct loops lying on them.

Definition at line 105 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by gapControl(), and init().

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().

A map from lanes to lane states lying on them.

Definition at line 108 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by duration(), and init().

The maximum gap to check.

Definition at line 114 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by gapControl().

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 MSSimpleTrafficLightLogic::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().

The passing time used.

Definition at line 117 of file MSUnboundActuatedTrafficLightLogic.h.

Referenced by duration().

unsigned int MSSimpleTrafficLightLogic::myStep [protected, inherited]

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:50 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6