NBOwnTLDef Class Reference

#include <NBOwnTLDef.h>

Inheritance diagram for NBOwnTLDef:

NBTrafficLightDefinition Named

Detailed Description

A traffic light logics which must be computed (only nodes/edges are given).

Definition at line 51 of file NBOwnTLDef.h.


Public Types

enum  TLColor {
  TLCOLOR_RED, TLCOLOR_YELLOW, TLCOLOR_REDYELLOW, TLCOLOR_GREEN,
  TLCOLOR_BLINK
}
 An enumeration of possible tl-signal states. More...

Public Member Functions

void addControlledInnerEdges (const std::vector< std::string > &edges) throw ()
 Adds the given ids into the list of edges not controlled by the tls.
NBTrafficLightLogiccompute (const NBEdgeCont &ec, OptionsCont &oc) throw ()
 Computes the traffic light logic.
bool foes (const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const throw ()
 Returns the information whether the given flows cross.
bool forbids (const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const throw ()
 Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
const std::string & getID () const throw ()
 Returns the id.
const EdgeVectorgetIncomingEdges () const throw ()
 Returns the list of incoming edges (must be build first).
bool isLeftMover (const NBEdge *const from, const NBEdge *const to) const throw ()
 returns the information whether the given link is a left-mover
bool mustBrake (const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, bool regardNonSignalisedLowerPriority) const throw ()
 Returns the information whether the described flow must let any other flow pass.
bool mustBrake (const NBConnection &possProhibited, const NBConnection &possProhibitor, bool regardNonSignalisedLowerPriority) const throw ()
 Returns the information whether the described flow must let the other flow pass.
bool mustBrake (const NBEdge *const from, const NBEdge *const to) const throw ()
 Returns the information whether the described flow must let any other flow pass.
 NBOwnTLDef (const std::string &id) throw ()
 Constructor.
 NBOwnTLDef (const std::string &id, NBNode *junction) throw ()
 Constructor.
 NBOwnTLDef (const std::string &id, const std::vector< NBNode * > &junctions) throw ()
 Constructor.
void setParticipantsInformation () throw ()
 Builds the list of participating nodes/edges/links.
 ~NBOwnTLDef () throw ()
 Destructor.
Access to controlled nodes
void addNode (NBNode *node) throw ()
 Adds a node to the traffic light logic.
const std::vector< NBNode * > & getNodes () const throw ()
 Returns the list of controlled nodes.
void removeNode (NBNode *node) throw ()
 Removes the given node from the list of controlled nodes.
Public methods from NBTrafficLightDefinition-interface
void remapRemoved (NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing) throw ()
 Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
void setTLControllingInformation (const NBEdgeCont &ec) const throw ()
 Informs edges about being controlled by a tls.

Protected Member Functions

void collectEdges () throw ()
 Build the list of participating edges.
unsigned int computeBrakingTime (SUMOReal minDecel) const throw ()
 Computes the time vehicles may need to brake.
SUMOReal computeUnblockedWeightedStreamNumber (const NBEdge *const e1, const NBEdge *const e2) throw ()
 Returns how many streams outgoing from the edges can pass the junction without being blocked.
std::pair< NBEdge *, NBEdge * > getBestCombination (const std::vector< NBEdge * > &edges) throw ()
 Returns the combination of two edges from the given which has most unblocked streams.
std::pair< NBEdge *, NBEdge * > getBestPair (std::vector< NBEdge * > &incoming) throw ()
 Returns the combination of two edges from the given which has most unblocked streams.
SUMOReal getDirectionalWeight (NBMMLDirection dir) throw ()
 Returns the weight of a stream given its direction.
std::pair< unsigned int,
unsigned int > 
getSizes () const throw ()
 Returns a pair of <number participating lanes, number participating links>.
int getToPrio (const NBEdge *const e) throw ()
 Returns this edge's priority at the node it ends at.
Protected methods from NBTrafficLightDefinition-interface
void collectLinks () throw (ProcessError)
 Collects the links participating in this traffic light
Exceptions:
ProcessError If a link could not be found.

void collectNodes () throw ()
 Collects the nodes participating in this traffic light.
NBTrafficLightLogicmyCompute (const NBEdgeCont &ec, unsigned int brakingTime) throw ()
 Computes the traffic light logic finally in dependence to the type.
void replaceRemoved (NBEdge *removed, int removedLane, NBEdge *by, int byLane) throw ()
 Replaces a removed edge/lane.

Protected Attributes

std::vector< std::string > myControlledInnerEdges
 List of inner edges that shall be controlled, though.
NBConnectionVector myControlledLinks
 The list of controlled links.
std::vector< NBNode * > myControlledNodes
 The container with participating nodes.
EdgeVector myEdgesWithin
 The list of edges within the area controlled by the tls.
std::string myID
 The name of the object.
EdgeVector myIncomingEdges
 The list of incoming edges.

Data Structures

class  edge_by_incoming_priority_sorter
 Sorts edges by their priority within the node they end at. More...

Member Enumeration Documentation

An enumeration of possible tl-signal states.

Enumerator:
TLCOLOR_RED  Signal shows red.
TLCOLOR_YELLOW  Signal shows yellow.
TLCOLOR_REDYELLOW  Signal shows red/yellow (unused).
TLCOLOR_GREEN  Signal shows green.
TLCOLOR_BLINK  Signal is blinking yellow.

Definition at line 76 of file NBTrafficLightDefinition.h.

00076                  {
00078         TLCOLOR_RED,
00080         TLCOLOR_YELLOW,
00082         TLCOLOR_REDYELLOW,
00084         TLCOLOR_GREEN,
00086         TLCOLOR_BLINK
00087     };


Constructor & Destructor Documentation

NBOwnTLDef::NBOwnTLDef ( const std::string &  id,
const std::vector< NBNode * > &  junctions 
) throw ()

Constructor.

Parameters:
[in] id The id of the tls
[in] junctions Junctions controlled by this tls

Definition at line 50 of file NBOwnTLDef.cpp.

00052         : NBTrafficLightDefinition(id, junctions) {}

NBOwnTLDef::NBOwnTLDef ( const std::string &  id,
NBNode junction 
) throw ()

Constructor.

Parameters:
[in] id The id of the tls
[in] junction The junction controlled by this tls

Definition at line 55 of file NBOwnTLDef.cpp.

00056         : NBTrafficLightDefinition(id, junction) {}

NBOwnTLDef::NBOwnTLDef ( const std::string &  id  )  throw ()

Constructor.

Parameters:
[in] id The id of the tls

Definition at line 59 of file NBOwnTLDef.cpp.

00060         : NBTrafficLightDefinition(id) {}

NBOwnTLDef::~NBOwnTLDef (  )  throw ()

Destructor.

Definition at line 63 of file NBOwnTLDef.cpp.

00063 {}


Member Function Documentation

void NBTrafficLightDefinition::addControlledInnerEdges ( const std::vector< std::string > &  edges  )  throw () [inherited]

Adds the given ids into the list of edges not controlled by the tls.

Parameters:
[in] edges The list of edge ids to add the inner edges to

Definition at line 368 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledInnerEdges.

Referenced by NIXMLNodesHandler::processTrafficLightDefinitions().

00368                                                                                            {
00369     copy(edges.begin(), edges.end(), back_inserter(myControlledInnerEdges));
00370 }

void NBTrafficLightDefinition::addNode ( NBNode node  )  throw () [inherited]

Adds a node to the traffic light logic.

Parameters:
[in] node A further node that shall be controlled by the tls

Definition at line 348 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledNodes.

Referenced by NBLoadedTLDef::addToSignalGroup(), and NIXMLNodesHandler::processTrafficLightDefinitions().

00348                                                       {
00349     if (std::find(myControlledNodes.begin(), myControlledNodes.end(), node)==myControlledNodes.end()) {
00350         myControlledNodes.push_back(node);
00351         std::sort(myControlledNodes.begin(), myControlledNodes.end(), NBNode::nodes_by_id_sorter());
00352         node->addTrafficLight(this);
00353     }
00354 }

void NBTrafficLightDefinition::collectEdges (  )  throw () [protected, inherited]

Build the list of participating edges.

Definition at line 121 of file NBTrafficLightDefinition.cpp.

References NBEdge::getID(), NBTrafficLightDefinition::myControlledInnerEdges, NBTrafficLightDefinition::myControlledNodes, NBTrafficLightDefinition::myEdgesWithin, and NBTrafficLightDefinition::myIncomingEdges.

Referenced by NBTrafficLightDefinition::setParticipantsInformation(), and setParticipantsInformation().

00121                                                {
00122     EdgeVector myOutgoing;
00123     // collect the edges from the participating nodes
00124     for (std::vector<NBNode*>::iterator i=myControlledNodes.begin(); i!=myControlledNodes.end(); i++) {
00125         const EdgeVector &incoming = (*i)->getIncomingEdges();
00126         copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
00127         const EdgeVector &outgoing = (*i)->getOutgoingEdges();
00128         copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
00129     }
00130     // check which of the edges are completely within the junction
00131     //  remove these edges from the list of incoming edges
00132     //  add them to the list of edges lying within the node
00133     for (EdgeVector::iterator j=myIncomingEdges.begin(); j!=myIncomingEdges.end();) {
00134         NBEdge *edge = *j;
00135         // an edge lies within the logic if it is outgoing as well as incoming
00136         EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
00137         if (k!=myOutgoing.end()) {
00138             if (find(myControlledInnerEdges.begin(), myControlledInnerEdges.end(), edge->getID())==myControlledInnerEdges.end()) {
00139                 myEdgesWithin.push_back(edge);
00140                 (*j)->setIsInnerEdge();
00141                 j = myIncomingEdges.erase(j);
00142                 continue;
00143             }
00144         }
00145         ++j;
00146     }
00147 }

void NBOwnTLDef::collectLinks (  )  throw (ProcessError) [protected, virtual]

Collects the links participating in this traffic light

Exceptions:
ProcessError If a link could not be found.

See also:
NBTrafficLightDefinition::collectLinks

Reimplemented from NBTrafficLightDefinition.

Definition at line 343 of file NBOwnTLDef.cpp.

References NBEdge::Connection::fromLane, NBEdge::getConnectionsFromLane(), NBEdge::getID(), NBEdge::getNoLanes(), NBEdge::mayBeTLSControlled(), NBTrafficLightDefinition::myControlledLinks, NBTrafficLightDefinition::myIncomingEdges, NBEdge::Connection::toEdge, NBEdge::Connection::toLane, and toString().

Referenced by setParticipantsInformation().

00343                                              {
00344     // build the list of links which are controled by the traffic light
00345     for (EdgeVector::iterator i=myIncomingEdges.begin(); i!=myIncomingEdges.end(); i++) {
00346         NBEdge *incoming = *i;
00347         unsigned int noLanes = incoming->getNoLanes();
00348         for (unsigned int j=0; j<noLanes; j++) {
00349             std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
00350             for (std::vector<NBEdge::Connection>::iterator k=connected.begin(); k!=connected.end(); k++) {
00351                 const NBEdge::Connection &el = *k;
00352                 if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
00353                     if (el.toEdge!=0&&el.toLane>=(int) el.toEdge->getNoLanes()) {
00354                         throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
00355                     }
00356                     myControlledLinks.push_back(NBConnection(incoming, j, el.toEdge, el.toLane));
00357                 }
00358             }
00359         }
00360     }
00361 }

void NBOwnTLDef::collectNodes (  )  throw () [protected]

Collects the nodes participating in this traffic light.

See also:
NBTrafficLightDefinition::collectNodes

Definition at line 339 of file NBOwnTLDef.cpp.

Referenced by setParticipantsInformation().

00339 {}

NBTrafficLightLogic * NBTrafficLightDefinition::compute ( const NBEdgeCont ec,
OptionsCont oc 
) throw () [inherited]

Computes the traffic light logic.

Does some initialisation at first, then calls myCompute to finally build the tl-logic

Parameters:
[in] ec The edge container in order to retrieve edge information
[in] oc The options container holding options needed during the building
Returns:
The built logic (may be 0)

Definition at line 88 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::computeBrakingTime(), Named::getID(), NBTrafficLightDefinition::myCompute(), NBTrafficLightDefinition::myIncomingEdges, and WRITE_WARNING.

Referenced by NBTrafficLightLogicCont::computeLogics().

00088                                                                                {
00089     // it is not really a traffic light if no incoming edge exists
00090     if (myIncomingEdges.size()==0) {
00091         WRITE_WARNING("The traffic light '" + getID() + "' has no incoming edges; it will not be build.");
00092         return 0;
00093     }
00094     // compute the time needed to brake
00095     unsigned int brakingTime = computeBrakingTime(oc.getFloat("min-decel"));
00096     // perform the computation depending on whether the traffic light
00097     //  definition was loaded or shall be computed new completely
00098     if (oc.isSet("traffic-light-yellow")) {
00099         brakingTime = oc.getInt("traffic-light-yellow");
00100     }
00101     return myCompute(ec, brakingTime);
00102 }

unsigned int NBTrafficLightDefinition::computeBrakingTime ( SUMOReal  minDecel  )  const throw () [protected, inherited]

Computes the time vehicles may need to brake.

This time depends on the maximum speed allowed on incoming junctions. It is computed as max_speed_allowed / minimum_vehicle_decleration

Definition at line 106 of file NBTrafficLightDefinition.cpp.

References NBContHelper::maxSpeed(), NBTrafficLightDefinition::myIncomingEdges, and SUMOReal.

Referenced by NBTrafficLightDefinition::compute().

00106                                                                             {
00107     SUMOReal vmax = NBContHelper::maxSpeed(myIncomingEdges);
00108     return (unsigned int)(vmax / minDecel);
00109 }

SUMOReal NBOwnTLDef::computeUnblockedWeightedStreamNumber ( const NBEdge *const   e1,
const NBEdge *const   e2 
) throw () [protected]

Returns how many streams outgoing from the edges can pass the junction without being blocked.

Parameters:
[in] e1 The first edge
[in] e2 The second edge
Todo:
There are several magic numbers; describe

Definition at line 90 of file NBOwnTLDef.cpp.

References NBTrafficLightDefinition::foes(), getDirectionalWeight(), and SUMOReal.

Referenced by getBestCombination().

00090                                                                                                          {
00091     SUMOReal val = 0;
00092     for (unsigned int e1l=0; e1l<e1->getNoLanes(); e1l++) {
00093         std::vector<NBEdge::Connection> approached1 = e1->getConnectionsFromLane(e1l);
00094         for (unsigned int e2l=0; e2l<e2->getNoLanes(); e2l++) {
00095             std::vector<NBEdge::Connection> approached2 = e2->getConnectionsFromLane(e2l);
00096             for (std::vector<NBEdge::Connection>::iterator e1c=approached1.begin(); e1c!=approached1.end(); ++e1c) {
00097                 if (e1->getTurnDestination()==(*e1c).toEdge) {
00098                     continue;
00099                 }
00100                 for (std::vector<NBEdge::Connection>::iterator e2c=approached2.begin(); e2c!=approached2.end(); ++e2c) {
00101                     if (e2->getTurnDestination()==(*e2c).toEdge) {
00102                         continue;
00103                     }
00104                     if (!foes(e1, (*e1c).toEdge, e2, (*e2c).toEdge)) {
00105                         val += getDirectionalWeight(e1->getToNode()->getMMLDirection(e1, (*e1c).toEdge));
00106                         val += getDirectionalWeight(e2->getToNode()->getMMLDirection(e2, (*e2c).toEdge));
00107                     }
00108                 }
00109             }
00110         }
00111     }
00112     return val;
00113 }

bool NBTrafficLightDefinition::foes ( const NBEdge *const   from1,
const NBEdge *const   to1,
const NBEdge *const   from2,
const NBEdge *const   to2 
) const throw () [inherited]

Returns the information whether the given flows cross.

Parameters:
[in] from1 The starting edge of the first stream
[in] to1 The ending edge of the first stream
[in] from2 The starting edge of the second stream
[in] to2 The ending edge of the second stream
Returns:
Whether both stream are foes (cross)

Definition at line 325 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledNodes.

Referenced by computeUnblockedWeightedStreamNumber().

00326                                                                                                    {
00327     if (to1==0||to2==0) {
00328         return false;
00329     }
00330     // retrieve both nodes (it is possible that a connection
00331     std::vector<NBNode*>::const_iterator incoming =
00332         find_if(myControlledNodes.begin(), myControlledNodes.end(),
00333                 NBContHelper::node_with_incoming_finder(from1));
00334     std::vector<NBNode*>::const_iterator outgoing =
00335         find_if(myControlledNodes.begin(), myControlledNodes.end(),
00336                 NBContHelper::node_with_outgoing_finder(to1));
00337     assert(incoming!=myControlledNodes.end());
00338     NBNode *incnode = *incoming;
00339     NBNode *outnode = *outgoing;
00340     if (incnode!=outnode) {
00341         return false;
00342     }
00343     return incnode->foes(from1, to1, from2, to2);
00344 }

bool NBTrafficLightDefinition::forbids ( const NBEdge *const   possProhibitorFrom,
const NBEdge *const   possProhibitorTo,
const NBEdge *const   possProhibitedFrom,
const NBEdge *const   possProhibitedTo,
bool  regardNonSignalisedLowerPriority 
) const throw () [inherited]

Returns the information whether "prohibited" flow must let "prohibitor" flow pass.

Parameters:
[in] possProhibitedFrom The maybe prohibited connection's begin
[in] possProhibitedTo The maybe prohibited connection's end
[in] possProhibitorFrom The maybe prohibiting connection's begin
[in] possProhibitorTo The maybe prohibiting connection's end
[in] regardNonSignalisedLowerPriority Whether the right of way rules without traffic lights shall be regarded
Returns:
Whether the second flow prohibits the first one
See also:
forbids

Definition at line 248 of file NBTrafficLightDefinition.cpp.

References NBNode::foes(), NBNode::forbids(), and NBTrafficLightDefinition::myControlledNodes.

Referenced by NBTrafficLightDefinition::mustBrake(), and myCompute().

00252                                                                                        {
00253     if (possProhibitorFrom==0||possProhibitorTo==0||possProhibitedFrom==0||possProhibitedTo==0) {
00254         return false;
00255     }
00256     // retrieve both nodes
00257     std::vector<NBNode*>::const_iterator incoming =
00258         find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom));
00259     std::vector<NBNode*>::const_iterator outgoing =
00260         find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo));
00261     assert(incoming!=myControlledNodes.end());
00262     NBNode *incnode = *incoming;
00263     NBNode *outnode = *outgoing;
00264     EdgeVector::const_iterator i;
00265     if (incnode!=outnode) {
00266         // the links are located at different nodes
00267         const EdgeVector &ev1 = possProhibitedTo->getConnectedEdges();
00268         // go through the following edge,
00269         //  check whether one of these connections is prohibited
00270         for (i=ev1.begin(); i!=ev1.end(); ++i) {
00271             std::vector<NBNode*>::const_iterator outgoing2 =
00272                 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(*i));
00273             if (outgoing2==myControlledNodes.end()) {
00274                 continue;
00275             }
00276             NBNode *outnode2 = *outgoing2;
00277             if (incnode!=outnode2) {
00278                 continue;
00279             }
00280             bool ret1 = incnode->foes(possProhibitorTo, *i,
00281                                       possProhibitedFrom, possProhibitedTo);
00282             bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
00283                                          possProhibitedTo, *i,
00284                                          regardNonSignalisedLowerPriority);
00285             bool ret = ret1||ret2;
00286             if (ret) {
00287                 return true;
00288             }
00289         }
00290 
00291         const EdgeVector &ev2 = possProhibitorTo->getConnectedEdges();
00292         // go through the following edge,
00293         //  check whether one of these connections is prohibited
00294         for (i=ev2.begin(); i!=ev2.end(); ++i) {
00295             std::vector<NBNode*>::const_iterator incoming2 =
00296                 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo));
00297             if (incoming2==myControlledNodes.end()) {
00298                 continue;
00299             }
00300             NBNode *incnode2 = *incoming2;
00301             if (incnode2!=outnode) {
00302                 continue;
00303             }
00304             bool ret1 = incnode2->foes(possProhibitorTo, *i,
00305                                        possProhibitedFrom, possProhibitedTo);
00306             bool ret2 = incnode2->forbids(possProhibitorTo, *i,
00307                                           possProhibitedFrom, possProhibitedTo,
00308                                           regardNonSignalisedLowerPriority);
00309             bool ret = ret1||ret2;
00310             if (ret) {
00311                 return true;
00312             }
00313         }
00314         return false;
00315     }
00316     // both links are located at the same node
00317     //  check using this node's information
00318     return incnode->forbids(possProhibitorFrom, possProhibitorTo,
00319                             possProhibitedFrom, possProhibitedTo,
00320                             regardNonSignalisedLowerPriority);
00321 }

std::pair< NBEdge *, NBEdge * > NBOwnTLDef::getBestCombination ( const std::vector< NBEdge * > &  edges  )  throw () [protected]

Returns the combination of two edges from the given which has most unblocked streams.

Parameters:
[in] edges The list of edges to include in the computation
Returns:
The two edges for which the weighted number of unblocked streams is the highest

Definition at line 117 of file NBOwnTLDef.cpp.

References computeUnblockedWeightedStreamNumber(), GeomHelper::getMinAngleDiff(), and SUMOReal.

Referenced by getBestPair().

00117                                                                       {
00118     std::pair<NBEdge*, NBEdge*> bestPair(0,0);
00119     SUMOReal bestValue = -1;
00120     for (std::vector<NBEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) {
00121         for (std::vector<NBEdge*>::const_iterator j=i+1; j!=edges.end(); ++j) {
00122             SUMOReal value = computeUnblockedWeightedStreamNumber(*i, *j);
00123             if (value>bestValue) {
00124                 bestValue = value;
00125                 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
00126             } else if (value==bestValue) {
00127                 SUMOReal ca = GeomHelper::getMinAngleDiff((*i)->getAngle(*(*i)->getToNode()), (*j)->getAngle(*(*j)->getToNode()));
00128                 SUMOReal oa = GeomHelper::getMinAngleDiff(bestPair.first->getAngle(*bestPair.first->getToNode()), bestPair.second->getAngle(*bestPair.second->getToNode()));
00129                 if (oa<ca) {
00130                     bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
00131                 }
00132             }
00133         }
00134     }
00135     return bestPair;
00136 }

std::pair< NBEdge *, NBEdge * > NBOwnTLDef::getBestPair ( std::vector< NBEdge * > &  incoming  )  throw () [protected]

Returns the combination of two edges from the given which has most unblocked streams.

The chosen edges are removed from the given vector

Parameters:
in,changed] incoming The list of edges which are participating in the logic
Returns:
The two edges for which the weighted number of unblocked streams is the highest

Definition at line 140 of file NBOwnTLDef.cpp.

References getBestCombination(), and getToPrio().

Referenced by myCompute().

00140                                                             {
00141     if (incoming.size()==1) {
00142         // only one there - return the one
00143         std::pair<NBEdge*, NBEdge*> ret(*incoming.begin(), 0);
00144         incoming.clear();
00145         return ret;
00146     }
00147     // determine the best combination
00148     //  by priority, first
00149     std::vector<NBEdge*> used;
00150     std::sort(incoming.begin(), incoming.end(), edge_by_incoming_priority_sorter());
00151     used.push_back(*incoming.begin()); // the first will definitely be used
00152     // get the ones with the same priority
00153     int prio = getToPrio(*used.begin());
00154     for (std::vector<NBEdge*>::iterator i=incoming.begin()+1; i!=incoming.end()&&prio!=getToPrio(*i); ++i) {
00155         used.push_back(*i);
00156     }
00157     //  if there only lower priorised, use these, too
00158     if (used.size()<2) {
00159         used = incoming;
00160     }
00161     std::pair<NBEdge*, NBEdge*> ret = getBestCombination(used);
00162     incoming.erase(find(incoming.begin(), incoming.end(), ret.first));
00163     incoming.erase(find(incoming.begin(), incoming.end(), ret.second));
00164     return ret;
00165 }

SUMOReal NBOwnTLDef::getDirectionalWeight ( NBMMLDirection  dir  )  throw () [protected]

Returns the weight of a stream given its direction.

Parameters:
[in] dir The direction of the stream
Returns:
This stream's weight
Todo:
There are several magic numbers; describe

Definition at line 73 of file NBOwnTLDef.cpp.

References MMLDIR_LEFT, MMLDIR_NODIR, MMLDIR_PARTLEFT, MMLDIR_PARTRIGHT, MMLDIR_RIGHT, MMLDIR_STRAIGHT, and MMLDIR_TURN.

Referenced by computeUnblockedWeightedStreamNumber().

00073                                                            {
00074     switch (dir) {
00075     case MMLDIR_STRAIGHT:
00076     case MMLDIR_PARTLEFT:
00077     case MMLDIR_PARTRIGHT:
00078         return 2.;
00079     case MMLDIR_LEFT:
00080     case MMLDIR_RIGHT:
00081         return .5;
00082     case MMLDIR_NODIR:
00083     case MMLDIR_TURN:
00084         return 0;
00085     }
00086     return 0;
00087 }

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

Returns the id.

Returns:
The stored id

Definition at line 59 of file Named.h.

References Named::myID.

Referenced by RORouteDef_Alternatives::addAlternative(), MSRouteProbe::addRoute(), MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), RORouteDef_Complete::buildCurrentRoute(), ODDistrictHandler::closeDistrict(), NBTrafficLightDefinition::collectLinks(), NBTrafficLightDefinition::compute(), GUIPointOfInterest::drawGL(), MSInductLoop::enterDetectorByMove(), MSVTypeProbe::execute(), MSNet::getBusStopID(), GUITriggeredRerouter::getMicrosimID(), GUIPointOfInterest::getMicrosimID(), GUILaneSpeedTrigger::getMicrosimID(), GUIInductLoop::MyWrapper::getMicrosimID(), GUIEmitter::getMicrosimID(), GUIBusStop::getMicrosimID(), GUI_E2_ZS_Collector::MyWrapper::getMicrosimID(), traci::TraCIServer::handlePoiDomain(), RORDLoader_SUMOBase::myCharacters(), myCompute(), NBLoadedTLDef::myCompute(), MSTriggeredRerouter::myStartElement(), MSLaneSpeedTrigger::myStartElement(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), NBLoadedTLDef::SignalGroup::patchTYellow(), TraCIServerAPI_Vehicle::processGet(), MSVehicle::replaceRoute(), MSVehicle::saveState(), setTLControllingInformation(), NBLoadedTLDef::setTLControllingInformation(), RORDLoader_SUMOBase::startRoute(), GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute(), NBTrafficLightLogic::writeXML(), MSRouteProbe::writeXMLOutput(), MSInductLoop::writeXMLOutput(), MSE2Collector::writeXMLOutput(), and MSVehicle::~MSVehicle().

00059                                            {
00060         return myID;
00061     }

const EdgeVector & NBTrafficLightDefinition::getIncomingEdges (  )  const throw () [inherited]

Returns the list of incoming edges (must be build first).

Returns:
The edges which are incoming into the tls

Definition at line 374 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myIncomingEdges.

Referenced by myCompute().

00374                                                          {
00375     return myIncomingEdges;
00376 }

const std::vector<NBNode*>& NBTrafficLightDefinition::getNodes (  )  const throw () [inline, inherited]

Returns the list of controlled nodes.

Returns:
Controlled nodes

Definition at line 147 of file NBTrafficLightDefinition.h.

References NBTrafficLightDefinition::myControlledNodes.

00147                                                        {
00148         return myControlledNodes;
00149     }

std::pair< unsigned int, unsigned int > NBTrafficLightDefinition::getSizes (  )  const throw () [protected, inherited]

Returns a pair of <number participating lanes, number participating links>.

Returns:
The numbers of lanes and links controlled by this tls

Definition at line 180 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myIncomingEdges.

00180                                                  {
00181     unsigned int noLanes = 0;
00182     unsigned int noLinks = 0;
00183     for (EdgeVector::const_iterator i=myIncomingEdges.begin(); i!=myIncomingEdges.end(); i++) {
00184         unsigned int noLanesEdge = (*i)->getNoLanes();
00185         for (unsigned int j=0; j<noLanesEdge; j++) {
00186             assert((*i)->getConnectionsFromLane(j).size()!=0);
00187             noLinks += (unsigned int)(*i)->getConnectionsFromLane(j).size();
00188         }
00189         noLanes += noLanesEdge;
00190     }
00191     return std::pair<unsigned int, unsigned int>(noLanes, noLinks);
00192 }

