MSLink Class Reference

#include <MSLink.h>


Detailed Description

Definition at line 68 of file MSLink.h.


Public Types

enum  LinkDirection {
  LINKDIR_STRAIGHT = 0, LINKDIR_TURN, LINKDIR_LEFT, LINKDIR_RIGHT,
  LINKDIR_PARTLEFT, LINKDIR_PARTRIGHT, LINKDIR_NODIR
}
 The different directions a link may take. More...
enum  LinkState {
  LINKSTATE_TL_GREEN_MAJOR = 'G', LINKSTATE_TL_GREEN_MINOR = 'g', LINKSTATE_TL_RED = 'r', LINKSTATE_TL_YELLOW_MAJOR = 'Y',
  LINKSTATE_TL_YELLOW_MINOR = 'y', LINKSTATE_TL_OFF_BLINKING = 'b', LINKSTATE_TL_OFF_NOSIGNAL = 'O', LINKSTATE_MAJOR = 'M',
  LINKSTATE_MINOR = 'm', LINKSTATE_EQUAL = '=', LINKSTATE_DEADEND = '-'
}
 The right-of-way state of this link. More...

Public Member Functions

bool blockedAtTime (SUMOTime arrivalTime, SUMOTime leaveTime) const throw ()
void deleteRequest () throw ()
 Removes the incoming vehicle's request.
MSVehiclegetApproaching () const throw ()
 Returns the approaching vehicle.
LinkDirection getDirection () const throw ()
 Returns the direction the vehicle passing this link take.
MSLanegetLane () const throw ()
 Returns the connected lane.
SUMOReal getLength () const throw ()
 Returns the length of this link.
unsigned int getRespondIndex () const throw ()
 Returns the respond index (for visualization).
LinkState getState () const throw ()
 Returns the current state of the link.
bool hasApproachingFoe (SUMOTime arrivalTime, SUMOTime leaveTime) const throw ()
 Returns the information whether a vehicle is approaching on one of the link's foe streams.
bool havePriority () const throw ()
 Returns whether this link is a major lin.
bool isCrossing () const throw ()
 Returns whether this link belongs to a junction where more than one edge is incoming.
 MSLink (MSLane *succLane, bool yield, LinkDirection dir, LinkState state, SUMOReal length) throw ()
 Constructor for simulation not using internal lanes.
bool opened (SUMOTime arrivalTime, SUMOReal arrivalSpeed) const throw ()
 Returns the information whether the link may be passed.
void removeApproaching (MSVehicle *veh)
void setApproaching (MSVehicle *approaching, SUMOTime arrivalTime, SUMOReal speed) throw ()
 Sets the information about an approaching vehicle.
void setPriority (bool prio) throw ()
 Resets this link priority (information whether it is yield).
void setRequestInformation (MSLogicJunction::Request *request, unsigned int requestIdx, MSLogicJunction::Respond *respond, unsigned int respondIdx, const MSLogicJunction::LinkFoes &foes, bool isCrossing, bool isCont, const std::vector< MSLink * > &foeLinks, const std::vector< MSLane * > &foeLanes) throw ()
 Sets the request information.
void setTLState (LinkState state) throw ()
 Sets the current tl-state.
 ~MSLink () throw ()
 Destructor.

Private Member Functions

 MSLink (const MSLink &s)
 invalidated copy constructor
MSLinkoperator= (const MSLink &s)
 invalidated assignment operator

Private Attributes

bool myAmCont
MSVehiclemyApproaching
 The approaching vehicle.
MSJunction::LinkApproachingVehicles myApproachingVehicles
LinkDirection myDirection
 An abstract (hopefully human readable) definition of the link's direction.
std::vector< MSLane * > myFoeLanes
std::vector< MSLink * > myFoeLinks
MSLogicJunction::LinkFoes myFoes
 This links foes.
bool myIsCrossing
 Whether any foe links exist.
MSLanemyLane
 The lane approached by this link.
SUMOReal myLength
 The length of the link.
bool myPrio
 The right of way.
MSLogicJunction::RequestmyRequest
 The request to set incoming request into.
unsigned int myRequestIdx
 The position of the link within this request.
MSLogicJunction::RespondmyRespond
 The respond to read whether the car may drive from.
unsigned int myRespondIdx
 The position within this respond.
LinkState myState
 The state of the link.

Member Enumeration Documentation

The different directions a link may take.

Enumerator:
LINKDIR_STRAIGHT  The link is a straight direction.
LINKDIR_TURN  The link is a 180 degree turn.
LINKDIR_LEFT  The link is a (hard) left direction.
LINKDIR_RIGHT  The link is a (hard) right direction.
LINKDIR_PARTLEFT  The link is a partial left direction.
LINKDIR_PARTRIGHT  The link is a partial right direction.
LINKDIR_NODIR  The link has no direction (is a dead end link).

Definition at line 108 of file MSLink.h.

00108                        {
00110         LINKDIR_STRAIGHT = 0,
00112         LINKDIR_TURN,
00114         LINKDIR_LEFT,
00116         LINKDIR_RIGHT,
00118         LINKDIR_PARTLEFT,
00120         LINKDIR_PARTRIGHT,
00122         LINKDIR_NODIR
00123     };

The right-of-way state of this link.

This enumerations holds the possible right-of-way rules a link may have. Beyond the righ-of-way rules, this enumeration also holds the possible traffic light states.

Enumerator:
LINKSTATE_TL_GREEN_MAJOR  The link has green light, may pass.
LINKSTATE_TL_GREEN_MINOR  The link has green light, has to brake.
LINKSTATE_TL_RED  The link has red light (must brake).
LINKSTATE_TL_YELLOW_MAJOR  The link has yellow light, may pass.
LINKSTATE_TL_YELLOW_MINOR  The link has yellow light, has to brake anyway.
LINKSTATE_TL_OFF_BLINKING  The link is controlled by a tls which is off and blinks, has to brake.
LINKSTATE_TL_OFF_NOSIGNAL  The link is controlled by a tls which is off, not blinking, may pass.
LINKSTATE_MAJOR  This is an uncontrolled, major link, may pass.
LINKSTATE_MINOR  This is an uncontrolled, minor link, has to brake.
LINKSTATE_EQUAL  This is an uncontrolled, right-before-left link.
LINKSTATE_DEADEND  This is a dead end link.

Definition at line 78 of file MSLink.h.

00078                    {
00080         LINKSTATE_TL_GREEN_MAJOR = 'G',
00082         LINKSTATE_TL_GREEN_MINOR = 'g',
00084         LINKSTATE_TL_RED = 'r',
00086         LINKSTATE_TL_YELLOW_MAJOR = 'Y',
00088         LINKSTATE_TL_YELLOW_MINOR = 'y',
00090         LINKSTATE_TL_OFF_BLINKING = 'b',
00092         LINKSTATE_TL_OFF_NOSIGNAL = 'O',
00094         LINKSTATE_MAJOR = 'M',
00096         LINKSTATE_MINOR = 'm',
00098         LINKSTATE_EQUAL = '=',
00100         LINKSTATE_DEADEND = '-'
00101     };


Constructor & Destructor Documentation

MSLink::MSLink ( MSLane succLane,
bool  yield,
LinkDirection  dir,
LinkState  state,
SUMOReal  length 
) throw ()

Constructor for simulation not using internal lanes.

Parameters:
[in] succLane The lane approached by this link
[in] yield Information whether vehicles have to decelerate in front of this link
[in] dir The direction of this link
[in] state The state of this link

Definition at line 43 of file MSLink.cpp.

00046         :
00047         myLane(succLane),
00048         myPrio(!yield), myApproaching(0),
00049         myRequest(0), myRequestIdx(0), myRespond(0), myRespondIdx(0),
00050         myState(state), myDirection(dir),  myLength(length) {}
#else

MSLink::~MSLink (  )  throw ()

Destructor.

Definition at line 64 of file MSLink.cpp.

00064 {}

MSLink::MSLink ( const MSLink s  )  [private]

invalidated copy constructor


Member Function Documentation

bool MSLink::blockedAtTime ( SUMOTime  arrivalTime,
SUMOTime  leaveTime 
) const throw ()

Definition at line 156 of file MSLink.cpp.

References myApproachingVehicles, and VIEW.

00156                                                                             {
00157     for (std::vector<MSJunction::ApproachingVehicleInformation>::const_iterator i=myApproachingVehicles.begin(); i!=myApproachingVehicles.end(); ++i) {
00158         if ((*i).arrivalTime-VIEW<=arrivalTime&&(*i).leavingTime+VIEW>=arrivalTime) {
00159             return true;
00160         }
00161         if ((*i).arrivalTime-VIEW<=leaveTime&&(*i).leavingTime+VIEW>=leaveTime) {
00162             return true;
00163         }
00164     }
00165     return false;
00166 }

