MSInternalJunction.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include "MSInternalJunction.h"
00031 #include "MSLane.h"
00032 #include "MSJunctionLogic.h"
00033 #include "MSBitSetLogic.h"
00034 #include <algorithm>
00035 #include <cassert>
00036 #include <cmath>
00037
00038 #ifdef CHECK_MEMORY_LEAKS
00039 #include <foreign/nvwa/debug_new.h>
00040 #endif // CHECK_MEMORY_LEAKS
00041
00042
00043
00044
00045
00046 #ifdef HAVE_INTERNAL_LANES
00047 MSInternalJunction::MSInternalJunction(const std::string &id,
00048 const Position2D &position,
00049 const Position2DVector &shape,
00050 std::vector<MSLane*> incoming,
00051 std::vector<MSLane*> internal) throw()
00052 : MSLogicJunction(id, position, shape, incoming, internal) {}
00053
00054
00055 bool
00056 MSInternalJunction::clearRequests() {
00057 return true;
00058 }
00059
00060
00061 MSInternalJunction::~MSInternalJunction() {}
00062
00063
00064 void
00065 MSInternalJunction::postloadInit() throw(ProcessError) {
00066
00067 unsigned int requestPos = 0;
00068 myInternalLaneFoes = myInternalLanes;
00069 for (std::vector<MSLane*>::const_iterator i=myIncomingLanes.begin()+1; i!=myIncomingLanes.end(); ++i) {
00070 MSLane *l = *i;
00071 const MSLinkCont &lc = l->getLinkCont();
00072 for (MSLinkCont::const_iterator j=lc.begin(); j!=lc.end(); ++j) {
00073 myInternalLinkFoes.push_back(*j);
00074 }
00075 }
00076 if (myIncomingLanes.size()!=0) {
00077
00078 const MSLinkCont &links = myIncomingLanes[0]->getLinkCont();
00079
00080 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) {
00081 (*j)->setRequestInformation(&myRequest, requestPos,
00082 &myRespond, requestPos,
00083 MSLogicJunction::LinkFoes(), true, false,
00084 myInternalLinkFoes, myInternalLaneFoes);
00085 requestPos++;
00086 }
00087 }
00088 }
00089
00090
00091 bool
00092 MSInternalJunction::setAllowed() {
00093
00094 myRespond.set(0, true);
00095 std::vector<MSLane*>::iterator i;
00096 if (myIncomingLanes.size()==0) {
00097 return true;
00098 }
00099
00100
00101 if (!myRequest.test(0)) {
00102 return true;
00103 }
00104
00105
00106 for (i=myInternalLanes.begin(); i!=myInternalLanes.end(); ++i) {
00107 if (!(*i)->empty()) {
00108 myRespond.set(0, false);
00109 return true;
00110 }
00111 }
00112
00113
00114
00115 for (i=myIncomingLanes.begin()+1; i!=myIncomingLanes.end(); ++i) {
00116 MSLane *l = *i;
00117 const MSVehicle * const foe = l->getFirstVehicle();
00118 const MSLinkCont &lc = l->getLinkCont();
00119 for (MSLinkCont::const_iterator j=lc.begin(); j!=lc.end(); ++j) {
00120 if (find(myInternalLanes.begin(), myInternalLanes.end(), (*j)->getViaLane())!=myInternalLanes.end()) {
00121 bool approached = foe!=0&&(*j)->getApproaching()==foe;
00122 approached |= ((*j)->getViaLane()!=0&&!(*j)->getViaLane()->empty());
00123 if (approached&&((*j)->opened(0, 0)||(*j)->havePriority())) {
00124 myRespond.set(0, false);
00125 return true;
00126 }
00127 }
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 return true;
00150 }
00151
00152
00153 #endif
00154
00155
00156
00157