46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
55 const std::vector<NBNode*>& junctions,
SUMOTime offset)
96 for (
unsigned int e1l = 0; e1l < e1->
getNumLanes(); e1l++) {
98 for (
unsigned int e2l = 0; e2l < e2->
getNumLanes(); e2l++) {
100 for (std::vector<NBEdge::Connection>::iterator e1c = approached1.begin(); e1c != approached1.end(); ++e1c) {
104 for (std::vector<NBEdge::Connection>::iterator e2c = approached2.begin(); e2c != approached2.end(); ++e2c) {
108 if (!
foes(e1, (*e1c).toEdge, e2, (*e2c).toEdge)) {
120 std::pair<NBEdge*, NBEdge*>
122 std::pair<NBEdge*, NBEdge*> bestPair(static_cast<NBEdge*>(0), static_cast<NBEdge*>(0));
124 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
125 for (EdgeVector::const_iterator j = i + 1; j != edges.end(); ++j) {
127 if (value > bestValue) {
129 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
130 }
else if (value == bestValue) {
134 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
143 std::pair<NBEdge*, NBEdge*>
145 if (incoming.size() == 1) {
147 std::pair<NBEdge*, NBEdge*> ret(*incoming.begin(),
static_cast<NBEdge*
>(0));
155 used.push_back(*incoming.begin());
158 for (EdgeVector::iterator i = incoming.begin() + 1; i != incoming.end() && prio !=
getToPrio(*i); ++i) {
162 if (used.size() < 2) {
166 incoming.erase(find(incoming.begin(), incoming.end(), ret.first));
167 incoming.erase(find(incoming.begin(), incoming.end(), ret.second));
174 unsigned int brakingTimeSeconds) {
179 std::vector<bool> isLeftMoverV, isTurnaround;
180 unsigned int noLanesAll = 0;
181 unsigned int noLinksAll = 0;
182 for (
unsigned int i1 = 0; i1 < incoming.size(); i1++) {
183 unsigned int noLanes = incoming[i1]->getNumLanes();
184 noLanesAll += noLanes;
185 for (
unsigned int i2 = 0; i2 < noLanes; i2++) {
186 NBEdge* fromEdge = incoming[i1];
188 noLinksAll += (
unsigned int) approached.size();
189 for (
unsigned int i3 = 0; i3 < approached.size(); i3++) {
190 if (!fromEdge->
mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
194 assert(i3 < approached.size());
195 NBEdge* toEdge = approached[i3].toEdge;
196 fromEdges.push_back(fromEdge);
198 toEdges.push_back(toEdge);
200 isLeftMoverV.push_back(
205 isTurnaround.push_back(
209 isLeftMoverV.push_back(
true);
210 isTurnaround.push_back(
true);
219 while (toProc.size() > 0) {
220 std::pair<NBEdge*, NBEdge*> chosen;
221 if (incoming.size() == 2) {
222 chosen = std::pair<NBEdge*, NBEdge*>(toProc[0],
static_cast<NBEdge*
>(0));
223 toProc.erase(toProc.begin());
227 unsigned int pos = 0;
229 std::string state((
size_t) noLinksAll,
'o');
231 for (
unsigned int i1 = 0; i1 < (
unsigned int) incoming.size(); ++i1) {
232 NBEdge* fromEdge = incoming[i1];
233 bool inChosen = fromEdge == chosen.first || fromEdge == chosen.second;
235 for (
unsigned int i2 = 0; i2 < noLanes; i2++) {
237 for (
unsigned int i3 = 0; i3 < approached.size(); ++i3) {
238 if (!fromEdge->
mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
251 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
252 if (state[i1] ==
'G') {
255 bool isForbidden =
false;
256 for (
unsigned int i2 = 0; i2 < pos && !isForbidden; ++i2) {
257 if (state[i2] ==
'G' && !isTurnaround[i2] &&
258 (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true) ||
forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2],
true))) {
267 bool haveForbiddenLeftMover =
false;
268 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
269 if (state[i1] !=
'G') {
272 for (
unsigned int i2 = 0; i2 < pos; ++i2) {
273 if ((state[i2] ==
'G' || state[i2] ==
'g') &&
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true)) {
275 if (!isTurnaround[i1]) {
276 haveForbiddenLeftMover =
true;
283 logic->
addStep(duration, state);
285 if (brakingTime > 0) {
287 duration = brakingTime;
288 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
289 if (state[i1] !=
'G' && state[i1] !=
'g') {
292 if ((state[i1] >=
'a' && state[i1] <=
'z') && haveForbiddenLeftMover) {
298 logic->
addStep(duration, state);
301 if (haveForbiddenLeftMover) {
304 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
305 if (state[i1] ==
'Y' || state[i1] ==
'y') {
309 if (state[i1] ==
'g') {
314 logic->
addStep(duration, state);
317 if (brakingTime > 0) {
318 duration = brakingTime;
319 for (
unsigned int i1 = 0; i1 < pos; ++i1) {
320 if (state[i1] !=
'G' && state[i1] !=
'g') {
326 logic->
addStep(duration, state);
351 for (
unsigned int j = 0; j < noLanes; j++) {
353 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {