NBRequest Class Reference

#include <NBRequest.h>


Detailed Description

Given a special node, this class builds the logic of this (junction) regarding the relationships between the incoming and outgoing edges and their priorities. The junction's logic is saved when it does not yet exist.

Definition at line 62 of file NBRequest.h.


Public Member Functions

void buildBitfieldLogic (bool leftHanded, NBJunctionLogicCont &jc, const std::string &key)
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.
std::pair< unsigned int,
unsigned int > 
getSizes () const
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.
bool mustBrake (const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo) const throw ()
 Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
 NBRequest (const NBEdgeCont &ec, NBNode *junction, const EdgeVector *const all, const EdgeVector *const incoming, const EdgeVector *const outgoing, const NBConnectionProhibits &loadedProhibits)
 ~NBRequest ()

Static Public Member Functions

static void reportWarnings ()
 reports warnings if any occured

Private Types

typedef std::vector< LinkInfoContCombinationsCont
typedef std::vector< boolLinkInfoCont
typedef std::map< NBEdge
*, LaneVector
OccupiedLanes

Private Member Functions

std::string bitsetToXML (std::string key)
void computeLeftOutgoingLinkCrossings (bool leftHanded, NBEdge *from, NBEdge *to)
void computeRightOutgoingLinkCrossings (bool leftHanded, NBEdge *from, NBEdge *to)
size_t distanceCounterClockwise (NBEdge *from, NBEdge *to)
int getIndex (const NBEdge *const from, const NBEdge *const to) const throw ()
 Returns the index to the internal combination container for the given edge combination.
void resetSignalised ()
void setBlocking (bool leftHanded, NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
void writeAreFoes (std::ostream &os, NBEdge *from, NBEdge *to, bool isInnerEnd)
int writeLaneResponse (std::ostream &os, NBEdge *from, int lane, int pos)
 writes the response of a certain lane Returns the next link index within the junction
void writeResponse (std::ostream &os, const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool mayDefinitelyPass) const throw (IOError)
 Writes the response of a certain link.

Private Attributes

const EdgeVector *const myAll
CombinationsCont myDone
CombinationsCont myForbids
const EdgeVector *const myIncoming
NBNodemyJunction
 the node the request is assigned to
const EdgeVector *const myOutgoing

Static Private Attributes

static size_t myGoodBuilds = 0
static size_t myNotBuild = 0

Friends

std::ostream & operator<< (std::ostream &os, const NBRequest &r)
 prints the request

Member Typedef Documentation

typedef std::vector<LinkInfoCont> NBRequest::CombinationsCont [private]

definition of a container for link(edge->edge) X link(edge->edge) combinations (size = |myIncoming|*|myOutgoing|)

Definition at line 220 of file NBRequest.h.

typedef std::vector<bool> NBRequest::LinkInfoCont [private]

definition of a container to store boolean informations about a link into

Definition at line 216 of file NBRequest.h.

typedef std::map<NBEdge*, LaneVector> NBRequest::OccupiedLanes [private]

a container for approached lanes of a certain edge

Definition at line 223 of file NBRequest.h.


Constructor & Destructor Documentation

NBRequest::NBRequest ( const NBEdgeCont ec,
NBNode junction,
const EdgeVector *const   all,
const EdgeVector *const   incoming,
const EdgeVector *const   outgoing,
const NBConnectionProhibits loadedProhibits 
)

constructor The parameter are the logic's lists of edges (all, incoming only and outgoing only edges). By now no further informations are needed to describe the junctions. These parameter must not be changed during the logic's building

Definition at line 64 of file NBRequest.cpp.

References NBConnection::check(), NBConnection::getFrom(), NBEdge::getID(), getIndex(), NBConnection::getTo(), myDone, myForbids, myGoodBuilds, myIncoming, myNotBuild, myOutgoing, and WRITE_WARNING.

00069         : myJunction(junction),
00070         myAll(all), myIncoming(incoming), myOutgoing(outgoing) {
00071     size_t variations = myIncoming->size() * myOutgoing->size();
00072     // build maps with information which forbidding connection were
00073     //  computed and what's in there
00074     myForbids.reserve(variations);
00075     myDone.reserve(variations);
00076     for (size_t i=0; i<variations; i++) {
00077         myForbids.push_back(LinkInfoCont(variations, false));
00078         myDone.push_back(LinkInfoCont(variations, false));
00079     }
00080     // insert loaded prohibits
00081     for (NBConnectionProhibits::const_iterator j=loadedProhibits.begin(); j!=loadedProhibits.end(); j++) {
00082         NBConnection prohibited = (*j).first;
00083         bool ok1 = prohibited.check(ec);
00084         if (find(myIncoming->begin(), myIncoming->end(), prohibited.getFrom())==myIncoming->end()) {
00085             ok1 = false;
00086         }
00087         if (find(myOutgoing->begin(), myOutgoing->end(), prohibited.getTo())==myOutgoing->end()) {
00088             ok1 = false;
00089         }
00090         int idx1 = 0;
00091         if (ok1) {
00092             idx1 = getIndex(prohibited.getFrom(), prohibited.getTo());
00093             if (idx1<0) {
00094                 ok1 = false;
00095             }
00096         }
00097         const NBConnectionVector &prohibiting = (*j).second;
00098         for (NBConnectionVector::const_iterator k=prohibiting.begin(); k!=prohibiting.end(); k++) {
00099             NBConnection sprohibiting = *k;
00100             bool ok2 = sprohibiting.check(ec);
00101             if (find(myIncoming->begin(), myIncoming->end(), sprohibiting.getFrom())==myIncoming->end()) {
00102                 ok2 = false;
00103             }
00104             if (find(myOutgoing->begin(), myOutgoing->end(), sprohibiting.getTo())==myOutgoing->end()) {
00105                 ok2 = false;
00106             }
00107             if (ok1&&ok2) {
00108                 int idx2 = getIndex(sprohibiting.getFrom(), sprohibiting.getTo());
00109                 if (idx2<0) {
00110                     ok2 = false;
00111                 } else {
00112                     myForbids[idx2][idx1] = true;
00113                     myDone[idx2][idx1] = true;
00114                     myDone[idx1][idx2] = true;
00115                     myGoodBuilds++;
00116                 }
00117             } else {
00118                 std::string pfID = prohibited.getFrom()!=0 ? prohibited.getFrom()->getID() : "UNKNOWN";
00119                 std::string ptID = prohibited.getTo()!=0 ? prohibited.getTo()->getID() : "UNKNOWN";
00120                 std::string bfID = sprohibiting.getFrom()!=0 ? sprohibiting.getFrom()->getID() : "UNKNOWN";
00121                 std::string btID = sprohibiting.getTo()!=0 ? sprohibiting.getTo()->getID() : "UNKNOWN";
00122                 WRITE_WARNING("could not prohibit " + pfID + "->" + ptID+ " by "+ bfID + "->" + btID);
00123                 myNotBuild++;
00124             }
00125         }
00126     }
00127     // ok, check whether someone has prohibited two links vice versa
00128     //  (this happens also in some Vissim-networks, when edges are joined)
00129     size_t no = myIncoming->size()*myOutgoing->size();
00130     for (size_t s1=0; s1<no; s1++) {
00131         for (size_t s2=s1+1; s2<no; s2++) {
00132             // not set, yet
00133             if (!myDone[s1][s2]) {
00134                 continue;
00135             }
00136             // check whether both prohibit vice versa
00137             if (myForbids[s1][s2]&&myForbids[s2][s1]) {
00138                 // mark unset - let our algorithm fix it later
00139                 myDone[s1][s2] = false;
00140                 myDone[s2][s1] = false;
00141             }
00142         }
00143     }
00144 }

NBRequest::~NBRequest (  ) 

destructor

Definition at line 147 of file NBRequest.cpp.

00147 {}


Member Function Documentation

std::string NBRequest::bitsetToXML ( std::string  key  )  [private]

returns the XML-representation of the logic as a bitset-logic XML representation

Definition at line 322 of file NBRequest.cpp.

References getSizes(), myIncoming, resetSignalised(), and writeLaneResponse().

Referenced by buildBitfieldLogic().

00322                                     {
00323     std::ostringstream os;
00324     // reset signalised/non-signalised dependencies
00325     resetSignalised();
00326     // init
00327     std::pair<size_t, size_t> sizes = getSizes();
00328     size_t absNoLinks = sizes.second;
00329     size_t absNoLanes = sizes.first;
00330     assert(absNoLinks>=absNoLanes);
00331     os << "   <row-logic id=\"" << key << "\" requestSize=\"" << absNoLinks
00332     << "\" laneNumber=\"" << absNoLanes << "\">" << std::endl;
00333     int pos = 0;
00334     // save the logic
00335     os << "      <logic>" << std::endl;
00336     EdgeVector::const_iterator i;
00337     for (i=myIncoming->begin(); i!=myIncoming->end(); i++) {
00338         unsigned int noLanes = (*i)->getNoLanes();
00339         for (unsigned int k=0; k<noLanes; k++) {
00340             pos = writeLaneResponse(os, *i, k, pos);
00341         }
00342     }
00343     os << "      </logic>" << std::endl;
00344     os << "   </row-logic>" << std::endl;
00345     return os.str();
00346 }

void NBRequest::buildBitfieldLogic ( bool  leftHanded,
NBJunctionLogicCont jc,
const std::string &  key 
)

builds the bitset-representation of the logic

Definition at line 151 of file NBRequest.cpp.

References NBJunctionLogicCont::add(), bitsetToXML(), computeLeftOutgoingLinkCrossings(), computeRightOutgoingLinkCrossings(), myIncoming, and myOutgoing.

Referenced by NBNode::computeLogic().

00152                                                     {
00153     EdgeVector::const_iterator i, j;
00154     for (i=myIncoming->begin(); i!=myIncoming->end(); i++) {
00155         for (j=myOutgoing->begin(); j!=myOutgoing->end(); j++) {
00156             computeRightOutgoingLinkCrossings(leftHanded, *i, *j);
00157             computeLeftOutgoingLinkCrossings(leftHanded, *i, *j);
00158         }
00159     }
00160     jc.add(key, bitsetToXML(key));
00161 }

void NBRequest::computeLeftOutgoingLinkCrossings ( bool  leftHanded,
NBEdge from,
NBEdge to 
) [private]

computes the relationships between links outgoing left of the given link

Definition at line 183 of file NBRequest.cpp.

References myAll, myJunction, NBContHelper::nextCW(), and setBlocking().

Referenced by buildBitfieldLogic().

00183                                                                                      {
00184     EdgeVector::const_iterator pfrom = find(myAll->begin(), myAll->end(), from);
00185     while (*pfrom!=to) {
00186         NBContHelper::nextCW(myAll, pfrom);
00187         if ((*pfrom)->getToNode()==myJunction) {
00188             EdgeVector::const_iterator pto = find(myAll->begin(), myAll->end(), to);
00189             while (*pto!=from) {
00190                 if (!((*pto)->getToNode()==myJunction)) {
00191                     setBlocking(leftHanded, from, to, *pfrom, *pto);
00192                 }
00193                 NBContHelper::nextCW(myAll, pto);
00194             }
00195         }
00196     }
00197 }

void NBRequest::computeRightOutgoingLinkCrossings ( bool  leftHanded,
NBEdge from,
NBEdge to 
) [private]

computes the relationships between links outgoing right of the given link

Definition at line 165 of file NBRequest.cpp.

References myAll, myJunction, NBContHelper::nextCCW(), and setBlocking().

Referenced by buildBitfieldLogic().

00165                                                                                       {
00166     EdgeVector::const_iterator pfrom = find(myAll->begin(), myAll->end(), from);
00167     while (*pfrom!=to) {
00168         NBContHelper::nextCCW(myAll, pfrom);
00169         if ((*pfrom)->getToNode()==myJunction) {
00170             EdgeVector::const_iterator pto = find(myAll->begin(), myAll->end(), to);
00171             while (*pto!=from) {
00172                 if (!((*pto)->getToNode()==myJunction)) {
00173                     setBlocking(leftHanded, from, to, *pfrom, *pto);
00174                 }
00175                 NBContHelper::nextCCW(myAll, pto);
00176             }
00177         }
00178     }
00179 }

size_t NBRequest::distanceCounterClockwise ( NBEdge from,
NBEdge to 
) [private]

returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges

Definition at line 305 of file NBRequest.cpp.

References myAll.

00305                                                             {
00306     EdgeVector::const_iterator p = find(myAll->begin(), myAll->end(), from);
00307     size_t ret = 0;
00308     while (true) {
00309         ret++;
00310         if (p==myAll->begin()) {
00311             p = myAll->end();
00312         }
00313         p--;
00314         if ((*p)==to) {
00315             return ret;
00316         }
00317     }
00318 }

bool NBRequest::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.

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 428 of file NBRequest.cpp.

References getIndex(), myForbids, myOutgoing, and size.

Referenced by NBNode::foes(), resetSignalised(), and writeAreFoes().

00429                                                                                     {
00430     // unconnected edges do not forbid other edges
00431     if (to1==0 || to2==0) {
00432         return false;
00433     }
00434     // get the indices
00435     int idx1 = getIndex(from1, to1);
00436     int idx2 = getIndex(from2, to2);
00437     if (idx1<0||idx2<0) {
00438         return false; // sure? (The connection does not exist within this junction)
00439     }
00440     assert((size_t) idx1<myIncoming->size()*myOutgoing->size());
00441     assert((size_t) idx2<myIncoming->size()*myOutgoing->size());
00442     return myForbids[idx1][idx2] || myForbids[idx2][idx1];
00443 }

bool NBRequest::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.

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

Definition at line 447 of file NBRequest.cpp.

References getIndex(), myForbids, myOutgoing, and size.

Referenced by NBNode::forbids().

00449                                                                         {
00450     // unconnected edges do not forbid other edges
00451     if (possProhibitorTo==0 || possProhibitedTo==0) {
00452         return false;
00453     }
00454     // get the indices
00455     int possProhibitorIdx = getIndex(possProhibitorFrom, possProhibitorTo);
00456     int possProhibitedIdx = getIndex(possProhibitedFrom, possProhibitedTo);
00457     if (possProhibitorIdx<0||possProhibitedIdx<0) {
00458         return false; // sure? (The connection does not exist within this junction)
00459     }
00460     assert((size_t) possProhibitorIdx<myIncoming->size()*myOutgoing->size());
00461     assert((size_t) possProhibitedIdx<myIncoming->size()*myOutgoing->size());
00462     // check simple right-of-way-rules
00463     if (!regardNonSignalisedLowerPriority) {
00464         return myForbids[possProhibitorIdx][possProhibitedIdx];
00465     }
00466     // if its not forbidden, report
00467     if (!myForbids[possProhibitorIdx][possProhibitedIdx]) {
00468         return false;
00469     }
00470     // do not forbid a signalised stream by a non-signalised
00471     if (!possProhibitorFrom->hasSignalisedConnectionTo(possProhibitorTo)) {
00472         return false;
00473     }
00474     return true;
00475 }

int NBRequest::getIndex ( const NBEdge *const   from,
const NBEdge *const   to 
) const throw () [private]

Returns the index to the internal combination container for the given edge combination.

If one of the edges is not known, -1 is returned.

Parameters:
[in] from The starting edge (incoming to this logic)
[in] to The destination edge (outgoing from this logic)
Returns:
The index within the internal container

Definition at line 575 of file NBRequest.cpp.

References myIncoming, and myOutgoing.

Referenced by foes(), forbids(), mustBrake(), NBRequest(), resetSignalised(), setBlocking(), writeAreFoes(), and writeResponse().

00575                                                                                     {
00576     EdgeVector::const_iterator fp = find(myIncoming->begin(), myIncoming->end(), from);
00577     EdgeVector::const_iterator tp = find(myOutgoing->begin(), myOutgoing->end(), to);
00578     if (fp==myIncoming->end()||tp==myOutgoing->end()) {
00579         return -1;
00580     }
00581     // compute the index
00582     return (int)(distance(myIncoming->begin(), fp) * myOutgoing->size() + distance(myOutgoing->begin(), tp));
00583 }

std::pair< unsigned int, unsigned int > NBRequest::getSizes (  )  const

returns the number of the junction's lanes and the number of the junction's links in respect

Definition at line 410 of file NBRequest.cpp.

References myIncoming.

Referenced by bitsetToXML(), and NBNode::computeLogic().

00410                           {
00411     unsigned int noLanes = 0;
00412     unsigned int noLinks = 0;
00413     for (EdgeVector::const_iterator i=myIncoming->begin();
00414             i!=myIncoming->end(); i++) {
00415         unsigned int noLanesEdge = (*i)->getNoLanes();
00416         for (unsigned int j=0; j<noLanesEdge; j++) {
00417             // assert that at least one edge is approached from this lane
00418             assert((*i)->getConnectionsFromLane(j).size()!=0);
00419             noLinks += (unsigned int)(*i)->getConnectionsFromLane(j).size();
00420         }
00421         noLanes += noLanesEdge;
00422     }
00423     return std::pair<size_t, size_t>(noLanes, noLinks);
00424 }

bool NBRequest::mustBrake ( const NBEdge *const   from,
const NBEdge *const   to 
) const throw ()

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

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 605 of file NBRequest.cpp.

References getIndex(), myDone, myForbids, myIncoming, myOutgoing, and size.

00605                                                                                      {
00606     // vehicles which do not have a following lane must always decelerate to the end
00607     if (to==0) {
00608         return true;
00609     }
00610     // get the indices
00611     int idx2 = getIndex(from, to);
00612     if (idx2==-1) {
00613         return false;
00614     }
00615     // go through all (existing) connections;
00616     //  check whether any of these forbids the one to determine
00617     assert((size_t) idx2<myIncoming->size()*myOutgoing->size());
00618     for (size_t idx1=0; idx1<myIncoming->size()*myOutgoing->size(); idx1++) {
00619         //assert(myDone[idx1][idx2]);
00620         if (myDone[idx1][idx2]&&myForbids[idx1][idx2]) {
00621             return true;
00622         }
00623     }
00624     return false;
00625 }

bool NBRequest::mustBrake ( const NBEdge *const   possProhibitorFrom,
const NBEdge *const   possProhibitorTo,
const NBEdge *const   possProhibitedFrom,
const NBEdge *const   possProhibitedTo 
) const throw ()

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

Parameters:
[in] possProhibitorFrom The maybe prohibiting connection's begin
[in] possProhibitorTo The maybe prohibiting connection's end
[in] possProhibitedFrom The maybe prohibited connection's begin
[in] possProhibitedTo The maybe prohibited connection's end
Returns:
Whether the first flow prohibits the second one

Definition at line 629 of file NBRequest.cpp.

References getIndex(), and myForbids.

Referenced by NBNode::mustBrake().

00630                                                                                                                    {
00631     // get the indices
00632     int idx1 = getIndex(possProhibitorFrom, possProhibitorTo);
00633     int idx2 = getIndex(possProhibitedFrom, possProhibitedTo);
00634     return (myForbids[idx2][idx1]);
00635 }

void NBRequest::reportWarnings (  )  [static]

reports warnings if any occured

Definition at line 639 of file NBRequest.cpp.

References myGoodBuilds, myNotBuild, toString(), and WRITE_WARNING.

Referenced by NBNetBuilder::compute().

00639                           {
00640     // check if any errors occured on build the link prohibitions
00641     if (myNotBuild!=0) {
00642         WRITE_WARNING(toString(myNotBuild) + " of " + toString(myNotBuild+myGoodBuilds)+ " prohibitions were not build.");
00643     }
00644 }

void NBRequest::resetSignalised (  )  [private]

Definition at line 350 of file NBRequest.cpp.

References foes(), getIndex(), myForbids, and myIncoming.

Referenced by bitsetToXML().

00350                            {
00351     // go through possible prohibitions
00352     for (EdgeVector::const_iterator i11=myIncoming->begin(); i11!=myIncoming->end(); i11++) {
00353         unsigned int noLanesEdge1 = (*i11)->getNoLanes();
00354         for (unsigned int j1=0; j1<noLanesEdge1; j1++) {
00355             std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
00356             for (std::vector<NBEdge::Connection>::iterator i12=el1.begin(); i12!=el1.end(); ++i12) {
00357                 int idx1 = getIndex((*i11), (*i12).toEdge);
00358                 if (idx1<0) {
00359                     continue;
00360                 }
00361                 // go through possibly prohibited
00362                 for (EdgeVector::const_iterator i21=myIncoming->begin(); i21!=myIncoming->end(); i21++) {
00363                     unsigned int noLanesEdge2 = (*i21)->getNoLanes();
00364                     for (unsigned int j2=0; j2<noLanesEdge2; j2++) {
00365                         std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
00366                         for (std::vector<NBEdge::Connection>::iterator i22=el2.begin(); i22!=el2.end(); i22++) {
00367                             int idx2 = getIndex((*i21), (*i22).toEdge);
00368                             if (idx2<0) {
00369                                 continue;
00370                             }
00371                             // check
00372                             // same incoming connections do not prohibit each other
00373                             if ((*i11)==(*i21)) {
00374                                 myForbids[idx1][idx2] = false;
00375                                 myForbids[idx2][idx1] = false;
00376                                 continue;
00377                             }
00378                             // check other
00379                             // if both are non-signalised or both are signalised
00380                             if (((*i12).tlID==""&&(*i22).tlID=="")
00381                                     ||
00382                                     ((*i12).tlID!=""&&(*i22).tlID!="")) {
00383                                 // do nothing
00384                                 continue;
00385                             }
00386                             // supposing, we don not have to
00387                             //  brake if we are no foes
00388                             if (!foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
00389                                 continue;
00390                             }
00391                             // otherwise:
00392                             //  the non-signalised must break
00393                             if ((*i12).tlID!="") {
00394                                 myForbids[idx1][idx2] = true;
00395                                 myForbids[idx2][idx1] = false;
00396                             } else {
00397                                 myForbids[idx1][idx2] = false;
00398                                 myForbids[idx2][idx1] = true;
00399                             }
00400                         }
00401                     }
00402                 }
00403             }
00404         }
00405     }
00406 }

void NBRequest::setBlocking ( bool  leftHanded,
NBEdge from1,
NBEdge to1,
NBEdge from2,
NBEdge to2 
) [private]

sets the information that the edge from1->to1 blocks the edge from2->to2 (is higher priorised than this)

Definition at line 201 of file NBRequest.cpp.

References getIndex(), NBEdge::getJunctionPriority(), NBNode::getType(), NBEdge::isTurningDirectionAt(), myAll, myDone, myForbids, myJunction, myOutgoing, NBContHelper::nextCW(), NBNode::NODETYPE_RIGHT_BEFORE_LEFT, and size.

Referenced by computeLeftOutgoingLinkCrossings(), and computeRightOutgoingLinkCrossings().

00203                                                    {
00204     // check whether one of the links has a dead end
00205     if (to1==0||to2==0) {
00206         return;
00207     }
00208     // get the indices of both links
00209     int idx1 = getIndex(from1, to1);
00210     int idx2 = getIndex(from2, to2);
00211     if (idx1<0||idx2<0) {
00212         return; // !!! error output? did not happend, yet
00213     }
00214     // check whether the link crossing has already been checked
00215     assert((size_t) idx1<myIncoming->size()*myOutgoing->size());
00216     if (myDone[idx1][idx2]) {
00217         return;
00218     }
00219     // mark the crossings as done
00220     myDone[idx1][idx2] = true;
00221     myDone[idx2][idx1] = true;
00222     // check if one of the links is a turn; this link is always not priorised
00223     //  true for right-before-left and priority
00224     if (from1->isTurningDirectionAt(myJunction, to1)) {
00225         myForbids[idx2][idx1] = true;
00226         return;
00227     }
00228     if (from2->isTurningDirectionAt(myJunction, to2)) {
00229         myForbids[idx1][idx2] = true;
00230         return;
00231     }
00232 
00233     // check the priorities
00234     int from1p = from1->getJunctionPriority(myJunction);
00235     int from2p = from2->getJunctionPriority(myJunction);
00236     // check if one of the connections is higher priorised when incoming into
00237     //  the junction, the connection road will yield
00238     // should be valid for priority junctions only
00239     if (from1p>from2p) {
00240         assert(myJunction->getType()!=NBNode::NODETYPE_RIGHT_BEFORE_LEFT);
00241         myForbids[idx1][idx2] = true;
00242         return;
00243     }
00244     if (from2p>from1p) {
00245         assert(myJunction->getType()!=NBNode::NODETYPE_RIGHT_BEFORE_LEFT);
00246         myForbids[idx2][idx1] = true;
00247         return;
00248     }
00249 
00250     // check whether one of the connections is higher priorised on
00251     //  the outgoing edge when both roads are high priorised
00252     //  the connection with the lower priorised outgoing edge will lead
00253     // should be valid for priority junctions only
00254     if (from1p>0&&from2p>0) {
00255         assert(myJunction->getType()!=NBNode::NODETYPE_RIGHT_BEFORE_LEFT);
00256         int to1p = to1->getJunctionPriority(myJunction);
00257         int to2p = to2->getJunctionPriority(myJunction);
00258         if (to1p>to2p) {
00259             myForbids[idx1][idx2] = true;
00260             return;
00261         }
00262         if (to2p>to1p) {
00263             myForbids[idx2][idx1] = true;
00264             return;
00265         }
00266     }
00267 
00268     // compute the yielding due to the right-before-left rule
00269     // get the position of the incoming lanes in the junction-wheel
00270     EdgeVector::const_iterator c1 = find(myAll->begin(), myAll->end(), from1);
00271     NBContHelper::nextCW(myAll, c1);
00272     // go through next edges clockwise...
00273     while (*c1!=from1&&*c1!=from2) {
00274         if (*c1==to2) {
00275             // if we encounter to2 the second one prohibits the first
00276             if (!leftHanded) {
00277                 myForbids[idx2][idx1] = true;
00278             } else {
00279                 myForbids[idx1][idx2] = true;
00280             }
00281             return;
00282         }
00283         NBContHelper::nextCW(myAll, c1);
00284     }
00285     // get the position of the incoming lanes in the junction-wheel
00286     EdgeVector::const_iterator c2 = find(myAll->begin(), myAll->end(), from2);
00287     NBContHelper::nextCW(myAll, c2);
00288     // go through next edges clockwise...
00289     while (*c2!=from2&&*c2!=from1) {
00290         if (*c2==to1) {
00291             // if we encounter to1 the second one prohibits the first
00292             if (!leftHanded) {
00293                 myForbids[idx1][idx2] = true;
00294             } else {
00295                 myForbids[idx2][idx1] = true;
00296             }
00297             return;
00298         }
00299         NBContHelper::nextCW(myAll, c2);
00300     }
00301 }

void NBRequest::writeAreFoes ( std::ostream &  os,
NBEdge from,
NBEdge to,
bool  isInnerEnd 
) [private]

writes which participating links are foes to the given

Definition at line 541 of file NBRequest.cpp.

References foes(), getIndex(), myIncoming, and size.

Referenced by writeLaneResponse().

00541                                                                                  {
00542     // remember the case when the lane is a "dead end" in the meaning that
00543     // vehicles must choose another lane to move over the following
00544     // junction
00545     int idx = 0;
00546     if (to!=0) {
00547         idx = getIndex(from, to);
00548     }
00549     // !!! move to forbidden
00550     for (EdgeVector::const_reverse_iterator i=myIncoming->rbegin();
00551             i!=myIncoming->rend(); i++) {
00552 
00553         unsigned int noLanes = (*i)->getNoLanes();
00554         for (unsigned int j=noLanes; j-->0;) {
00555             std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
00556             int size = (int) connected.size();
00557             for (int k=size; k-->0;) {
00558                 if (to==0) {
00559                     os << '0';
00560                 } else {
00561 //                    if (foes(from, to, (*i), connected[k].edge) && !isInnerEnd) {
00562                     if (foes(from, to, (*i), connected[k].toEdge)) {
00563                         os << '1';
00564                     } else {
00565                         os << '0';
00566                     }
00567                 }
00568             }
00569         }
00570     }
00571 }

int NBRequest::writeLaneResponse ( std::ostream &  os,
NBEdge from,
int  lane,
int  pos 
) [private]

writes the response of a certain lane Returns the next link index within the junction

Definition at line 479 of file NBRequest.cpp.

References OptionsCont::getBool(), NBEdge::getConnectionsFromLane(), NBNode::getCrossingPosition(), OptionsCont::getOptions(), myJunction, writeAreFoes(), and writeResponse().

Referenced by bitsetToXML().

00480                                                     {
00481     std::vector<NBEdge::Connection> connected = from->getConnectionsFromLane(fromLane);
00482     for (std::vector<NBEdge::Connection>::iterator j=connected.begin(); j!=connected.end(); j++) {
00483         os << "         <logicitem request=\"" << pos++ << "\" response=\"";
00484         writeResponse(os, from, (*j).toEdge, fromLane, (*j).toLane, (*j).mayDefinitelyPass);
00485         os << "\" foes=\"";
00486         writeAreFoes(os, from, (*j).toEdge, myJunction->getCrossingPosition(from, fromLane, (*j).toEdge, (*j).toLane).first>=0);
00487         os << "\"";
00488         if (!OptionsCont::getOptions().getBool("no-internal-links")) {
00489             if (myJunction->getCrossingPosition(from, fromLane, (*j).toEdge, (*j).toLane).first>=0) {
00490                 os << " cont=\"1\"";
00491             } else {
00492                 os << " cont=\"0\"";
00493             }
00494         }
00495         os << "/>" << std::endl;
00496     }
00497     return pos;
00498 }

void NBRequest::writeResponse ( std::ostream &  os,
const NBEdge *const   from,
const NBEdge *const   to,
int  fromLane,
int  toLane,
bool  mayDefinitelyPass 
) const throw (IOError) [private]

Writes the response of a certain link.

For the link (described by the connected edges and lanes), the response in dependence to all other links of this junction is computed. Herefor, the method goes through all links of this junction and writes a '0' if the link is not blocked by the currently investigated one, or '1' if it is.

In the case "mayDefinitelyPass" is true, the link will not be disturbed by any other (special case for on-ramps).

Parameters:
[in] os The stream to write the information to
[in] from The link's starting edge
[in] to The link's destination edge
[in] fromLane The link's starting lane
[in] toLane The link's destination lane
[in] mayDefinitelyPass Whether this link is definitely not disturbed
Exceptions:
IOError not yet implemented

Definition at line 502 of file NBRequest.cpp.

References getIndex(), myForbids, myIncoming, myOutgoing, and size.

Referenced by writeLaneResponse().

00503                                                                                                 {
00504     int idx = 0;
00505     if (to!=0) {
00506         idx = getIndex(from, to);
00507     }
00508     for (EdgeVector::const_reverse_iterator i=myIncoming->rbegin(); i!=myIncoming->rend(); i++) {
00509         const std::vector<NBEdge::Connection> &allConnections = (*i)->getConnections();
00510         unsigned int noLanes = (*i)->getNoLanes();
00511         for (int j=noLanes; j-->0;) {
00512             std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
00513             int size = (int) connected.size();
00514             for (int k=size; k-->0;) {
00515                 if (mayDefinitelyPass) {
00516                     os << '0';
00517                 } else if (to==0) {
00518                     // should wait if no further connection!?
00519                     os << '1';
00520                 } else if ((*i)==from&&fromLane==j) {
00521                     // do not prohibit a connection by others from same lane
00522                     os << '0';
00523                 } else {
00524                     assert(k<(int) connected.size());
00525                     assert((size_t) idx<myIncoming->size()*myOutgoing->size());
00526                     assert(connected[k].toEdge==0 || (size_t) getIndex(*i, connected[k].toEdge)<myIncoming->size()*myOutgoing->size());
00527                     // check whether the connection is prohibited by another one
00528                     if (connected[k].toEdge!=0 && myForbids[getIndex(*i, connected[k].toEdge)][idx]) {
00529                         os << '1';
00530                         continue;
00531                     }
00532                     os << '0';
00533                 }
00534             }
00535         }
00536     }
00537 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const NBRequest r 
) [friend]

prints the request

Definition at line 587 of file NBRequest.cpp.

00587                                                {
00588     size_t variations = r.myIncoming->size() * r.myOutgoing->size();
00589     for (size_t i=0; i<variations; i++) {
00590         os << i << ' ';
00591         for (size_t j=0; j<variations; j++) {
00592             if (r.myForbids[i][j])
00593                 os << '1';
00594             else
00595                 os << '0';
00596         }
00597         os << std::endl;
00598     }
00599     os << std::endl;
00600     return os;
00601 }


Field Documentation

const EdgeVector* const NBRequest::myAll [private]

all (icoming and outgoing) of the junctions edges

Definition at line 206 of file NBRequest.h.

Referenced by computeLeftOutgoingLinkCrossings(), computeRightOutgoingLinkCrossings(), distanceCounterClockwise(), and setBlocking().

the link X link is done-checks

Definition at line 229 of file NBRequest.h.

Referenced by mustBrake(), NBRequest(), and setBlocking().

the link X link blockings

Definition at line 226 of file NBRequest.h.

Referenced by foes(), forbids(), mustBrake(), NBRequest(), operator<<(), resetSignalised(), setBlocking(), and writeResponse().

size_t NBRequest::myGoodBuilds = 0 [static, private]

Definition at line 232 of file NBRequest.h.

Referenced by NBRequest(), and reportWarnings().

const EdgeVector* const NBRequest::myIncoming [private]

edges incoming to the junction

Definition at line 209 of file NBRequest.h.

Referenced by bitsetToXML(), buildBitfieldLogic(), getIndex(), getSizes(), mustBrake(), NBRequest(), operator<<(), resetSignalised(), writeAreFoes(), and writeResponse().

the node the request is assigned to

Definition at line 203 of file NBRequest.h.

Referenced by computeLeftOutgoingLinkCrossings(), computeRightOutgoingLinkCrossings(), setBlocking(), and writeLaneResponse().

size_t NBRequest::myNotBuild = 0 [static, private]

Definition at line 232 of file NBRequest.h.

Referenced by NBRequest(), and reportWarnings().

const EdgeVector* const NBRequest::myOutgoing [private]

edges outgoing from the junction

Definition at line 212 of file NBRequest.h.

Referenced by buildBitfieldLogic(), foes(), forbids(), getIndex(), mustBrake(), NBRequest(), operator<<(), setBlocking(), and writeResponse().


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