46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
55 const std::vector<NBNode*>& junctions,
SUMOTime offset,
99 for (
unsigned int e1l = 0; e1l < e1->
getNumLanes(); e1l++) {
101 for (
unsigned int e2l = 0; e2l < e2->
getNumLanes(); e2l++) {
103 for (std::vector<NBEdge::Connection>::iterator e1c = approached1.begin(); e1c != approached1.end(); ++e1c) {
107 for (std::vector<NBEdge::Connection>::iterator e2c = approached2.begin(); e2c != approached2.end(); ++e2c) {
111 if (!
foes(e1, (*e1c).toEdge, e2, (*e2c).toEdge)) {
123 std::pair<NBEdge*, NBEdge*>
125 std::pair<NBEdge*, NBEdge*> bestPair(static_cast<NBEdge*>(0), static_cast<NBEdge*>(0));
127 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
128 for (EdgeVector::const_iterator j = i + 1; j != edges.end(); ++j) {
130 if (value > bestValue) {
132 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
133 }
else if (value == bestValue) {
135 const SUMOReal oa =
GeomHelper::getMinAngleDiff(bestPair.first->getAngleAtNode(bestPair.first->getToNode()), bestPair.second->getAngleAtNode(bestPair.second->getToNode()));
137 if (bestPair.first->getID() < (*i)->getID()) {
138 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
140 }
else if (oa < ca) {
141 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
150 std::pair<NBEdge*, NBEdge*>
152 if (incoming.size() == 1) {
154 std::pair<NBEdge*, NBEdge*> ret(*incoming.begin(),
static_cast<NBEdge*
>(0));
162 used.push_back(*incoming.begin());
165 for (EdgeVector::iterator i = incoming.begin() + 1; i != incoming.end() && prio !=
getToPrio(*i); ++i) {
169 if (used.size() < 2) {
173 incoming.erase(find(incoming.begin(), incoming.end(), ret.first));
174 incoming.erase(find(incoming.begin(), incoming.end(), ret.second));
181 unsigned int brakingTimeSeconds) {
187 std::vector<bool> isLeftMoverV, isTurnaround;
188 unsigned int noLanesAll = 0;
189 unsigned int noLinksAll = 0;
190 for (
unsigned int i1 = 0; i1 < incoming.size(); i1++) {
191 unsigned int noLanes = incoming[i1]->getNumLanes();
192 noLanesAll += noLanes;
193 for (
unsigned int i2 = 0; i2 < noLanes; i2++) {
194 NBEdge* fromEdge = incoming[i1];
196 noLinksAll += (
unsigned int) approached.size();
197 for (
unsigned int i3 = 0; i3 < approached.size(); i3++) {
198 if (!fromEdge->
mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
202 assert(i3 < approached.size());
203 NBEdge* toEdge = approached[i3].toEdge;
204 fromEdges.push_back(fromEdge);
206 toEdges.push_back(toEdge);
208 isLeftMoverV.push_back(
213 isTurnaround.push_back(
217 isLeftMoverV.push_back(
true);
218 isTurnaround.push_back(
true);
228 while (toProc.size() > 0) {
229 std::pair<NBEdge*, NBEdge*> chosen;
230 if (incoming.size() == 2) {
231 chosen = std::pair<NBEdge*, NBEdge*>(toProc[0],
static_cast<NBEdge*
>(0));
232 toProc.erase(toProc.begin());
236 unsigned int pos = 0;
237 std::string state((
size_t) noLinksAll,
'o');
239 for (
unsigned int i1 = 0; i1 < (
unsigned int) incoming.size(); ++i1) {
240 NBEdge* fromEdge = incoming[i1];
241 const bool inChosen = fromEdge == chosen.first || fromEdge == chosen.second;
242 const unsigned int numLanes = fromEdge->
getNumLanes();
243 for (
unsigned int i2 = 0; i2 < numLanes; i2++) {
245 for (
unsigned int i3 = 0; i3 < approached.size(); ++i3) {
246 if (!fromEdge->
mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
259 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
260 if (state[i1] ==
'G') {
263 bool isForbidden =
false;
264 for (
unsigned int i2 = 0; i2 < pos && !isForbidden; ++i2) {
265 if (state[i2] ==
'G' && !isTurnaround[i2] &&
266 (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true) ||
forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2],
true))) {
275 bool haveForbiddenLeftMover =
false;
276 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
277 if (state[i1] !=
'G') {
280 for (
unsigned int i2 = 0; i2 < pos; ++i2) {
281 if ((state[i2] ==
'G' || state[i2] ==
'g') &&
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true)) {
283 if (!isTurnaround[i1]) {
284 haveForbiddenLeftMover =
true;
290 logic->
addStep(greenTime, state);
292 if (brakingTime > 0) {
294 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
295 if (state[i1] !=
'G' && state[i1] !=
'g') {
298 if ((state[i1] >=
'a' && state[i1] <=
'z') && haveForbiddenLeftMover) {
304 logic->
addStep(brakingTime, state);
307 if (haveForbiddenLeftMover) {
309 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
310 if (state[i1] ==
'Y' || state[i1] ==
'y') {
314 if (state[i1] ==
'g') {
319 logic->
addStep(leftTurnTime, state);
322 if (brakingTime > 0) {
323 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
324 if (state[i1] !=
'G' && state[i1] !=
'g') {
330 logic->
addStep(brakingTime, state);
335 if (totalDuration > 0) {
336 if (totalDuration > 3 * (greenTime + 2 * brakingTime + leftTurnTime)) {