SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSLink.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A connnection between lanes
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <iostream>
34 #include <algorithm>
35 #include <limits>
37 #include "MSNet.h"
38 #include "MSLink.h"
39 #include "MSLane.h"
41 #include "MSEdge.h"
42 #include "MSGlobals.h"
43 #include "MSVehicle.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 //#define MSLink_DEBUG_CROSSING_POINTS
51 
52 // ===========================================================================
53 // static member variables
54 // ===========================================================================
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 #ifndef HAVE_INTERNAL_LANES
62 MSLink::MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length) :
63  myLane(succLane),
64  myIndex(-1),
65  myState(state),
66  myLastStateChange(-1),
67  myDirection(dir),
68  myLength(length),
69  myHasFoes(false),
70  myAmCont(false),
71  myJunction(0)
72 #else
73 MSLink::MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length) :
74  myLane(succLane),
75  myIndex(-1),
76  myState(state),
77  myLastStateChange(-1),
78  myDirection(dir),
79  myLength(length),
80  myHasFoes(false),
81  myAmCont(false),
82  myJunctionInlane(via),
83  myInternalLaneBefore(0),
84  myJunction(0)
85 #endif
86 {}
87 
88 
90 
91 
92 void
93 MSLink::setRequestInformation(int index, bool hasFoes, bool isCont,
94  const std::vector<MSLink*>& foeLinks,
95  const std::vector<MSLane*>& foeLanes,
96  MSLane* internalLaneBefore) {
97  myIndex = index;
99  myAmCont = isCont;
100  myFoeLinks = foeLinks;
101  for (std::vector<MSLane*>::const_iterator it_lane = foeLanes.begin(); it_lane != foeLanes.end(); ++it_lane) {
102  // cannot assign vector due to const-ness
103  myFoeLanes.push_back(*it_lane);
104  }
105  myJunction = myLane->getEdge().getFromJunction(); // junctionGraph is initialized after the whole network is loaded
106 #ifdef HAVE_INTERNAL_LANES
107  myInternalLaneBefore = internalLaneBefore;
108  MSLane* lane = 0;
109  if (internalLaneBefore != 0) {
110  // this is an exit link. compute crossing points with all foeLanes
111  lane = internalLaneBefore;
112  //} else if (myLane->getEdge().isCrossing()) {
113  // // this is the link to a pedestrian crossing. compute crossing points with all foeLanes
114  // // @note not currently used by pedestrians
115  // lane = myLane;
116  }
117 #ifdef MSLink_DEBUG_CROSSING_POINTS
118  std::cout << " link " << myIndex << " to " << getViaLaneOrLane()->getID() << " internalLane=" << (lane == 0 ? "NULL" : lane->getID()) << " has foes: " << toString(foeLanes) << "\n";
119 #endif
120  if (lane != 0) {
121  const bool beforeInternalJunction = lane->getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
122  assert(lane->getIncomingLanes().size() == 1);
123  // compute crossing points
124  for (std::vector<const MSLane*>::const_iterator it_lane = myFoeLanes.begin(); it_lane != myFoeLanes.end(); ++it_lane) {
125  const bool sameTarget = myLane == (*it_lane)->getLinkCont()[0]->getLane();
126  if (sameTarget && !beforeInternalJunction) {
127  //if (myLane == (*it_lane)->getLinkCont()[0]->getLane()) {
128  // this foeLane has the same target and merges at the end (lane exits the junction)
129  myLengthsBehindCrossing.push_back(std::make_pair(0, 0)); // dummy value, never used
130 #ifdef MSLink_DEBUG_CROSSING_POINTS
131  std::cout
132  << " " << lane->getID()
133  << " merges with " << (*it_lane)->getID()
134  << " nextLane " << lane->getLinkCont()[0]->getViaLaneOrLane()->getID()
135  << " dist1=" << myLengthsBehindCrossing.back().first
136  << " dist2=" << myLengthsBehindCrossing.back().second
137  << "\n";
138 #endif
139  } else {
140  std::vector<SUMOReal> intersections1 = lane->getShape().intersectsAtLengths2D((*it_lane)->getShape());
141 #ifdef MSLink_DEBUG_CROSSING_POINTS
142  //std::cout << " intersections1=" << toString(intersections1) << "\n";
143 #endif
144  bool haveIntersection = true;
145  if (intersections1.size() == 0) {
146  intersections1.push_back(-10000.0); // disregard this foe (using maxdouble leads to nasty problems down the line)
147  haveIntersection = false;
148  } else if (intersections1.size() > 1) {
149  std::sort(intersections1.begin(), intersections1.end());
150  }
151  std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->getShape());
152 #ifdef MSLink_DEBUG_CROSSING_POINTS
153  //std::cout << " intersections2=" << toString(intersections2) << "\n";
154 #endif
155  if (intersections2.size() == 0) {
156  intersections2.push_back(0);
157  } else if (intersections2.size() > 1) {
158  std::sort(intersections2.begin(), intersections2.end());
159  }
160  if (haveIntersection) {
161  // lane width affects the crossing point
162  intersections1.back() -= (*it_lane)->getWidth() / 2;
163  intersections2.back() -= lane->getWidth() / 2;
164  // also length/geometry factor
165  intersections1.back() = lane->interpolateGeometryPosToLanePos(intersections1.back());
166  intersections2.back() = (*it_lane)->interpolateGeometryPosToLanePos(intersections2.back());
167 
168  if (internalLaneBefore->getLogicalPredecessorLane()->getEdge().isInternal() && !(*it_lane)->getEdge().isCrossing()) {
169  // wait at the internal junction
170  // (except for foes that are crossings since there is no internal junction)
171  intersections1.back() = 0;
172  }
173  }
174 
175  myLengthsBehindCrossing.push_back(std::make_pair(
176  lane->getLength() - intersections1.back(),
177  (*it_lane)->getLength() - intersections2.back()));
178 
179 #ifdef MSLink_DEBUG_CROSSING_POINTS
180  std::cout
181  << " intersection of " << lane->getID()
182  << " totalLength=" << lane->getLength()
183  << " with " << (*it_lane)->getID()
184  << " totalLength=" << (*it_lane)->getLength()
185  << " dist1=" << myLengthsBehindCrossing.back().first
186  << " dist2=" << myLengthsBehindCrossing.back().second
187  << "\n";
188 #endif
189  }
190  }
191  // check for overlap with internal lanes from the same source lane
192  const MSLane* pred = lane->getLogicalPredecessorLane();
193  // to avoid overlap with vehicles that came from pred (especially when pred has endOffset > 0)
194  // we add all other internal lanes from pred as foeLanes
195  const MSLinkCont& predLinks = pred->getLinkCont();
196  for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
197  const MSLane* sibling = (*it)->getViaLane();
198  if (sibling != lane && sibling != 0) {
199  std::vector<SUMOReal> intersections1 = lane->getShape().intersectsAtLengths2D(sibling->getShape());
200 #ifdef MSLink_DEBUG_CROSSING_POINTS
201  //std::cout << " intersections1=" << toString(intersections1) << "\n";
202 #endif
203  if (intersections1.size() > 0) {
204  std::sort(intersections1.begin(), intersections1.end());
205  if (intersections1.back() > NUMERICAL_EPS) {
206  // siblings share a common shape up to the last crossing point so intersections are identical and only need to be computed once
207  myLengthsBehindCrossing.push_back(std::make_pair(
208  lane->getLength() - intersections1.back(),
209  sibling->getLength() - intersections1.back()));
210  myFoeLanes.push_back(sibling);
211 #ifdef MSLink_DEBUG_CROSSING_POINTS
212  std::cout << " adding same-origin foe" << sibling->getID()
213  << " dist1=" << myLengthsBehindCrossing.back().first
214  << " dist2=" << myLengthsBehindCrossing.back().second
215  << "\n";
216 #endif
217  }
218  }
219  }
220  }
221  }
222 #else
223  UNUSED_PARAMETER(internalLaneBefore);
224 #endif
225 }
226 
227 
228 std::pair<SUMOReal, SUMOReal>
229 getLastIntersections(const MSLane* lane, const MSLane* foe);
230 
231 void
232 MSLink::setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed,
233  const bool setRequest, const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking, const SUMOTime waitingTime) {
234  const SUMOTime leaveTime = getLeaveTime(arrivalTime, arrivalSpeed, leaveSpeed, approaching->getVehicleType().getLength());
235  myApproachingVehicles.insert(std::make_pair(approaching,
236  ApproachingVehicleInformation(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, setRequest,
237  arrivalTimeBraking, arrivalSpeedBraking, waitingTime)));
238 }
239 
240 
241 void
243  myBlockedFoeLinks.insert(link);
244 }
245 
246 
247 
248 bool
250  for (std::set<MSLink*>::const_iterator i = myBlockedFoeLinks.begin(); i != myBlockedFoeLinks.end(); ++i) {
251  if ((*i)->isBlockingAnyone()) {
252  return true;
253  }
254  }
255  return false;
256 }
257 
258 
259 void
261  myApproachingVehicles.erase(veh);
262 }
263 
264 
267  std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i = myApproachingVehicles.find(veh);
268  if (i != myApproachingVehicles.end()) {
269  return i->second;
270  } else {
271  return ApproachingVehicleInformation(-1000, -1000, 0, 0, false, -1000, 0, 0);
272  }
273 }
274 
275 
276 SUMOTime
277 MSLink::getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed,
278  const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const {
279  return arrivalTime + TIME2STEPS((getLength() + vehicleLength) / MAX2((SUMOReal)0.5 * (arrivalSpeed + leaveSpeed), NUMERICAL_EPS));
280 }
281 
282 
283 bool
284 MSLink::opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
285  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
286  std::vector<const SUMOVehicle*>* collectFoes) const {
287  if (haveRed()) {
288  return false;
289  }
291  return true;
292  }
293  if ((myState == LINKSTATE_STOP || myState == LINKSTATE_ALLWAY_STOP) && waitingTime == 0) {
294  return false;
295  }
296  const SUMOTime leaveTime = getLeaveTime(arrivalTime, arrivalSpeed, leaveSpeed, vehicleLength);
297  for (std::vector<MSLink*>::const_iterator i = myFoeLinks.begin(); i != myFoeLinks.end(); ++i) {
298 #ifdef HAVE_INTERNAL
300  if ((*i)->haveRed()) {
301  continue;
302  }
303  }
304 #endif
305  if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, myLane == (*i)->getLane(),
306  impatience, decel, waitingTime, collectFoes)) {
307  return false;
308  }
309  }
310  return true;
311 }
312 
313 
314 bool
315 MSLink::blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
316  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
317  std::vector<const SUMOVehicle*>* collectFoes) const {
318  for (std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i = myApproachingVehicles.begin(); i != myApproachingVehicles.end(); ++i) {
319  if (!i->second.willPass) {
320  continue;
321  }
323  assert(waitingTime > 0);
324  if (waitingTime > i->second.waitingTime) {
325  continue;
326  }
327  if (waitingTime == i->second.waitingTime && arrivalTime < i->second.arrivalTime) {
328  continue;
329  }
330  }
331  const SUMOTime foeArrivalTime = (SUMOTime)((1.0 - impatience) * i->second.arrivalTime + impatience * i->second.arrivalTimeBraking);
332  if (i->second.leavingTime < arrivalTime) {
333  // ego wants to be follower
334  if (sameTargetLane && (arrivalTime - i->second.leavingTime < myLookaheadTime
335  || unsafeMergeSpeeds(i->second.leaveSpeed, arrivalSpeed,
336  i->first->getVehicleType().getCarFollowModel().getMaxDecel(), decel))) {
337  if (collectFoes == 0) {
338  return true;
339  } else {
340  collectFoes->push_back(i->first);
341  }
342  }
343  } else if (foeArrivalTime > leaveTime) {
344  // ego wants to be leader.
345  if (sameTargetLane && (foeArrivalTime - leaveTime < myLookaheadTime
346  || unsafeMergeSpeeds(leaveSpeed, i->second.arrivalSpeedBraking,
347  decel, i->first->getVehicleType().getCarFollowModel().getMaxDecel()))) {
348  if (collectFoes == 0) {
349  return true;
350  } else {
351  collectFoes->push_back(i->first);
352  }
353  }
354  } else {
355  // even without considering safeHeadwayTime there is already a conflict
356  if (collectFoes == 0) {
357  return true;
358  } else {
359  collectFoes->push_back(i->first);
360  }
361  }
362  }
363  return false;
364 }
365 
366 
367 bool
369  MSVehicle* veh = lane->getLastVehicle();
370  SUMOReal distLeft = 0;
371  if (veh == 0) {
372  veh = lane->getPartialOccupator();
373  distLeft = lane->getLength() - lane->getPartialOccupatorEnd();
374  } else {
375  distLeft = lane->getLength() - veh->getPositionOnLane() + veh->getVehicleType().getLength();
376  }
377  if (veh == 0) {
378  return false;
379  } else {
380  assert(distLeft > 0);
381  // can we be sure that the vehicle leaves this lane in the next step?
382  bool result = distLeft > (veh->getSpeed() - veh->getCarFollowModel().getMaxDecel());
383  return result;
384  }
385 }
386 
387 
388 bool
389 MSLink::hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const {
390  for (std::vector<MSLink*>::const_iterator i = myFoeLinks.begin(); i != myFoeLinks.end(); ++i) {
391  if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed, myLane == (*i)->getLane(), 0, decel, 0)) {
392  return true;
393  }
394  }
395  for (std::vector<const MSLane*>::const_iterator i = myFoeLanes.begin(); i != myFoeLanes.end(); ++i) {
396  if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) {
397  return true;
398  }
399  }
400  return false;
401 }
402 
403 
406  return myDirection;
407 }
408 
409 
410 void
412  if (myState != state) {
413  myLastStateChange = t;
414  }
415  myState = state;
416 }
417 
418 
419 MSLane*
421  return myLane;
422 }
423 
424 MSLane*
426  MSLane* approachedLane; //the lane approached by this link; this lane may be an internal lane
427 #ifdef HAVE_INTERNAL_LANES
428  if (myJunctionInlane != 0) { // if there is an internal lane
429  approachedLane = myJunctionInlane; //consider the internal lane as the approached lane
430  } else { //if ther is no internal lane
431  approachedLane = myLane;
432  }
433 #else
434  approachedLane = myLane;
435 #endif
436  const std::vector<MSLane::IncomingLaneInfo> possibleLanes = approachedLane->getIncomingLanes();
437  std::vector<MSLane::IncomingLaneInfo>::const_iterator i;
438  for (i = possibleLanes.begin(); i != possibleLanes.end(); i++) {
439  MSLane* lane = (*i).lane;
440  MSLinkCont outgoingLinks = lane->getLinkCont(); //the links outgoing from lane
441  for (MSLinkCont::const_iterator j = outgoingLinks.begin(); j != outgoingLinks.end(); j++) {
442  if ((*j) == this) {
443  return lane;
444  }
445  }
446  }
447  WRITE_WARNING("No approaching lane found for the link with the index " + toString(this->getIndex()) + ".");
448  return 0;
449 }
450 
451 
452 bool
454 #ifdef HAVE_INTERNAL_LANES
455  if (myJunctionInlane == 0 || myAmCont) {
456  return false;
457  } else {
458  MSLane* pred = myJunctionInlane->getLogicalPredecessorLane();
460  return false;
461  } else {
462  MSLane* pred2 = pred->getLogicalPredecessorLane();
463  assert(pred2 != 0);
464  MSLink* predLink = MSLinkContHelper::getConnectingLink(*pred2, *pred);
465  assert(predLink != 0);
466  return predLink->havePriority();
467  }
468  }
469 #else
470  return false;
471 #endif
472 }
473 
474 
475 void
476 MSLink::writeApproaching(OutputDevice& od, const std::string fromLaneID) const {
477  if (myApproachingVehicles.size() > 0) {
478  od.openTag("link");
479  od.writeAttr(SUMO_ATTR_FROM, fromLaneID);
480 #ifdef HAVE_INTERNAL_LANES
481  const std::string via = getViaLane() == 0 ? "" : getViaLane()->getID();
482 #else
483  const std::string via = "";
484 #endif
485  od.writeAttr(SUMO_ATTR_VIA, via);
486  od.writeAttr(SUMO_ATTR_TO, getLane() == 0 ? "" : getLane()->getID());
487  std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort; // stabilize output
488  for (std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator it = myApproachingVehicles.begin(); it != myApproachingVehicles.end(); ++it) {
489  toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
490  }
491  std::sort(toSort.begin(), toSort.end());
492  for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
493  od.openTag("approaching");
494  const ApproachingVehicleInformation& avi = myApproachingVehicles.find(it->second)->second;
495  od.writeAttr(SUMO_ATTR_ID, it->second->getID());
496  od.writeAttr(SUMO_ATTR_IMPATIENCE, it->second->getImpatience());
497  od.writeAttr("arrivalTime", time2string(avi.arrivalTime));
498  od.writeAttr("arrivalTimeBraking", time2string(avi.arrivalTimeBraking));
499  od.writeAttr("leaveTime", time2string(avi.leavingTime));
500  od.writeAttr("arrivalSpeed", toString(avi.arrivalSpeed));
501  od.writeAttr("arrivalSpeedBraking", toString(avi.arrivalSpeedBraking));
502  od.writeAttr("leaveSpeed", toString(avi.leaveSpeed));
503  od.writeAttr("willPass", toString(avi.willPass));
504  od.closeTag();
505  }
506  od.closeTag();
507  }
508 }
509 
510 
511 #ifdef HAVE_INTERNAL_LANES
512 MSLane*
513 MSLink::getViaLane() const {
514  return myJunctionInlane;
515 }
516 
517 
519 MSLink::getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers) const {
520  LinkLeaders result;
521  //gDebugFlag1 = true;
522  // this link needs to start at an internal lane (either an exit link or between two internal lanes)
524  (myJunctionInlane == 0 && getLane()->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_NORMAL)
525  || (myJunctionInlane != 0 && myJunctionInlane->getLogicalPredecessorLane()->getEdge().isInternal()))) {
526  //if (gDebugFlag1) std::cout << SIMTIME << " getLeaderInfo link=" << getViaLaneOrLane()->getID() << "\n";
527  // this is an exit link
528  for (size_t i = 0; i < myFoeLanes.size(); ++i) {
529  const MSLane* foeLane = myFoeLanes[i];
530  // distance from the querying vehicle to the crossing point with foeLane
531  const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
532  const bool sameTarget = (myLane == foeLane->getLinkCont()[0]->getLane());
533  const bool sameSource = (myInternalLaneBefore != 0 && myInternalLaneBefore->getLogicalPredecessorLane() == foeLane->getLogicalPredecessorLane());
534  const SUMOReal crossingWidth = (sameTarget || sameSource) ? 0 : foeLane->getWidth();
535  const SUMOReal foeCrossingWidth = (sameTarget || sameSource) ? 0 : myInternalLaneBefore->getWidth();
536  //if (gDebugFlag1) std::cout << " distToCrossing=" << distToCrossing << " foeLane=" << foeLane->getID() << "\n";
537  if (distToCrossing + crossingWidth < 0) {
538  continue; // vehicle is behind the crossing point, continue with next foe lane
539  }
540  const SUMOReal foeDistToCrossing = foeLane->getLength() - myLengthsBehindCrossing[i].second;
541  // it is not sufficient to return the last vehicle on the foeLane because ego might be its leader
542  // therefore we return all vehicles on the lane
543  //
544  // special care must be taken for continuation lanes. (next lane is also internal)
545  // vehicles on these lanes should always block (gap = -1)
546  const bool contLane = (foeLane->getLinkCont()[0]->getViaLaneOrLane()->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL);
547  // vehicles on cont. lanes or on internal lanes with the same target as this link can never be ignored
548  const bool cannotIgnore = contLane || sameTarget || sameSource;
549  const MSLane::VehCont& vehicles = foeLane->getVehiclesSecure();
550  foeLane->releaseVehicles();
551  for (MSLane::VehCont::const_iterator it_veh = vehicles.begin(); it_veh != vehicles.end(); ++it_veh) {
552  MSVehicle* leader = *it_veh;
553  if (!cannotIgnore && !foeLane->getLinkCont()[0]->getApproaching(leader).willPass) {
554  continue;
555  }
556  if (cannotIgnore || leader->getWaitingTime() < MSGlobals::gIgnoreJunctionBlocker) {
557  // compute distance between vehicles on the the superimposition of both lanes
558  // where the crossing point is the common point
559  SUMOReal gap;
560  if (contLane && !sameSource) {
561  gap = -1; // always break for vehicles which are on a continuation lane
562  } else {
563  const SUMOReal leaderBack = leader->getPositionOnLane() - leader->getVehicleType().getLength();
564  const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
565  //if (gDebugFlag1) std::cout << " distToCrossing=" << distToCrossing << " leader back=" << leaderBack << " backDist=" << leaderBackDist << "\n";
566  if (leaderBackDist + foeCrossingWidth < 0) {
567  // leader is completely past the crossing point
568  // or there is no crossing point
569  continue; // next vehicle
570  }
571  gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
572  }
573  result.push_back(LinkLeader(leader, gap, cannotIgnore ? -1 : distToCrossing));
574  }
575 
576  }
577  MSVehicle* leader = foeLane->getPartialOccupator();
578  if (leader != 0) {
579  if (cannotIgnore || leader->getWaitingTime() < MSGlobals::gIgnoreJunctionBlocker) {
580  // compute distance between vehicles on the the superimposition of both lanes
581  // where the crossing point is the common point
582  SUMOReal gap;
583  if (contLane && !sameSource) {
584  gap = -1; // always break for vehicles which are on a continuation lane
585  } else {
586  const SUMOReal leaderBackDist = foeDistToCrossing - foeLane->getPartialOccupatorEnd();
587  //if (gDebugFlag1) std::cout << " distToCrossing=" << distToCrossing << " leader (partialOccupator) backDist=" << leaderBackDist << "\n";
588  if (leaderBackDist + foeCrossingWidth < 0) {
589  // leader is completely past the crossing point
590  // or there is no crossing point
591  continue; // next lane
592  }
593  gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
594  }
595  result.push_back(LinkLeader(leader, gap, sameTarget ? -1 : distToCrossing));
596  }
597  }
598  // check for crossing pedestrians (keep driving if already on top of the crossing
599  const SUMOReal distToPeds = distToCrossing - MSPModel::SAFETY_GAP;
600  if (distToPeds >= -MSPModel::SAFETY_GAP && MSPModel::getModel()->blockedAtDist(foeLane, foeDistToCrossing, collectBlockers)) {
601  result.push_back(LinkLeader((MSVehicle*)0, -1, distToPeds));
602  }
603  }
604  }
605  return result;
606 }
607 #endif
608 
609 
610 MSLane*
612 #ifdef HAVE_INTERNAL_LANES
613  if (myJunctionInlane != 0) {
614  return myJunctionInlane;
615  }
616 #endif
617  return myLane;
618 }
619 
620 
621 /****************************************************************************/
622 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:455
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
static const SUMOReal SAFETY_GAP
Definition: MSPModel.h:81
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:303
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:540
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:359
This is an uncontrolled, minor link, has to stop.
SUMOReal getLength() const
Returns the lane's length.
Definition: MSLane.h:370
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition: MSLane.h:88
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal getLength() const
Get vehicle's length [m].
SUMOReal getWidth() const
Returns the lane's width.
Definition: MSLane.h:386
T MAX2(T a, T b)
Definition: StdDefs.h:74
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:286
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
This is an uncontrolled, all-way stop link.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:296
SUMOReal getPartialOccupatorEnd() const
Returns the position of the in-lapping vehicle's end.
Definition: MSLane.h:261
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
const std::string & getID() const
Returns the id.
Definition: Named.h:60
MSLane * getLogicalPredecessorLane() const
Definition: MSLane.cpp:1357
Representation of a vehicle.
Definition: SUMOVehicle.h:65
static MSPModel * getModel()
Definition: MSPModel.cpp:65
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:71
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
Definition: MSCFModel.h:184
MSVehicle * getLastVehicle() const
returns the last vehicle
Definition: MSLane.cpp:960
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:240
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:235
The edge is a normal street.
Definition: MSEdge.h:94
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:90
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:294
int SUMOTime
Definition: SUMOTime.h:43
static SUMOTime gIgnoreJunctionBlocker
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:74
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
MSVehicle * getPartialOccupator() const
Returns the vehicle which laps into this lane.
Definition: MSLane.h:253
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:218
static const bool gUseMesoSim
Definition: MSGlobals.h:102
const MSJunction * getFromJunction() const
Definition: MSEdge.h:345
#define NUMERICAL_EPS
Definition: config.h:162
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1026
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:584
The edge is an internal edge.
Definition: MSEdge.h:98
SUMOReal interpolateGeometryPosToLanePos(SUMOReal geometryPos) const
Definition: MSLane.h:346
std::vector< SUMOReal > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.