|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // 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 "MSRightOfWayJunction.h" 00031 #include "MSLane.h" 00032 #include "MSJunctionLogic.h" 00033 #include "MSBitSetLogic.h" 00034 #include "MSGlobals.h" 00035 #include "MSInternalLane.h" 00036 #include <algorithm> 00037 #include <cassert> 00038 #include <cmath> 00039 #include <utils/common/RandHelper.h> 00040 00041 #ifdef CHECK_MEMORY_LEAKS 00042 #include <foreign/nvwa/debug_new.h> 00043 #endif // CHECK_MEMORY_LEAKS 00044 00045 00046 // =========================================================================== 00047 // method definitions 00048 // =========================================================================== 00049 MSRightOfWayJunction::MSRightOfWayJunction(const std::string& id, 00050 const Position& position, 00051 const PositionVector& shape, 00052 std::vector<MSLane*> incoming, 00053 #ifdef HAVE_INTERNAL_LANES 00054 std::vector<MSLane*> internal, 00055 #endif 00056 MSJunctionLogic* logic) throw() 00057 : MSLogicJunction(id, position, shape, incoming 00058 #ifdef HAVE_INTERNAL_LANES 00059 , internal), 00060 #else 00061 ), 00062 #endif 00063 myLogic(logic) {} 00064 00065 00066 MSRightOfWayJunction::~MSRightOfWayJunction() { 00067 delete myLogic; 00068 } 00069 00070 00071 void 00072 MSRightOfWayJunction::postloadInit() throw(ProcessError) { 00073 // inform links where they have to report approaching vehicles to 00074 unsigned int requestPos = 0; 00075 std::vector<MSLane*>::iterator i; 00076 // going through the incoming lanes... 00077 unsigned int maxNo = 0; 00078 std::vector<std::pair<MSLane*, MSLink*> > sortedLinks; 00079 for (i=myIncomingLanes.begin(); i!=myIncomingLanes.end(); ++i) { 00080 const MSLinkCont& links = (*i)->getLinkCont(); 00081 // ... set information for every link 00082 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) { 00083 if (myLogic->getLogicSize()<=requestPos) { 00084 throw ProcessError("Found invalid logic position of a link (network error)"); 00085 } 00086 sortedLinks.push_back(std::make_pair(*i, *j)); 00087 ++maxNo; 00088 } 00089 } 00090 00091 bool isCrossing = myLogic->isCrossing(); 00092 for (i=myIncomingLanes.begin(); i!=myIncomingLanes.end(); ++i) { 00093 const MSLinkCont& links = (*i)->getLinkCont(); 00094 // ... set information for every link 00095 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) { 00096 if (myLogic->getLogicSize()<=requestPos) { 00097 throw ProcessError("Found invalid logic position of a link (network error)"); 00098 } 00099 const MSLogicJunction::LinkFoes& foeLinks = myLogic->getFoesFor(requestPos); 00100 const std::bitset<64> &internalFoes = myLogic->getInternalFoesFor(requestPos); 00101 bool cont = myLogic->getIsCont(requestPos); 00102 myLinkFoeLinks[*j] = std::vector<MSLink*>(); 00103 for (unsigned int c=0; c<maxNo; ++c) { 00104 if (foeLinks.test(c)) { 00105 myLinkFoeLinks[*j].push_back(sortedLinks[c].second); 00106 } 00107 } 00108 std::vector<MSLink*> foes; 00109 for (unsigned int c=0; c<maxNo; ++c) { 00110 if (internalFoes.test(c)) { 00111 MSLink* foe = sortedLinks[c].second; 00112 foes.push_back(foe); 00113 #ifdef HAVE_INTERNAL_LANES 00114 MSLane* l = foe->getViaLane(); 00115 if (l==0) { 00116 continue; 00117 } 00118 const MSLinkCont& lc = l->getLinkCont(); 00119 for (MSLinkCont::const_iterator q=lc.begin(); q!=lc.end(); ++q) { 00120 if ((*q)->getViaLane()!=0) { 00121 foes.push_back(*q); 00122 } 00123 } 00124 #endif 00125 } 00126 } 00127 00128 myLinkFoeInternalLanes[*j] = std::vector<MSLane*>(); 00129 #ifdef HAVE_INTERNAL_LANES 00130 if (MSGlobals::gUsingInternalLanes&&myInternalLanes.size()>0) { 00131 int li = 0; 00132 for (unsigned int c=0; c<sortedLinks.size(); ++c) { 00133 if (sortedLinks[c].second->getLane()==0) { // dead end 00134 continue; 00135 } 00136 if (internalFoes.test(c)) { 00137 myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]); 00138 } 00139 ++li; 00140 } 00141 } 00142 #endif 00143 (*j)->setRequestInformation(requestPos, requestPos, isCrossing, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]); 00144 for (std::vector<MSLink*>::const_iterator k=foes.begin(); k!=foes.end(); ++k) { 00145 (*j)->addBlockedLink(*k); 00146 (*k)->addBlockedLink(*j); 00147 } 00148 requestPos++; 00149 } 00150 } 00151 #ifdef HAVE_INTERNAL_LANES 00152 // set information for the internal lanes 00153 requestPos = 0; 00154 for (i=myInternalLanes.begin(); i!=myInternalLanes.end(); ++i) { 00155 // ... set information about participation 00156 static_cast<MSInternalLane*>(*i)->setParentJunctionInformation(&myInnerState, requestPos++); 00157 } 00158 #endif 00159 } 00160 00161 00162 /****************************************************************************/ 00163