SUMO - Simulation of Urban MObility
MSRightOfWayJunction.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // junction.
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include "MSRightOfWayJunction.h"
00034 #include "MSLane.h"
00035 #include "MSJunctionLogic.h"
00036 #include "MSBitSetLogic.h"
00037 #include "MSGlobals.h"
00038 #include "MSInternalLane.h"
00039 #include <algorithm>
00040 #include <cassert>
00041 #include <cmath>
00042 #include <utils/common/RandHelper.h>
00043 
00044 #ifdef CHECK_MEMORY_LEAKS
00045 #include <foreign/nvwa/debug_new.h>
00046 #endif // CHECK_MEMORY_LEAKS
00047 
00048 
00049 // ===========================================================================
00050 // method definitions
00051 // ===========================================================================
00052 MSRightOfWayJunction::MSRightOfWayJunction(const std::string& id,
00053         const Position& position,
00054         const PositionVector& shape,
00055         std::vector<MSLane*> incoming,
00056 #ifdef HAVE_INTERNAL_LANES
00057         std::vector<MSLane*> internal,
00058 #endif
00059         MSJunctionLogic* logic)
00060     : MSLogicJunction(id, position, shape, incoming
00061 #ifdef HAVE_INTERNAL_LANES
00062                       , internal),
00063 #else
00064                      ),
00065 #endif
00066     myLogic(logic) {}
00067 
00068 
00069 MSRightOfWayJunction::~MSRightOfWayJunction() {
00070     delete myLogic;
00071 }
00072 
00073 
00074 void
00075 MSRightOfWayJunction::postloadInit() {
00076     // inform links where they have to report approaching vehicles to
00077     unsigned int requestPos = 0;
00078     std::vector<MSLane*>::iterator i;
00079     // going through the incoming lanes...
00080     unsigned int maxNo = 0;
00081     std::vector<std::pair<MSLane*, MSLink*> > sortedLinks;
00082     for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
00083         const MSLinkCont& links = (*i)->getLinkCont();
00084         // ... set information for every link
00085         for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
00086             if (myLogic->getLogicSize() <= requestPos) {
00087                 throw ProcessError("Found invalid logic position of a link (network error)");
00088             }
00089             sortedLinks.push_back(std::make_pair(*i, *j));
00090             ++maxNo;
00091         }
00092     }
00093 
00094     bool isCrossing = myLogic->isCrossing();
00095     for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
00096         const MSLinkCont& links = (*i)->getLinkCont();
00097         // ... set information for every link
00098         for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
00099             if (myLogic->getLogicSize() <= requestPos) {
00100                 throw ProcessError("Found invalid logic position of a link (network error)");
00101             }
00102             const MSLogicJunction::LinkFoes& foeLinks = myLogic->getFoesFor(requestPos);
00103             const std::bitset<64> &internalFoes = myLogic->getInternalFoesFor(requestPos);
00104             bool cont = myLogic->getIsCont(requestPos);
00105             myLinkFoeLinks[*j] = std::vector<MSLink*>();
00106             for (unsigned int c = 0; c < maxNo; ++c) {
00107                 if (foeLinks.test(c)) {
00108                     myLinkFoeLinks[*j].push_back(sortedLinks[c].second);
00109                 }
00110             }
00111             std::vector<MSLink*> foes;
00112             for (unsigned int c = 0; c < maxNo; ++c) {
00113                 if (internalFoes.test(c)) {
00114                     MSLink* foe = sortedLinks[c].second;
00115                     foes.push_back(foe);
00116 #ifdef HAVE_INTERNAL_LANES
00117                     MSLane* l = foe->getViaLane();
00118                     if (l == 0) {
00119                         continue;
00120                     }
00121                     const MSLinkCont& lc = l->getLinkCont();
00122                     for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
00123                         if ((*q)->getViaLane() != 0) {
00124                             foes.push_back(*q);
00125                         }
00126                     }
00127 #endif
00128                 }
00129             }
00130 
00131             myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
00132 #ifdef HAVE_INTERNAL_LANES
00133             if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
00134                 int li = 0;
00135                 for (unsigned int c = 0; c < sortedLinks.size(); ++c) {
00136                     if (sortedLinks[c].second->getLane() == 0) { // dead end
00137                         continue;
00138                     }
00139                     if (internalFoes.test(c)) {
00140                         myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
00141                         if(foeLinks.test(c)) {
00142                             const std::vector<MSLane::IncomingLaneInfo> &l = myInternalLanes[li]->getIncomingLanes();
00143                             if(l.size()==1&&l[0].lane->getEdge().getPurpose()==MSEdge::EDGEFUNCTION_INTERNAL) {
00144                                 myLinkFoeInternalLanes[*j].push_back(l[0].lane);
00145                             }
00146                         }
00147                     }
00148                     ++li;
00149                 }
00150             }
00151 #endif
00152             (*j)->setRequestInformation(requestPos, requestPos, isCrossing, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
00153             for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
00154                 (*j)->addBlockedLink(*k);
00155                 (*k)->addBlockedLink(*j);
00156             }
00157             requestPos++;
00158         }
00159     }
00160 #ifdef HAVE_INTERNAL_LANES
00161     // set information for the internal lanes
00162     requestPos = 0;
00163     for (i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
00164         // ... set information about participation
00165         static_cast<MSInternalLane*>(*i)->setParentJunctionInformation(&myInnerState, requestPos++);
00166     }
00167 #endif
00168 }
00169 
00170 
00171 /****************************************************************************/
00172 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines