SUMO - Simulation of Urban MObility

NBRequest.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // This class computes the logic of a junction
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <string>
00031 #include <vector>
00032 #include <set>
00033 #include <algorithm>
00034 #include <bitset>
00035 #include <sstream>
00036 #include <map>
00037 #include <cassert>
00038 #include <utils/common/MsgHandler.h>
00039 #include <utils/common/ToString.h>
00040 #include <utils/options/OptionsCont.h>
00041 #include <utils/iodevices/OutputDevice_String.h>
00042 #include "NBEdge.h"
00043 #include "NBContHelper.h"
00044 #include "NBTrafficLightLogic.h"
00045 #include "NBTrafficLightLogicCont.h"
00046 #include "NBNode.h"
00047 #include "NBRequest.h"
00048 
00049 #ifdef CHECK_MEMORY_LEAKS
00050 #include <foreign/nvwa/debug_new.h>
00051 #endif // CHECK_MEMORY_LEAKS
00052 
00053 
00054 // ===========================================================================
00055 // static member variables
00056 // ===========================================================================
00057 size_t NBRequest::myGoodBuilds = 0;
00058 size_t NBRequest::myNotBuild = 0;
00059 
00060 
00061 // ===========================================================================
00062 // method definitions
00063 // ===========================================================================
00064 NBRequest::NBRequest(const NBEdgeCont& ec,
00065                      NBNode* junction,
00066                      const EdgeVector& all,
00067                      const EdgeVector& incoming,
00068                      const EdgeVector& outgoing,
00069                      const NBConnectionProhibits& loadedProhibits)
00070     : myJunction(junction),
00071       myAll(all), myIncoming(incoming), myOutgoing(outgoing) {
00072     size_t variations = myIncoming.size() * myOutgoing.size();
00073     // build maps with information which forbidding connection were
00074     //  computed and what's in there
00075     myForbids.reserve(variations);
00076     myDone.reserve(variations);
00077     for (size_t i=0; i<variations; i++) {
00078         myForbids.push_back(LinkInfoCont(variations, false));
00079         myDone.push_back(LinkInfoCont(variations, false));
00080     }
00081     // insert loaded prohibits
00082     for (NBConnectionProhibits::const_iterator j=loadedProhibits.begin(); j!=loadedProhibits.end(); j++) {
00083         NBConnection prohibited = (*j).first;
00084         bool ok1 = prohibited.check(ec);
00085         if (find(myIncoming.begin(), myIncoming.end(), prohibited.getFrom())==myIncoming.end()) {
00086             ok1 = false;
00087         }
00088         if (find(myOutgoing.begin(), myOutgoing.end(), prohibited.getTo())==myOutgoing.end()) {
00089             ok1 = false;
00090         }
00091         int idx1 = 0;
00092         if (ok1) {
00093             idx1 = getIndex(prohibited.getFrom(), prohibited.getTo());
00094             if (idx1<0) {
00095                 ok1 = false;
00096             }
00097         }
00098         const NBConnectionVector& prohibiting = (*j).second;
00099         for (NBConnectionVector::const_iterator k=prohibiting.begin(); k!=prohibiting.end(); k++) {
00100             NBConnection sprohibiting = *k;
00101             bool ok2 = sprohibiting.check(ec);
00102             if (find(myIncoming.begin(), myIncoming.end(), sprohibiting.getFrom())==myIncoming.end()) {
00103                 ok2 = false;
00104             }
00105             if (find(myOutgoing.begin(), myOutgoing.end(), sprohibiting.getTo())==myOutgoing.end()) {
00106                 ok2 = false;
00107             }
00108             if (ok1&&ok2) {
00109                 int idx2 = getIndex(sprohibiting.getFrom(), sprohibiting.getTo());
00110                 if (idx2<0) {
00111                     ok2 = false;
00112                 } else {
00113                     myForbids[idx2][idx1] = true;
00114                     myDone[idx2][idx1] = true;
00115                     myDone[idx1][idx2] = true;
00116                     myGoodBuilds++;
00117                 }
00118             } else {
00119                 std::string pfID = prohibited.getFrom()!=0 ? prohibited.getFrom()->getID() : "UNKNOWN";
00120                 std::string ptID = prohibited.getTo()!=0 ? prohibited.getTo()->getID() : "UNKNOWN";
00121                 std::string bfID = sprohibiting.getFrom()!=0 ? sprohibiting.getFrom()->getID() : "UNKNOWN";
00122                 std::string btID = sprohibiting.getTo()!=0 ? sprohibiting.getTo()->getID() : "UNKNOWN";
00123                 WRITE_WARNING("could not prohibit " + pfID + "->" + ptID+ " by "+ bfID + "->" + btID);
00124                 myNotBuild++;
00125             }
00126         }
00127     }
00128     // ok, check whether someone has prohibited two links vice versa
00129     //  (this happens also in some Vissim-networks, when edges are joined)
00130     size_t no = myIncoming.size()*myOutgoing.size();
00131     for (size_t s1=0; s1<no; s1++) {
00132         for (size_t s2=s1+1; s2<no; s2++) {
00133             // not set, yet
00134             if (!myDone[s1][s2]) {
00135                 continue;
00136             }
00137             // check whether both prohibit vice versa
00138             if (myForbids[s1][s2]&&myForbids[s2][s1]) {
00139                 // mark unset - let our algorithm fix it later
00140                 myDone[s1][s2] = false;
00141                 myDone[s2][s1] = false;
00142             }
00143         }
00144     }
00145 }
00146 
00147 
00148 NBRequest::~NBRequest() {}
00149 
00150 
00151 void
00152 NBRequest::buildBitfieldLogic(bool leftHanded) {
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     // reset signalised/non-signalised dependencies
00161     resetSignalised();
00162 }
00163 
00164 
00165 void
00166 NBRequest::computeRightOutgoingLinkCrossings(bool leftHanded, NBEdge* from, NBEdge* to) {
00167     EdgeVector::const_iterator pfrom = find(myAll.begin(), myAll.end(), from);
00168     while (*pfrom!=to) {
00169         NBContHelper::nextCCW(myAll, pfrom);
00170         if ((*pfrom)->getToNode()==myJunction) {
00171             EdgeVector::const_iterator pto = find(myAll.begin(), myAll.end(), to);
00172             while (*pto!=from) {
00173                 if (!((*pto)->getToNode()==myJunction)) {
00174                     setBlocking(leftHanded, from, to, *pfrom, *pto);
00175                 }
00176                 NBContHelper::nextCCW(myAll, pto);
00177             }
00178         }
00179     }
00180 }
00181 
00182 
00183 void
00184 NBRequest::computeLeftOutgoingLinkCrossings(bool leftHanded, NBEdge* from, NBEdge* to) {
00185     EdgeVector::const_iterator pfrom = find(myAll.begin(), myAll.end(), from);
00186     while (*pfrom!=to) {
00187         NBContHelper::nextCW(myAll, pfrom);
00188         if ((*pfrom)->getToNode()==myJunction) {
00189             EdgeVector::const_iterator pto = find(myAll.begin(), myAll.end(), to);
00190             while (*pto!=from) {
00191                 if (!((*pto)->getToNode()==myJunction)) {
00192                     setBlocking(leftHanded, from, to, *pfrom, *pto);
00193                 }
00194                 NBContHelper::nextCW(myAll, pto);
00195             }
00196         }
00197     }
00198 }
00199 
00200 
00201 void
00202 NBRequest::setBlocking(bool leftHanded,
00203                        NBEdge* from1, NBEdge* to1,
00204                        NBEdge* from2, NBEdge* to2) {
00205     // check whether one of the links has a dead end
00206     if (to1==0||to2==0) {
00207         return;
00208     }
00209     // get the indices of both links
00210     int idx1 = getIndex(from1, to1);
00211     int idx2 = getIndex(from2, to2);
00212     if (idx1<0||idx2<0) {
00213         return; // !!! error output? did not happend, yet
00214     }
00215     // check whether the link crossing has already been checked
00216     assert((size_t) idx1<myIncoming.size()*myOutgoing.size());
00217     if (myDone[idx1][idx2]) {
00218         return;
00219     }
00220     // mark the crossings as done
00221     myDone[idx1][idx2] = true;
00222     myDone[idx2][idx1] = true;
00223     // check if one of the links is a turn; this link is always not priorised
00224     //  true for right-before-left and priority
00225     if (from1->isTurningDirectionAt(myJunction, to1)) {
00226         myForbids[idx2][idx1] = true;
00227         return;
00228     }
00229     if (from2->isTurningDirectionAt(myJunction, to2)) {
00230         myForbids[idx1][idx2] = true;
00231         return;
00232     }
00233 
00234     // check the priorities
00235     int from1p = from1->getJunctionPriority(myJunction);
00236     int from2p = from2->getJunctionPriority(myJunction);
00237     // check if one of the connections is higher priorised when incoming into
00238     //  the junction, the connection road will yield
00239     // should be valid for priority junctions only
00240     if (from1p>from2p) {
00241         assert(myJunction->getType()!=NODETYPE_RIGHT_BEFORE_LEFT);
00242         myForbids[idx1][idx2] = true;
00243         return;
00244     }
00245     if (from2p>from1p) {
00246         assert(myJunction->getType()!=NODETYPE_RIGHT_BEFORE_LEFT);
00247         myForbids[idx2][idx1] = true;
00248         return;
00249     }
00250 
00251     // check whether one of the connections is higher priorised on
00252     //  the outgoing edge when both roads are high priorised
00253     //  the connection with the lower priorised outgoing edge will lead
00254     // should be valid for priority junctions only
00255     if (from1p>0&&from2p>0) {
00256         assert(myJunction->getType()!=NODETYPE_RIGHT_BEFORE_LEFT);
00257         int to1p = to1->getJunctionPriority(myJunction);
00258         int to2p = to2->getJunctionPriority(myJunction);
00259         if (to1p>to2p) {
00260             myForbids[idx1][idx2] = true;
00261             return;
00262         }
00263         if (to2p>to1p) {
00264             myForbids[idx2][idx1] = true;
00265             return;
00266         }
00267     }
00268 
00269     // compute the yielding due to the right-before-left rule
00270     // get the position of the incoming lanes in the junction-wheel
00271     EdgeVector::const_iterator c1 = find(myAll.begin(), myAll.end(), from1);
00272     NBContHelper::nextCW(myAll, c1);
00273     // go through next edges clockwise...
00274     while (*c1!=from1&&*c1!=from2) {
00275         if (*c1==to2) {
00276             // if we encounter to2 the second one prohibits the first
00277             if (!leftHanded) {
00278                 myForbids[idx2][idx1] = true;
00279             } else {
00280                 myForbids[idx1][idx2] = true;
00281             }
00282             return;
00283         }
00284         NBContHelper::nextCW(myAll, c1);
00285     }
00286     // get the position of the incoming lanes in the junction-wheel
00287     EdgeVector::const_iterator c2 = find(myAll.begin(), myAll.end(), from2);
00288     NBContHelper::nextCW(myAll, c2);
00289     // go through next edges clockwise...
00290     while (*c2!=from2&&*c2!=from1) {
00291         if (*c2==to1) {
00292             // if we encounter to1 the second one prohibits the first
00293             if (!leftHanded) {
00294                 myForbids[idx1][idx2] = true;
00295             } else {
00296                 myForbids[idx2][idx1] = true;
00297             }
00298             return;
00299         }
00300         NBContHelper::nextCW(myAll, c2);
00301     }
00302 }
00303 
00304 
00305 size_t
00306 NBRequest::distanceCounterClockwise(NBEdge* from, NBEdge* to) {
00307     EdgeVector::const_iterator p = find(myAll.begin(), myAll.end(), from);
00308     size_t ret = 0;
00309     while (true) {
00310         ret++;
00311         if (p==myAll.begin()) {
00312             p = myAll.end();
00313         }
00314         p--;
00315         if ((*p)==to) {
00316             return ret;
00317         }
00318     }
00319 }
00320 
00321 
00322 void
00323 NBRequest::writeLogic(std::string key, OutputDevice& into) const {
00324     int pos = 0;
00325     EdgeVector::const_iterator i;
00326     for (i=myIncoming.begin(); i!=myIncoming.end(); i++) {
00327         unsigned int noLanes = (*i)->getNumLanes();
00328         for (unsigned int k=0; k<noLanes; k++) {
00329             pos = writeLaneResponse(into, *i, k, pos);
00330         }
00331     }
00332 }
00333 
00334 
00335 void
00336 NBRequest::resetSignalised() {
00337     // go through possible prohibitions
00338     for (EdgeVector::const_iterator i11=myIncoming.begin(); i11!=myIncoming.end(); i11++) {
00339         unsigned int noLanesEdge1 = (*i11)->getNumLanes();
00340         for (unsigned int j1=0; j1<noLanesEdge1; j1++) {
00341             std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
00342             for (std::vector<NBEdge::Connection>::iterator i12=el1.begin(); i12!=el1.end(); ++i12) {
00343                 int idx1 = getIndex((*i11), (*i12).toEdge);
00344                 if (idx1<0) {
00345                     continue;
00346                 }
00347                 // go through possibly prohibited
00348                 for (EdgeVector::const_iterator i21=myIncoming.begin(); i21!=myIncoming.end(); i21++) {
00349                     unsigned int noLanesEdge2 = (*i21)->getNumLanes();
00350                     for (unsigned int j2=0; j2<noLanesEdge2; j2++) {
00351                         std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
00352                         for (std::vector<NBEdge::Connection>::iterator i22=el2.begin(); i22!=el2.end(); i22++) {
00353                             int idx2 = getIndex((*i21), (*i22).toEdge);
00354                             if (idx2<0) {
00355                                 continue;
00356                             }
00357                             // check
00358                             // same incoming connections do not prohibit each other
00359                             if ((*i11)==(*i21)) {
00360                                 myForbids[idx1][idx2] = false;
00361                                 myForbids[idx2][idx1] = false;
00362                                 continue;
00363                             }
00364                             // check other
00365                             // if both are non-signalised or both are signalised
00366                             if (((*i12).tlID==""&&(*i22).tlID=="")
00367                                     ||
00368                                     ((*i12).tlID!=""&&(*i22).tlID!="")) {
00369                                 // do nothing
00370                                 continue;
00371                             }
00372                             // supposing, we don not have to
00373                             //  brake if we are no foes
00374                             if (!foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
00375                                 continue;
00376                             }
00377                             // otherwise:
00378                             //  the non-signalised must break
00379                             if ((*i12).tlID!="") {
00380                                 myForbids[idx1][idx2] = true;
00381                                 myForbids[idx2][idx1] = false;
00382                             } else {
00383                                 myForbids[idx1][idx2] = false;
00384                                 myForbids[idx2][idx1] = true;
00385                             }
00386                         }
00387                     }
00388                 }
00389             }
00390         }
00391     }
00392 }
00393 
00394 
00395 std::pair<unsigned int, unsigned int>
00396 NBRequest::getSizes() const {
00397     unsigned int noLanes = 0;
00398     unsigned int noLinks = 0;
00399     for (EdgeVector::const_iterator i=myIncoming.begin();
00400             i!=myIncoming.end(); i++) {
00401         unsigned int noLanesEdge = (*i)->getNumLanes();
00402         for (unsigned int j=0; j<noLanesEdge; j++) {
00403             unsigned int numConnections = (unsigned int)(*i)->getConnectionsFromLane(j).size();
00404             noLinks += numConnections;
00405             if (numConnections > 0) {
00406                 noLanes++;
00407             }
00408         }
00409     }
00410     return std::make_pair(noLanes, noLinks);
00411 }
00412 
00413 
00414 bool
00415 NBRequest::foes(const NBEdge* const from1, const NBEdge* const to1,
00416                 const NBEdge* const from2, const NBEdge* const to2) const throw() {
00417     // unconnected edges do not forbid other edges
00418     if (to1==0 || to2==0) {
00419         return false;
00420     }
00421     // get the indices
00422     int idx1 = getIndex(from1, to1);
00423     int idx2 = getIndex(from2, to2);
00424     if (idx1<0||idx2<0) {
00425         return false; // sure? (The connection does not exist within this junction)
00426     }
00427     assert((size_t) idx1<myIncoming.size()*myOutgoing.size());
00428     assert((size_t) idx2<myIncoming.size()*myOutgoing.size());
00429     return myForbids[idx1][idx2] || myForbids[idx2][idx1];
00430 }
00431 
00432 
00433 bool
00434 NBRequest::forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
00435                    const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
00436                    bool regardNonSignalisedLowerPriority) const throw() {
00437     // unconnected edges do not forbid other edges
00438     if (possProhibitorTo==0 || possProhibitedTo==0) {
00439         return false;
00440     }
00441     // get the indices
00442     int possProhibitorIdx = getIndex(possProhibitorFrom, possProhibitorTo);
00443     int possProhibitedIdx = getIndex(possProhibitedFrom, possProhibitedTo);
00444     if (possProhibitorIdx<0||possProhibitedIdx<0) {
00445         return false; // sure? (The connection does not exist within this junction)
00446     }
00447     assert((size_t) possProhibitorIdx<myIncoming.size()*myOutgoing.size());
00448     assert((size_t) possProhibitedIdx<myIncoming.size()*myOutgoing.size());
00449     // check simple right-of-way-rules
00450     if (!regardNonSignalisedLowerPriority) {
00451         return myForbids[possProhibitorIdx][possProhibitedIdx];
00452     }
00453     // if its not forbidden, report
00454     if (!myForbids[possProhibitorIdx][possProhibitedIdx]) {
00455         return false;
00456     }
00457     // do not forbid a signalised stream by a non-signalised
00458     if (!possProhibitorFrom->hasSignalisedConnectionTo(possProhibitorTo)) {
00459         return false;
00460     }
00461     return true;
00462 }
00463 
00464 
00465 int
00466 NBRequest::writeLaneResponse(OutputDevice& od, NBEdge* from,
00467                              int fromLane, int pos) const {
00468     std::vector<NBEdge::Connection> connected = from->getConnectionsFromLane(fromLane);
00469     for (std::vector<NBEdge::Connection>::iterator j=connected.begin(); j!=connected.end(); j++) {
00470         od.openTag(SUMO_TAG_REQUEST);
00471         od.writeAttr(SUMO_ATTR_INDEX, pos++);
00472         od << " " << toString(SUMO_ATTR_RESPONSE) << "=\"";
00473         writeResponse(od, from, (*j).toEdge, fromLane, (*j).toLane, (*j).mayDefinitelyPass);
00474         od << "\" " << toString(SUMO_ATTR_FOES) << "=\"";
00475         writeAreFoes(od, from, (*j).toEdge, (*j).haveVia);
00476         od << "\"";
00477         if (!OptionsCont::getOptions().getBool("no-internal-links")) {
00478             if ((*j).haveVia) {
00479                 od.writeAttr(SUMO_ATTR_CONT, 1);
00480             } else {
00481                 od.writeAttr(SUMO_ATTR_CONT, 0);
00482             }
00483         }
00484         od.closeTag(true);
00485     }
00486     return pos;
00487 }
00488 
00489 
00490 void
00491 NBRequest::writeResponse(OutputDevice& od, const NBEdge* const from, const NBEdge* const to,
00492                          int fromLane, int toLane, bool mayDefinitelyPass) const throw(IOError) {
00493     UNUSED_PARAMETER(toLane);
00494     int idx = 0;
00495     if (to!=0) {
00496         idx = getIndex(from, to);
00497     }
00498     for (EdgeVector::const_reverse_iterator i=myIncoming.rbegin(); i!=myIncoming.rend(); i++) {
00499         //const std::vector<NBEdge::Connection> &allConnections = (*i)->getConnections();
00500         unsigned int noLanes = (*i)->getNumLanes();
00501         for (int j=noLanes; j-->0;) {
00502             std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
00503             int size = (int) connected.size();
00504             for (int k=size; k-->0;) {
00505                 if (mayDefinitelyPass) {
00506                     od << '0';
00507                 } else if (to==0) {
00508                     // should wait if no further connection!?
00509                     od << '1';
00510                 } else if ((*i)==from&&fromLane==j) {
00511                     // do not prohibit a connection by others from same lane
00512                     od << '0';
00513                 } else {
00514                     assert(k<(int) connected.size());
00515                     assert((size_t) idx<myIncoming.size()*myOutgoing.size());
00516                     assert(connected[k].toEdge==0 || (size_t) getIndex(*i, connected[k].toEdge)<myIncoming.size()*myOutgoing.size());
00517                     // check whether the connection is prohibited by another one
00518                     if (connected[k].toEdge!=0 && myForbids[getIndex(*i, connected[k].toEdge)][idx]) {
00519                         od << '1';
00520                         continue;
00521                     }
00522                     od << '0';
00523                 }
00524             }
00525         }
00526     }
00527 }
00528 
00529 
00530 void
00531 NBRequest::writeAreFoes(OutputDevice& od, NBEdge* from, NBEdge* to, bool isInnerEnd) const {
00532     // remember the case when the lane is a "dead end" in the meaning that
00533     // vehicles must choose another lane to move over the following
00534     // junction
00535     UNUSED_PARAMETER(isInnerEnd);
00536     int idx = 0;
00537     if (to!=0) {
00538         idx = getIndex(from, to);
00539     }
00540     // !!! move to forbidden
00541     for (EdgeVector::const_reverse_iterator i=myIncoming.rbegin();
00542             i!=myIncoming.rend(); i++) {
00543 
00544         unsigned int noLanes = (*i)->getNumLanes();
00545         for (unsigned int j=noLanes; j-->0;) {
00546             std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
00547             int size = (int) connected.size();
00548             for (int k=size; k-->0;) {
00549                 if (to==0) {
00550                     od << '0';
00551                 } else {
00552 //                    if (foes(from, to, (*i), connected[k].edge) && !isInnerEnd) {
00553                     if (foes(from, to, (*i), connected[k].toEdge)) {
00554                         od << '1';
00555                     } else {
00556                         od << '0';
00557                     }
00558                 }
00559             }
00560         }
00561     }
00562 }
00563 
00564 
00565 int
00566 NBRequest::getIndex(const NBEdge* const from, const NBEdge* const to) const throw() {
00567     EdgeVector::const_iterator fp = find(myIncoming.begin(), myIncoming.end(), from);
00568     EdgeVector::const_iterator tp = find(myOutgoing.begin(), myOutgoing.end(), to);
00569     if (fp==myIncoming.end()||tp==myOutgoing.end()) {
00570         return -1;
00571     }
00572     // compute the index
00573     return (int)(distance(myIncoming.begin(), fp) * myOutgoing.size() + distance(myOutgoing.begin(), tp));
00574 }
00575 
00576 
00577 std::ostream&
00578 operator<<(std::ostream& os, const NBRequest& r) {
00579     size_t variations = r.myIncoming.size() * r.myOutgoing.size();
00580     for (size_t i=0; i<variations; i++) {
00581         os << i << ' ';
00582         for (size_t j=0; j<variations; j++) {
00583             if (r.myForbids[i][j]) {
00584                 os << '1';
00585             } else {
00586                 os << '0';
00587             }
00588         }
00589         os << std::endl;
00590     }
00591     os << std::endl;
00592     return os;
00593 }
00594 
00595 
00596 bool
00597 NBRequest::mustBrake(const NBEdge* const from, const NBEdge* const to) const throw() {
00598     // vehicles which do not have a following lane must always decelerate to the end
00599     if (to==0) {
00600         return true;
00601     }
00602     // get the indices
00603     int idx2 = getIndex(from, to);
00604     if (idx2==-1) {
00605         return false;
00606     }
00607     // go through all (existing) connections;
00608     //  check whether any of these forbids the one to determine
00609     assert((size_t) idx2<myIncoming.size()*myOutgoing.size());
00610     for (size_t idx1=0; idx1<myIncoming.size()*myOutgoing.size(); idx1++) {
00611         //assert(myDone[idx1][idx2]);
00612         if (myDone[idx1][idx2]&&myForbids[idx1][idx2]) {
00613             return true;
00614         }
00615     }
00616     return false;
00617 }
00618 
00619 
00620 bool
00621 NBRequest::mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
00622                      const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const throw() {
00623     // get the indices
00624     int idx1 = getIndex(possProhibitorFrom, possProhibitorTo);
00625     int idx2 = getIndex(possProhibitedFrom, possProhibitedTo);
00626     return (myForbids[idx2][idx1]);
00627 }
00628 
00629 
00630 void
00631 NBRequest::reportWarnings() {
00632     // check if any errors occured on build the link prohibitions
00633     if (myNotBuild!=0) {
00634         WRITE_WARNING(toString(myNotBuild) + " of " + toString(myNotBuild+myGoodBuilds)+ " prohibitions were not build.");
00635     }
00636 }
00637 
00638 
00639 
00640 /****************************************************************************/
00641 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines