MSActuatedTrafficLightLogic Class Reference

#include <MSActuatedTrafficLightLogic.h>

Inheritance diagram for MSActuatedTrafficLightLogic:

MSSimpleTrafficLightLogic MSTrafficLightLogic

Detailed Description

An actuated (adaptive) traffic light logic.

Definition at line 55 of file MSActuatedTrafficLightLogic.h.


Public Types

typedef std::map< MSLane
*, MSInductLoop * > 
InductLoopMap
 Definition of a map from lanes to induct loops 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

void init (NLDetectorBuilder &nb) throw (ProcessError)
 Initialises the tls with information about incoming lanes.
 MSActuatedTrafficLightLogic (MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const MSSimpleTrafficLightLogic::Phases &phases, unsigned int step, SUMOTime delay, SUMOReal maxGap, SUMOReal passingTime, SUMOReal detectorGap) throw ()
 Constructor.
 ~MSActuatedTrafficLightLogic () 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.
Switching and setting current rows
SUMOTime trySwitch (bool isActive) throw ()
 Switches to the next phase.

Protected Member Functions

"actuated" algorithm methods
SUMOTime duration () const throw ()
 Returns the duration of the given step.
void gapControl () throw ()
 Decides, whether a phase should be continued by checking the gaps of vehicles having green.

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.
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 59 of file MSActuatedTrafficLightLogic.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

MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic ( MSTLLogicControl tlcontrol,
const std::string &  id,
const std::string &  subid,
const MSSimpleTrafficLightLogic::Phases phases,
unsigned int  step,
SUMOTime  delay,
SUMOReal  maxGap,
SUMOReal  passingTime,
SUMOReal  detectorGap 
) 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
[in] maxGap !!!
[in] passingTime !!!
[in] detectorGap !!!

MSActuatedTrafficLightLogic::~MSActuatedTrafficLightLogic (  )  throw ()

Destructor.

Definition at line 101 of file MSActuatedTrafficLightLogic.cpp.

References myInductLoops.

00101                                                                   {
00102     for (InductLoopMap::iterator i=myInductLoops.begin(); i!=myInductLoops.end(); ++i) {
00103         delete(*i).second;
00104     }
00105 }


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 }

SUMOTime MSActuatedTrafficLightLogic::duration (  )  const throw () [protected]

Returns the duration of the given step.

Returns:
The wanted duration of the current step

Definition at line 131 of file MSActuatedTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, MSSimpleTrafficLightLogic::getCurrentPhaseDef(), MSTrafficLightLogic::getLanesAt(), MSPhaseDefinition::getState(), MSPhaseDefinition::isGreenPhase(), MSLink::LINKSTATE_TL_GREEN_MAJOR, MSLink::LINKSTATE_TL_GREEN_MINOR, MSPhaseDefinition::maxDuration, MSPhaseDefinition::minDuration, myContinue, myInductLoops, myPassingTime, MSSimpleTrafficLightLogic::myPhases, MSSimpleTrafficLightLogic::myStep, and SUMOReal.

Referenced by trySwitch().

00131                                                     {
00132     if (myContinue) {
00133         return 1;
00134     }
00135     assert(myPhases.size()>myStep);
00136     if (!getCurrentPhaseDef().isGreenPhase()) {
00137         return getCurrentPhaseDef().duration;
00138     }
00139     // define the duration depending from the number of waiting vehicles of the actual phase
00140     int newduration = (int) getCurrentPhaseDef().minDuration;
00141     const std::string &state = getCurrentPhaseDef().getState();
00142     for (unsigned int i=0; i<(unsigned int) state.size(); i++) {
00143         if (state[i]==MSLink::LINKSTATE_TL_GREEN_MAJOR||state[i]==MSLink::LINKSTATE_TL_GREEN_MINOR) {
00144             const std::vector<MSLane*> &lanes = getLanesAt(i);
00145             if (lanes.empty()) {
00146                 break;
00147             }
00148             for (LaneVector::const_iterator j=lanes.begin(); j!=lanes.end(); j++) {
00149                 InductLoopMap::const_iterator k = myInductLoops.find(*j);
00150                 SUMOReal waiting = (SUMOReal)(*k).second->getNVehContributed();
00151                 SUMOReal tmpdur =  myPassingTime * waiting;
00152                 if (tmpdur > newduration) {
00153                     // here we cut the decimal places, because we have to return an integer
00154                     newduration = (int) tmpdur;
00155                 }
00156                 if (newduration > (int) getCurrentPhaseDef().maxDuration)  {
00157                     return getCurrentPhaseDef().maxDuration;
00158                 }
00159             }
00160         }
00161     }
00162     return newduration;
00163 }

void MSActuatedTrafficLightLogic::gapControl (  )  throw () [protected]

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

Definition at line 167 of file MSActuatedTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::getCurrentPhaseDef(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), MSTrafficLightLogic::getLanesAt(), MSPhaseDefinition::getState(), MSPhaseDefinition::isGreenPhase(), MSLink::LINKSTATE_TL_GREEN_MAJOR, MSLink::LINKSTATE_TL_GREEN_MINOR, myContinue, myInductLoops, myMaxGap, MSSimpleTrafficLightLogic::myPhases, MSSimpleTrafficLightLogic::myStep, and SUMOReal.

Referenced by trySwitch().

00167                                                 {
00168     //intergreen times should not be lenghtend
00169     assert(myPhases.size()>myStep);
00170     if (!getCurrentPhaseDef().isGreenPhase()) {
00171         myContinue = false;
00172         return;
00173     }
00174 
00175     // Checks, if the maxDuration is kept. No phase should longer send than maxDuration.
00176     SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch;
00177     if (actDuration >= getCurrentPhaseDef().maxDuration) {
00178         myContinue = false;
00179         return;
00180     }
00181 
00182     // now the gapcontrol starts
00183     const std::string &state = getCurrentPhaseDef().getState();
00184     for (unsigned int i=0; i<(unsigned int) state.size(); i++)  {
00185         if (state[i]==MSLink::LINKSTATE_TL_GREEN_MAJOR||state[i]==MSLink::LINKSTATE_TL_GREEN_MINOR) {
00186             const std::vector<MSLane*> &lanes = getLanesAt(i);
00187             if (lanes.empty())    {
00188                 break;
00189             }
00190             for (LaneVector::const_iterator j=lanes.begin(); j!=lanes.end(); j++) {
00191                 if (myInductLoops.find(*j)==myInductLoops.end()) {
00192                     continue;
00193                 }
00194                 SUMOReal actualGap =
00195                     myInductLoops.find(*j)->second->getTimestepsSinceLastDetection();
00196                 if (actualGap < myMaxGap) {
00197                     myContinue = true;
00198                     return;
00199                 }
00200             }
00201         }
00202     }
00203     myContinue = false;
00204 }

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

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

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

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

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(), MSUnboundActuatedTrafficLightLogic::duration(), duration(), Command_SaveTLSSwitches::execute(), MSUnboundActuatedTrafficLightLogic::gapControl(), 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 MSActuatedTrafficLightLogic::init ( NLDetectorBuilder nb  )  throw (ProcessError) [virtual]

Initialises the tls with information about incoming lanes.

Parameters:
[in] nb The detector builder
Exceptions:
ProcessError If something fails on initialisation

Reimplemented from MSTrafficLightLogic.

Definition at line 61 of file MSActuatedTrafficLightLogic.cpp.

References TplConvert< E >::_2SUMOReal(), MSLane::getID(), MSLane::getLength(), MSLane::getMaxSpeed(), and SUMOReal.

00061                                                                            {
00062     SUMOReal det_offset = TplConvert<char>::_2SUMOReal(myParameter.find("detector_offset")->second.c_str());
00063     // change values for setting the loops and lanestate-detectors, here
00064     SUMOTime inductLoopInterval = 1; //
00065     LaneVectorVector::const_iterator i2;
00066     LaneVector::const_iterator i;
00067     // build the induct loops
00068     for (i2=myLanes.begin(); i2!=myLanes.end(); ++i2) {
00069         const LaneVector &lanes = *i2;
00070         for (i=lanes.begin(); i!=lanes.end(); i++) {
00071             MSLane *lane = (*i);
00072             SUMOReal length = lane->getLength();
00073             SUMOReal speed = lane->getMaxSpeed();
00074             SUMOReal inductLoopPosition = myDetectorGap * speed;
00075             // check whether the lane is long enough
00076             SUMOReal ilpos = length - inductLoopPosition;
00077             if (ilpos<0) {
00078                 ilpos = 0;
00079             }
00080             // Build the induct loop and set it into the container
00081             std::string id = "TLS" + myID + "_" + mySubID + "_InductLoopOn_" + lane->getID();
00082             if (myInductLoops.find(lane)==myInductLoops.end()) {
00083                 myInductLoops[lane] =
00084                     nb.createInductLoop(id, lane, ilpos);
00085             }
00086         }
00087         // build the lane state-detectors
00088         for (i=lanes.begin(); i!=lanes.end(); i++) {
00089             MSLane *lane = (*i);
00090             SUMOReal length = lane->getLength();
00091             // check whether the position is o.k. (not longer than the lane)
00092             SUMOReal lslen = det_offset;
00093             if (lslen>length) {
00094                 lslen = length;
00095             }
00096         }
00097     }
00098 }

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 MSActuatedTrafficLightLogic::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

Reimplemented from MSSimpleTrafficLightLogic.

Definition at line 110 of file MSActuatedTrafficLightLogic.cpp.

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

00110                                                    {
00111     // checks if the actual phase should be continued
00112     gapControl();
00113     if (myContinue) {
00114         return duration();
00115     }
00116     // increment the index to the current phase
00117     myStep++;
00118     assert(myStep<=myPhases.size());
00119     if (myStep==myPhases.size()) {
00120         myStep = 0;
00121     }
00122     //stores the time the phase started
00123     myPhases[myStep]->myLastSwitch = MSNet::getInstance()->getCurrentTimeStep();
00124     // set the next event
00125     return duration();
00126 }


Field Documentation

information whether the current phase should be lenghtend

Definition at line 125 of file MSActuatedTrafficLightLogic.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 134 of file MSActuatedTrafficLightLogic.h.

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 122 of file MSActuatedTrafficLightLogic.h.

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

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

The maximum gap to check.

Definition at line 128 of file MSActuatedTrafficLightLogic.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 131 of file MSActuatedTrafficLightLogic.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:46 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6