void MSLink::deleteRequest (  )  throw ()

Removes the incoming vehicle's request.

Necessary to mask out vehicles having yellow or red.

Definition at line 190 of file MSLink.cpp.

References myApproaching, myRequest, myRequestIdx, myRespond, and myRespondIdx.

00190                               {
00191     if (myRequest!=0) {
00192         myRequest->reset(myRequestIdx);
00193     }
00194     if (myRespond!=0) {
00195         myRespond->reset(myRespondIdx);
00196     }
00197     myApproaching = 0;
00198 }

MSVehicle* MSLink::getApproaching (  )  const throw () [inline]

Returns the approaching vehicle.

May be 0 if no vehicle is approaching.

Returns:
The approaching vehicle if any, 0 otherwise
Todo:
Unsecure!

Definition at line 192 of file MSLink.h.

References myApproaching.

00192                                               {
00193         return myApproaching;
00194     };

MSLink::LinkDirection MSLink::getDirection (  )  const throw ()

Returns the direction the vehicle passing this link take.

Returns:
The direction of this link

Definition at line 202 of file MSLink.cpp.

References myDirection.

00202                                    {
00203     return myDirection;
00204 }

MSLane * MSLink::getLane (  )  const throw ()

Returns the connected lane.

Returns:
The lane approached by this link

Definition at line 214 of file MSLink.cpp.

References myLane.

Referenced by MSVehicle::checkRewindLinkLanes(), Command_SaveTLSSwitches::execute(), MSLinkContHelper::getConnectingLink(), MSVehicle::moveFirstChecked(), TraCIServerAPI_TLS::processGet(), and TraCIServerAPI_Lane::processGet().

00214                               {
00215     return myLane;
00216 }

SUMOReal MSLink::getLength (  )  const throw () [inline]

Returns the length of this link.

Returns:
The length of this link

Definition at line 283 of file MSLink.h.

References myLength.

Referenced by opened(), TraCIServerAPI_Lane::processGet(), and setApproaching().

00283                                        {
00284         return myLength;
00285     }

unsigned int MSLink::getRespondIndex (  )  const throw ()

Returns the respond index (for visualization).

Returns:
The respond index for this link

Definition at line 245 of file MSLink.cpp.

References myRespondIdx.

00245                                       {
00246     return myRespondIdx;
00247 }

LinkState MSLink::getState (  )  const throw () [inline]

Returns the current state of the link.

Returns:
The current state of this link

Definition at line 237 of file MSLink.h.

References myState.

Referenced by Command_SaveTLCoupledLaneDet::execute(), and MSVehicle::moveFirstChecked().

00237                                        {
00238         return myState;
00239     }

bool MSLink::hasApproachingFoe ( SUMOTime  arrivalTime,
SUMOTime  leaveTime 
) const throw ()

Returns the information whether a vehicle is approaching on one of the link's foe streams.

Valid after the vehicles have set their requests

Returns:
Whether a foe of this link is approaching

Definition at line 170 of file MSLink.cpp.

References myFoeLanes, myFoeLinks, and myRequest.

Referenced by TraCIServerAPI_Lane::processGet().

00170                                                                                 {
00171     if (myRequest==0) {
00172         return false;
00173     }
00174     for (std::vector<MSLink*>::const_iterator i=myFoeLinks.begin(); i!=myFoeLinks.end(); ++i) {
00175         if ((*i)->blockedAtTime(arrivalTime, leaveTime)) {
00176             return true;
00177         }
00178     }
00179     for (std::vector<MSLane*>::const_iterator i=myFoeLanes.begin(); i!=myFoeLanes.end(); ++i) {
00180         if ((*i)->getVehicleNumber()>0||(*i)->getPartialOccupator()!=0) {
00181             return true;
00182         }
00183     }
00184     return false;
00185 //    return (*myRequest&myFoes).any();
00186 }

bool MSLink::havePriority (  )  const throw () [inline]

Returns whether this link is a major lin.

Returns:
Whether the link has a large priority

Definition at line 274 of file MSLink.h.

References myPrio.

Referenced by TraCIServerAPI_Lane::processGet().

00274                                       {
00275         return myPrio;
00276     }

bool MSLink::isCrossing (  )  const throw () [inline]

Returns whether this link belongs to a junction where more than one edge is incoming.

Returns:
Whether any foe links exist

Definition at line 291 of file MSLink.h.

References myIsCrossing.

Referenced by MSVehicle::checkRewindLinkLanes(), and setRequestInformation().

00291                                     {
00292         return myIsCrossing;
00293     }

bool MSLink::opened ( SUMOTime  arrivalTime,
SUMOReal  arrivalSpeed 
) const throw ()

Returns the information whether the link may be passed.

Valid after the junctions have set their reponds

Returns:
Whether this link may be passed.

Definition at line 123 of file MSLink.cpp.

References getLength(), LINKSTATE_TL_RED, myAmCont, myFoeLanes, myFoeLinks, myRespond, myState, and TIME2STEPS.

Referenced by MSVehicle::moveFirstChecked(), and TraCIServerAPI_Lane::processGet().

00123                                                                         {
00124     if (myRespond==0) {
00125         // this is the case for internal lanes ending at a junction's end
00126         // (let the vehicle always leave the junction)
00127         return true;
00128     }
00129     if (myAmCont) {
00130         return true;
00131     }
00132     if (myState==LINKSTATE_TL_RED) {
00133         return false;
00134     }
00135 #ifdef HAVE_INTERNAL_LANES
00136     SUMOTime leaveTime = myJunctionInlane==0 ? arrivalTime + TIME2STEPS(getLength() * arrivalSpeed) : arrivalTime + TIME2STEPS(this->myJunctionInlane->getLength() * arrivalSpeed);
00137 #else
00138     SUMOTime leaveTime = arrivalTime + TIME2STEPS(getLength() * arrivalSpeed);
00139 #endif
00140     for (std::vector<MSLink*>::const_iterator i=myFoeLinks.begin(); i!=myFoeLinks.end(); ++i) {
00141         if ((*i)->blockedAtTime(arrivalTime, leaveTime)) {
00142             return false;
00143         }
00144     }
00145     for (std::vector<MSLane*>::const_iterator i=myFoeLanes.begin(); i!=myFoeLanes.end(); ++i) {
00146         if ((*i)->getVehicleNumber()>0||(*i)->getPartialOccupator()!=0) {
00147             return false;
00148         }
00149     }
00150     return true;
00151 }

MSLink& MSLink::operator= ( const MSLink s  )  [private]

invalidated assignment operator

void MSLink::removeApproaching ( MSVehicle veh  ) 

Definition at line 105 of file MSLink.cpp.

References myApproachingVehicles, and myRequest.

00105                                         {
00106     if (myRequest==0) {
00107         return;
00108     }
00109     std::vector<MSJunction::ApproachingVehicleInformation>::iterator i = find_if(myApproachingVehicles.begin(), myApproachingVehicles.end(), MSJunction::vehicle_in_request_finder(veh));
00110     if (i!=myApproachingVehicles.end()) {
00111         myApproachingVehicles.erase(i);
00112     }
00113 }

void MSLink::setApproaching ( MSVehicle approaching,
SUMOTime  arrivalTime,
SUMOReal  speed 
) throw ()

Sets the information about an approaching vehicle.

Stores the approaching vehicle in myApproaching, sets the information that a vehicle is approaching in request.

Parameters:
[in] approaching The approaching vehicle

Definition at line 88 of file MSLink.cpp.

References getLength(), myApproaching, myApproachingVehicles, myRequest, myRequestIdx, and SUMOReal.

00088                                                                                            {
00089     if (myRequest==0) {
00090         return;
00091     }
00092     myApproaching = approaching;
00093     myRequest->set(myRequestIdx);
00094     std::vector<MSJunction::ApproachingVehicleInformation>::iterator i = find_if(myApproachingVehicles.begin(), myApproachingVehicles.end(), MSJunction::vehicle_in_request_finder(approaching));
00095     if (i!=myApproachingVehicles.end()) {
00096         myApproachingVehicles.erase(i);
00097     }
00098     SUMOReal leaveTime = arrivalTime + getLength() / speed * 1000.;
00099     MSJunction::ApproachingVehicleInformation approachInfo(arrivalTime, leaveTime, approaching);
00100     myApproachingVehicles.push_back(approachInfo);
00101 }

void MSLink::setPriority ( bool  prio  )  throw ()

Resets this link priority (information whether it is yield).

Some Junctions need to switch the priority.

Parameters:
[in] prio The current priority of the link

Definition at line 117 of file MSLink.cpp.

References myPrio.

00117                                      {
00118     myPrio = prio;
00119 }

void MSLink::setRequestInformation ( MSLogicJunction::Request request,
unsigned int  requestIdx,
MSLogicJunction::Respond respond,
unsigned int  respondIdx,
const MSLogicJunction::LinkFoes foes,
bool  isCrossing,
bool  isCont,
const std::vector< MSLink * > &  foeLinks,
const std::vector< MSLane * > &  foeLanes 
) throw ()

Sets the request information.

Because traffic lights and junction logics are loaded after links, we have to assign the information about the right-of-way requests and responses after the initialisation.

Parameters:
[in] request The request of this link
[in] requestIdx This link's index within this request
[in] respond The respond of this link
[in] respondIdx This link's index within this respond
[in] foes This link's foes
Todo:
Unsecure!

Definition at line 68 of file MSLink.cpp.

References isCrossing(), myAmCont, myFoeLanes, myFoeLinks, myFoes, myIsCrossing, myRequest, myRequestIdx, myRespond, and myRespondIdx.

00072                                                                           {
00073     assert(myRequest==0);
00074     assert(myRespond==0);
00075     myRequest = request;
00076     myRequestIdx = requestIdx;
00077     myRespond = respond;
00078     myRespondIdx = respondIdx;
00079     myFoes = foes;
00080     myIsCrossing = isCrossing;
00081     myAmCont = isCont;
00082     myFoeLinks = foeLinks;
00083     myFoeLanes = foeLanes;
00084 }

void MSLink::setTLState ( LinkState  state  )  throw ()

Sets the current tl-state.

Parameters:
[in] state The current state of the link

Definition at line 208 of file MSLink.cpp.

References myState.

00208                                           {
00209     myState = state;
00210 }


Field Documentation

Definition at line 352 of file MSLink.h.

Referenced by opened(), and setRequestInformation().

The approaching vehicle.

Definition at line 322 of file MSLink.h.

Referenced by deleteRequest(), getApproaching(), and setApproaching().

Definition at line 326 of file MSLink.h.

Referenced by blockedAtTime(), removeApproaching(), and setApproaching().

An abstract (hopefully human readable) definition of the link's direction.

Definition at line 341 of file MSLink.h.

Referenced by getDirection().

std::vector<MSLane*> MSLink::myFoeLanes [private]

Definition at line 363 of file MSLink.h.

Referenced by hasApproachingFoe(), opened(), and setRequestInformation().

std::vector<MSLink*> MSLink::myFoeLinks [private]

Definition at line 362 of file MSLink.h.

Referenced by hasApproachingFoe(), opened(), and setRequestInformation().

This links foes.

Definition at line 347 of file MSLink.h.

Referenced by setRequestInformation().

Whether any foe links exist.

Definition at line 350 of file MSLink.h.

Referenced by isCrossing(), and setRequestInformation().

MSLane* MSLink::myLane [private]

The lane approached by this link.

Definition at line 316 of file MSLink.h.

Referenced by getLane().

SUMOReal MSLink::myLength [private]

The length of the link.

Definition at line 344 of file MSLink.h.

Referenced by getLength().

bool MSLink::myPrio [private]

The right of way.

Definition at line 319 of file MSLink.h.

Referenced by havePriority(), and setPriority().

The request to set incoming request into.

Definition at line 325 of file MSLink.h.

Referenced by deleteRequest(), hasApproachingFoe(), removeApproaching(), setApproaching(), and setRequestInformation().

unsigned int MSLink::myRequestIdx [private]

The position of the link within this request.

Definition at line 329 of file MSLink.h.

Referenced by deleteRequest(), setApproaching(), and setRequestInformation().

The respond to read whether the car may drive from.

Definition at line 332 of file MSLink.h.

Referenced by deleteRequest(), opened(), and setRequestInformation().

unsigned int MSLink::myRespondIdx [private]

The position within this respond.

Definition at line 335 of file MSLink.h.

Referenced by deleteRequest(), getRespondIndex(), and setRequestInformation().

The state of the link.

Definition at line 338 of file MSLink.h.

Referenced by getState(), opened(), and setTLState().


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

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