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