int NBOwnTLDef::getToPrio ( const NBEdge *const   e  )  throw () [protected]

Returns this edge's priority at the node it ends at.

Parameters:
[in] e The edge to ask for his priority
Returns:
The edge's priority at his destination node

Definition at line 67 of file NBOwnTLDef.cpp.

Referenced by getBestPair().

00067                                                     {
00068     return e->getJunctionPriority(e->getToNode());
00069 }

bool NBTrafficLightDefinition::isLeftMover ( const NBEdge *const   from,
const NBEdge *const   to 
) const throw () [inherited]

returns the information whether the given link is a left-mover

Parameters:
[in] from The connection's start edge
[in] to The connection's end edge
Returns:
Whether the connection is a left-mover

Definition at line 196 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledNodes.

Referenced by myCompute().

00196                                                                                                      {
00197     // the destination edge may be unused
00198     if (to==0) {
00199         return false;
00200     }
00201     // get the node which is holding this connection
00202     std::vector<NBNode*>::const_iterator i =
00203         find_if(myControlledNodes.begin(), myControlledNodes.end(),
00204                 NBContHelper::node_with_incoming_finder(from));
00205     assert(i!=myControlledNodes.end());
00206     NBNode *node = *i;
00207     return node->isLeftMover(from, to);
00208 }

bool NBTrafficLightDefinition::mustBrake ( const NBEdge *const   possProhibitedFrom,
const NBEdge *const   possProhibitedTo,
const NBEdge *const   possProhibitorFrom,
const NBEdge *const   possProhibitorTo,
bool  regardNonSignalisedLowerPriority 
) const throw () [inherited]

Returns the information whether the described flow must let any other flow pass.

Parameters:
[in] possProhibitedFrom The maybe prohibited connection's begin
[in] possProhibitedTo The maybe prohibited connection's end
[in] possProhibitorFrom The maybe prohibiting connection's begin
[in] possProhibitorTo The maybe prohibiting connection's end
[in] regardNonSignalisedLowerPriority Whether the right of way rules without traffic lights shall be regarded
Returns:
Whether the second flow prohibits the first one
See also:
forbids

Definition at line 226 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::forbids().

00230                                                                                          {
00231     return forbids(possProhibitorFrom, possProhibitorTo,
00232                    possProhibitedFrom, possProhibitedTo,
00233                    regardNonSignalisedLowerPriority);
00234 }

bool NBTrafficLightDefinition::mustBrake ( const NBConnection possProhibited,
const NBConnection possProhibitor,
bool  regardNonSignalisedLowerPriority 
) const throw () [inherited]

Returns the information whether the described flow must let the other flow pass.

Parameters:
[in] possProhibited The maybe prohibited connection
[in] possProhibitor The maybe prohibiting connection
[in] regardNonSignalisedLowerPriority Whether the right of way rules without traffic lights shall be regarded
Returns:
Whether the second flow prohibits the first one
See also:
forbids

Definition at line 238 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::forbids().

00240                                                                                          {
00241     return forbids(possProhibitor.getFrom(), possProhibitor.getTo(),
00242                    possProhibited.getFrom(), possProhibited.getTo(),
00243                    regardNonSignalisedLowerPriority);
00244 }

bool NBTrafficLightDefinition::mustBrake ( const NBEdge *const   from,
const NBEdge *const   to 
) const throw () [inherited]

Returns the information whether the described flow must let any other flow pass.

If the from/to connection passes only one junction (from is incoming into same node as to outgoes from) the node is asked whether the flow must brake- Otherwise true is returned (recheck!) "from" must be an incoming edge into one of the participating nodes!

Parameters:
[in] from The connection's start edge
[in] to The connection's end edge
Returns:
Whether the described connection must brake (has higher priorised foes)

Definition at line 212 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledNodes.

Referenced by NBLoadedTLDef::mustBrake().

00212                                                                                                     {
00213     std::vector<NBNode*>::const_iterator i =
00214         find_if(myControlledNodes.begin(), myControlledNodes.end(),
00215                 NBContHelper::node_with_incoming_finder(from));
00216     assert(i!=myControlledNodes.end());
00217     NBNode *node = *i;
00218     if (!node->hasOutgoing(to)) {
00219         return true; // !!!
00220     }
00221     return node->mustBrake(from, to, -1);
00222 }

NBTrafficLightLogic * NBOwnTLDef::myCompute ( const NBEdgeCont ec,
unsigned int  brakingTime 
) throw () [protected, virtual]

Computes the traffic light logic finally in dependence to the type.

Parameters:
[in] ec The edge container
[in] brakingTime Duration a vehicle needs for braking in front of the tls
Returns:
The computed logic
See also:
NBTrafficLightDefinition::myCompute

Implements NBTrafficLightDefinition.

Definition at line 169 of file NBOwnTLDef.cpp.

References NBTrafficLightLogic::addStep(), NBTrafficLightDefinition::forbids(), getBestPair(), NBEdge::getConnectionsFromLane(), NBTrafficLightLogic::getDuration(), Named::getID(), NBTrafficLightDefinition::getIncomingEdges(), OptionsCont::getInt(), NBEdge::getNoLanes(), OptionsCont::getOptions(), NBEdge::getToNode(), NBTrafficLightDefinition::isLeftMover(), NBEdge::isTurningDirectionAt(), and NBEdge::mayBeTLSControlled().

00170                                                         {
00171     // build complete lists first
00172     const EdgeVector &incoming = getIncomingEdges();
00173     std::vector<NBEdge*> fromEdges, toEdges;
00174     std::vector<bool> isLeftMoverV, isTurnaround;
00175     unsigned int noLanesAll = 0;
00176     unsigned int noLinksAll = 0;
00177     for (unsigned int i1=0; i1<incoming.size(); i1++) {
00178         unsigned int noLanes = incoming[i1]->getNoLanes();
00179         noLanesAll += noLanes;
00180         for (unsigned int i2=0; i2<noLanes; i2++) {
00181             NBEdge *fromEdge = incoming[i1];
00182             std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
00183             noLinksAll += (unsigned int) approached.size();
00184             for (unsigned int i3=0; i3<approached.size(); i3++) {
00185                 if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
00186                     --noLinksAll;
00187                     continue;
00188                 }
00189                 assert(i3<approached.size());
00190                 NBEdge *toEdge = approached[i3].toEdge;
00191                 fromEdges.push_back(fromEdge);
00192                 //myFromLanes.push_back(i2);
00193                 toEdges.push_back(toEdge);
00194                 if (toEdge!=0) {
00195                     isLeftMoverV.push_back(
00196                         isLeftMover(fromEdge, toEdge)
00197                         ||
00198                         fromEdge->isTurningDirectionAt(fromEdge->getToNode(), toEdge));
00199 
00200                     isTurnaround.push_back(
00201                         fromEdge->isTurningDirectionAt(
00202                             fromEdge->getToNode(), toEdge));
00203                 } else {
00204                     isLeftMoverV.push_back(true);
00205                     isTurnaround.push_back(true);
00206                 }
00207             }
00208         }
00209     }
00210 
00211     NBTrafficLightLogic *logic = new NBTrafficLightLogic(getID(), "0", noLinksAll);
00212     std::vector<NBEdge*> toProc = incoming;
00213     // build all phases
00214     while (toProc.size()>0) {
00215         std::pair<NBEdge*, NBEdge*> chosen;
00216         if (incoming.size()==2) {
00217             chosen = std::pair<NBEdge*, NBEdge*>(toProc[0], 0);
00218             toProc.erase(toProc.begin());
00219         } else {
00220             chosen = getBestPair(toProc);
00221         }
00222         unsigned int pos = 0;
00223         unsigned int duration = 31;
00224         if (OptionsCont::getOptions().isSet("traffic-light-green")) {
00225             duration = OptionsCont::getOptions().getInt("traffic-light-green");
00226         }
00227         std::string state((size_t) noLinksAll, 'o');
00228         // plain straight movers
00229         for (unsigned int i1=0; i1<(unsigned int) incoming.size(); ++i1) {
00230             NBEdge *fromEdge = incoming[i1];
00231             bool inChosen = fromEdge==chosen.first||fromEdge==chosen.second;//chosen.find(fromEdge)!=chosen.end();
00232             unsigned int noLanes = fromEdge->getNoLanes();
00233             for (unsigned int i2=0; i2<noLanes; i2++) {
00234                 std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
00235                 for (unsigned int i3=0; i3<approached.size(); ++i3) {
00236                     if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
00237                         continue;
00238                     }
00239                     if (inChosen) {
00240                         state[pos] = 'G';
00241                     } else {
00242                         state[pos] = 'r';
00243                     }
00244                     ++pos;
00245                 }
00246             }
00247         }
00248         // correct behaviour for those that are not in chosen, but may drive, though
00249         for (unsigned int i1=0; i1<pos; ++i1) {
00250             if (state[i1]=='G') {
00251                 continue;
00252             }
00253             bool isForbidden = false;
00254             for (unsigned int i2=0; i2<pos&&!isForbidden; ++i2) {
00255                 if (state[i2]=='G'&&!isTurnaround[i2]&&
00256                         (forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true)||forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2], true))) {
00257                     isForbidden = true;
00258                 }
00259             }
00260             if (!isForbidden) {
00261                 state[i1] = 'G';
00262             }
00263         }
00264         // correct behaviour for those that have to wait (mainly left-mover)
00265         bool haveForbiddenLeftMover = false;
00266         for (unsigned int i1=0; i1<pos; ++i1) {
00267             if (state[i1]!='G') {
00268                 continue;
00269             }
00270             for (unsigned int i2=0; i2<pos; ++i2) {
00271                 if ((state[i2]=='G'||state[i2]=='g')&&forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true)) {
00272                     state[i1] = 'g';
00273                     if (!isTurnaround[i1]) {
00274                         haveForbiddenLeftMover = true;
00275                     }
00276                 }
00277             }
00278         }
00279 
00280         // add step
00281         logic->addStep(duration, state);
00282 
00283         if (brakingTime>0) {
00284             // build yellow (straight)
00285             duration = brakingTime;
00286             for (unsigned int i1=0; i1<pos; ++i1) {
00287                 if (state[i1]!='G'&&state[i1]!='g') {
00288                     continue;
00289                 }
00290                 if ((state[i1]>='a'&&state[i1]<='z')&&haveForbiddenLeftMover) {
00291                     continue;
00292                 }
00293                 state[i1] = 'y';
00294             }
00295             // add step
00296             logic->addStep(duration, state);
00297         }
00298 
00299         if (haveForbiddenLeftMover) {
00300             // build left green
00301             duration = 6;
00302             for (unsigned int i1=0; i1<pos; ++i1) {
00303                 if (state[i1]=='Y'||state[i1]=='y') {
00304                     state[i1] = 'r';
00305                     continue;
00306                 }
00307                 if (state[i1]=='g') {
00308                     state[i1] = 'G';
00309                 }
00310             }
00311             // add step
00312             logic->addStep(duration, state);
00313 
00314             // build left yellow
00315             if (brakingTime>0) {
00316                 duration = brakingTime;
00317                 for (unsigned int i1=0; i1<pos; ++i1) {
00318                     if (state[i1]!='G'&&state[i1]!='g') {
00319                         continue;
00320                     }
00321                     state[i1] = 'y';
00322                 }
00323                 // add step
00324                 logic->addStep(duration, state);
00325             }
00326         }
00327     }
00328     if (logic->getDuration()>0) {
00329         return logic;
00330     } else {
00331         delete logic;
00332         return 0;
00333     }
00334 
00335 }

void NBOwnTLDef::remapRemoved ( NBEdge removed,
const EdgeVector incoming,
const EdgeVector outgoing 
) throw () [virtual]

Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.

Parameters:
[in] removed The removed edge
[in] incoming The edges to use instead if an incoming edge was removed
[in] outgoing The edges to use instead if an outgoing edge was removed
See also:
NBTrafficLightDefinition::remapRemoved

Implements NBTrafficLightDefinition.

Definition at line 390 of file NBOwnTLDef.cpp.

00391                                                                  {}

void NBTrafficLightDefinition::removeNode ( NBNode node  )  throw () [inherited]

Removes the given node from the list of controlled nodes.

Parameters:
[in] node The node that shall not be controlled by the tls any more

Definition at line 358 of file NBTrafficLightDefinition.cpp.

References NBTrafficLightDefinition::myControlledNodes.

00358                                                          {
00359     std::vector<NBNode*>::iterator i = std::find(myControlledNodes.begin(), myControlledNodes.end(), node);
00360     if (i!=myControlledNodes.end()) {
00361         myControlledNodes.erase(i);
00362     }
00363     // !!! remove in node?
00364 }

void NBOwnTLDef::replaceRemoved ( NBEdge removed,
int  removedLane,
NBEdge by,
int  byLane 
) throw () [protected, virtual]

Replaces a removed edge/lane.

Parameters:
[in] removed The edge to replace
[in] removedLane The lane of this edge to replace
[in] by The edge to insert instead
[in] byLane This edge's lane to insert instead
See also:
NBTrafficLightDefinition::replaceRemoved

Implements NBTrafficLightDefinition.

Definition at line 395 of file NBOwnTLDef.cpp.

00396                                                                     {}

void NBOwnTLDef::setParticipantsInformation (  )  throw () [virtual]

Builds the list of participating nodes/edges/links.

See also:
NBTrafficLightDefinition::setParticipantsInformation

Reimplemented from NBTrafficLightDefinition.

Definition at line 365 of file NBOwnTLDef.cpp.

References NBTrafficLightDefinition::collectEdges(), collectLinks(), and collectNodes().

00365                                                {
00366     // assign participating nodes to the request
00367     collectNodes();
00368     // collect the information about participating edges and links
00369     collectEdges();
00370     collectLinks();
00371 }

void NBOwnTLDef::setTLControllingInformation ( const NBEdgeCont ec  )  const throw () [virtual]

Informs edges about being controlled by a tls.

Parameters:
[in] ec The container of edges
See also:
NBTrafficLightDefinition::setTLControllingInformation

Implements NBTrafficLightDefinition.

Definition at line 375 of file NBOwnTLDef.cpp.

References NBConnection::getFrom(), NBConnection::getFromLane(), Named::getID(), NBConnection::getTo(), NBConnection::getToLane(), NBTrafficLightDefinition::myControlledLinks, and NBEdge::setControllingTLInformation().

00375                                                                         {
00376     // set the information about the link's positions within the tl into the
00377     //  edges the links are starting at, respectively
00378     unsigned int pos = 0;
00379     for (NBConnectionVector::const_iterator j=myControlledLinks.begin(); j!=myControlledLinks.end(); ++j) {
00380         const NBConnection &conn = *j;
00381         NBEdge *edge = conn.getFrom();
00382         if (edge->setControllingTLInformation(conn.getFromLane(), conn.getTo(), conn.getToLane(), getID(), pos)) {
00383             pos++;
00384         }
00385     }
00386 }


Field Documentation

std::vector<std::string> NBTrafficLightDefinition::myControlledInnerEdges [protected, inherited]

List of inner edges that shall be controlled, though.

Definition at line 315 of file NBTrafficLightDefinition.h.

Referenced by NBTrafficLightDefinition::addControlledInnerEdges(), and NBTrafficLightDefinition::collectEdges().

std::vector<NBNode*> NBTrafficLightDefinition::myControlledNodes [protected, inherited]

The list of edges within the area controlled by the tls.

Definition at line 309 of file NBTrafficLightDefinition.h.

Referenced by NBTrafficLightDefinition::collectEdges().

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


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

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