48 #ifdef CHECK_MEMORY_LEAKS 50 #endif // CHECK_MEMORY_LEAKS 64 #define ZIPPER_ADAPT_TIME 10 69 #ifndef HAVE_INTERNAL_LANES 72 myLaneBefore(predLane),
80 myFoeVisibilityDistance(foeVisibilityDistance),
83 myKeepClear(keepClear),
106 myInternalLaneBefore(0),
121 const std::vector<MSLink*>& foeLinks,
122 const std::vector<MSLane*>& foeLanes,
123 MSLane* internalLaneBefore) {
128 for (std::vector<MSLane*>::const_iterator it_lane = foeLanes.begin(); it_lane != foeLanes.end(); ++it_lane) {
133 #ifdef HAVE_INTERNAL_LANES 134 myInternalLaneBefore = internalLaneBefore;
136 if (internalLaneBefore != 0) {
138 lane = internalLaneBefore;
144 #ifdef MSLink_DEBUG_CROSSING_POINTS 148 const bool beforeInternalJunction = lane->
getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
151 for (std::vector<const MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
153 if (sameTarget && !beforeInternalJunction) {
156 myLengthsBehindCrossing.push_back(std::make_pair(0, 0));
157 #ifdef MSLink_DEBUG_CROSSING_POINTS 159 <<
" " << lane->
getID()
160 <<
" merges with " << (*it_lane)->getID()
161 <<
" nextLane " << lane->
getLinkCont()[0]->getViaLaneOrLane()->getID()
162 <<
" dist1=" << myLengthsBehindCrossing.back().first
163 <<
" dist2=" << myLengthsBehindCrossing.back().second
168 #ifdef MSLink_DEBUG_CROSSING_POINTS 171 bool haveIntersection =
true;
172 if (intersections1.size() == 0) {
173 intersections1.push_back(-10000.0);
174 haveIntersection =
false;
175 }
else if (intersections1.size() > 1) {
176 std::sort(intersections1.begin(), intersections1.end());
178 std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->
getShape());
179 #ifdef MSLink_DEBUG_CROSSING_POINTS 182 if (intersections2.size() == 0) {
183 intersections2.push_back(0);
184 }
else if (intersections2.size() > 1) {
185 std::sort(intersections2.begin(), intersections2.end());
187 if (haveIntersection) {
189 intersections1.back() -= (*it_lane)->getWidth() / 2;
190 intersections2.back() -= lane->
getWidth() / 2;
193 intersections2.back() = (*it_lane)->interpolateGeometryPosToLanePos(intersections2.back());
198 intersections1.back() = 0;
202 myLengthsBehindCrossing.push_back(std::make_pair(
203 lane->
getLength() - intersections1.back(),
204 (*it_lane)->getLength() - intersections2.back()));
206 #ifdef MSLink_DEBUG_CROSSING_POINTS 208 <<
" intersection of " << lane->
getID()
210 <<
" with " << (*it_lane)->getID()
211 <<
" totalLength=" << (*it_lane)->getLength()
212 <<
" dist1=" << myLengthsBehindCrossing.back().first
213 <<
" dist2=" << myLengthsBehindCrossing.back().second
223 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
224 const MSLane* sibling = (*it)->getViaLane();
225 if (sibling != lane && sibling != 0) {
227 #ifdef MSLink_DEBUG_CROSSING_POINTS 230 if (intersections1.size() > 0) {
231 std::sort(intersections1.begin(), intersections1.end());
234 myLengthsBehindCrossing.push_back(std::make_pair(
235 lane->
getLength() - intersections1.back(),
236 sibling->
getLength() - intersections1.back()));
238 #ifdef MSLink_DEBUG_CROSSING_POINTS 239 std::cout <<
" adding same-origin foe" << sibling->
getID()
240 <<
" dist1=" << myLengthsBehindCrossing.back().first
241 <<
" dist2=" << myLengthsBehindCrossing.back().second
256 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
257 const MSEdge* target = &((*it)->getLane()->getEdge());
258 if (*it !=
this && target == myTarget) {
266 std::pair<SUMOReal, SUMOReal>
275 arrivalTimeBraking, arrivalSpeedBraking, waitingTime, dist)));
289 if ((*i)->isBlockingAnyone()) {
305 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
324 std::vector<const SUMOVehicle*>* collectFoes)
const {
335 const MSLink* foeLink = *it;
344 && (arrivalTime > i->second.arrivalTime
348 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
false,
349 impatience, decel, waitingTime)) {
351 if (collectFoes == 0) {
355 collectFoes->push_back(i->first);
366 return collectFoes == 0 || collectFoes->size() == 0;
373 if ((*i)->haveRed()) {
377 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
378 impatience, decel, waitingTime, collectFoes)) {
382 if (collectFoes != 0 && collectFoes->size() > 0) {
392 std::vector<const SUMOVehicle*>* collectFoes)
const {
394 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, sameTargetLane,
395 impatience, decel, waitingTime)) {
396 if (collectFoes == 0) {
399 collectFoes->push_back(i->first);
414 assert(waitingTime > 0);
426 if (sameTargetLane && (arrivalTime - avi.
leavingTime < lookAhead
431 }
else if (foeArrivalTime > leaveTime) {
433 if (sameTargetLane && (foeArrivalTime - leaveTime < lookAhead
454 assert(distLeft > 0);
465 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
469 for (std::vector<const MSLane*>::const_iterator i =
myFoeLanes.begin(); i !=
myFoeLanes.end(); ++i) {
470 if ((*i)->getVehicleNumberWithPartials() > 0) {
500 #ifdef HAVE_INTERNAL_LANES 501 if (myInternalLane == 0 ||
myAmCont) {
511 assert(predLink != 0);
526 #ifdef HAVE_INTERNAL_LANES 527 const std::string via = getViaLane() == 0 ?
"" : getViaLane()->
getID();
529 const std::string via =
"";
533 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
535 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
537 std::sort(toSort.begin(), toSort.end());
538 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
560 #ifdef HAVE_INTERNAL_LANES 561 MSLane* lane = myInternalLane;
572 #ifdef HAVE_INTERNAL_LANES 574 MSLink::getViaLane()
const {
575 return myInternalLane;
597 MSLink::getLeaderInfo(
const MSVehicle* ego,
SUMOReal dist, std::vector<const MSPerson*>* collectBlockers)
const {
608 for (
int i = 0; i < (int)
myFoeLanes.size(); ++i) {
611 const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
613 const bool sameSource = (myInternalLaneBefore != 0 && myInternalLaneBefore->getLogicalPredecessorLane() == foeLane->
getLogicalPredecessorLane());
614 const SUMOReal crossingWidth = (sameTarget || sameSource) ? 0 : foeLane->
getWidth();
615 const SUMOReal foeCrossingWidth = (sameTarget || sameSource) ? 0 : myInternalLaneBefore->getWidth();
617 std::cout <<
" distToCrossing=" << distToCrossing <<
" foeLane=" << foeLane->
getID() <<
"\n";
619 if (distToCrossing + crossingWidth < 0) {
622 const SUMOReal foeDistToCrossing = foeLane->
getLength() - myLengthsBehindCrossing[i].second;
630 const bool cannotIgnore = contLane || sameTarget || sameSource;
636 std::cout <<
" candiate leader=" << leader->
getID()
637 <<
" cannotIgnore=" << cannotIgnore
638 <<
" willPass=" << foeLane->
getLinkCont()[0]->getApproaching(leader).willPass
640 <<
" isOpposite=" << isOpposite <<
"\n";
642 if (!cannotIgnore && !foeLane->
getLinkCont()[0]->getApproaching(leader).willPass && leader->
isFrontOnLane(foeLane) && !isOpposite) {
649 if ((contLane && !sameSource) || isOpposite) {
653 const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
655 std::cout <<
" distToCrossing=" << distToCrossing <<
" leader back=" << leaderBack <<
" backDist=" << leaderBackDist <<
"\n";
657 if (leaderBackDist + foeCrossingWidth < 0) {
665 std::cout <<
" leader=" << leader->
getID() <<
" contLane=" << contLane <<
" cannotIgnore=" << cannotIgnore <<
"\n";
669 const bool stopAsap = leader->
isFrontOnLane(foeLane) ? cannotIgnore : sameTarget;
670 result.push_back(
LinkLeader(leader, gap, stopAsap ? -1 : distToCrossing));
676 if (distToPeds >= -MSPModel::SAFETY_GAP &&
MSPModel::getModel()->blockedAtDist(foeLane, foeDistToCrossing, collectBlockers)) {
688 #ifdef HAVE_INTERNAL_LANES 689 if (myInternalLane != 0) {
690 return myInternalLane;
699 #ifdef HAVE_INTERNAL_LANES 701 if (myInternalLaneBefore != 0) {
713 if (direction == -1) {
715 }
else if (direction == 1) {
728 if (before != 0 && after != 0) {
755 #ifdef HAVE_INTERNAL_LANES 756 return myInternalLaneBefore;
766 std::vector<const SUMOVehicle*>* collectFoes)
const {
773 throw ProcessError(
"Zipper junctions with more than two conflicting lanes are not supported (at junction '" 792 for (std::vector<const SUMOVehicle*>::const_iterator i = collectFoes->begin(); i != collectFoes->end(); ++i) {
817 const SUMOReal followInTime = vSafeOrig + (follow - vSafeOrig) /
MAX2((
SUMOReal)1, secondsToArrival /
TS);
818 vSafe =
MIN2(vSafe, followInTime);
839 followDist > leaderDist &&
bool gDebugFlag1
global utility flags for debugging
SUMOReal getZipperSpeed(const MSVehicle *ego, const SUMOReal dist, SUMOReal vSafe, SUMOTime arrivalTime, std::vector< const SUMOVehicle * > *collectFoes) const
return the speed at which ego vehicle must approach the zipper link
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
MSEdge & getEdge() const
Returns the lane's edge.
int myIndex
The position within this respond.
Representation of a vehicle in the micro simulation.
bool hasFoes() const
Returns whether this link belongs to a junction where more than one edge is incoming.
MSVehicle * getLastAnyVehicle() const
returns the last vehicle that is fully or partially on this lane
bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const
Returns the information whether a vehicle is approaching on one of the link's foe streams...
static const SUMOReal SAFETY_GAP
const MSLane * getInternalLaneBefore() const
return myInternalLaneBefore (always 0 when compiled without internal lanes)
MSLane * myLane
The lane behind the junction approached by this link.
void addBlockedLink(MSLink *link)
SUMOTime myMesoTLSPenalty
penalty time for mesoscopic simulation
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
LinkState myState
The state of the link.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
std::pair< SUMOReal, SUMOReal > getLastIntersections(const MSLane *lane, const MSLane *foe)
MSLink * getParallelLink(int direction) const
return the link that is parallel to this lane or 0
void setRequestInformation(int index, bool hasFoes, bool isCont, const std::vector< MSLink * > &foeLinks, const std::vector< MSLane * > &foeLanes, MSLane *internalLaneBefore=0)
Sets the request information.
void setApproaching(const SUMOVehicle *approaching, const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest, const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking, const SUMOTime waitingTime, SUMOReal dist)
Sets the information about an approaching vehicle.
const std::map< const SUMOVehicle *, ApproachingVehicleInformation > & getApproaching() const
return all approaching vehicles
bool keepClear() const
whether the junction after this link must be kept clear
static const SUMOReal ZIPPER_ADAPT_DIST
const int myTLIndex
the traffic light index
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
bool myHasFoes
Whether any foe links exist.
This is an uncontrolled, minor link, has to stop.
SUMOReal getLength() const
Returns the lane's length.
The base class for an intersection.
std::vector< MSLink * > mySublaneFoeLinks
SUMOTime myLastStateChange
The time of the last state change.
std::vector< MSLink * > myFoeLinks
#define ZIPPER_ADAPT_TIME
void setTLState(LinkState state, SUMOTime t)
Sets the current tl-state.
std::string time2string(SUMOTime t)
SUMOReal getLength() const
Get vehicle's length [m].
static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle *follow, const MSVehicle *leader)
whether fllower could stay behind leader (possibly by braking)
LinkDirection myDirection
An abstract (hopefully human readable) definition of the link's direction.
SUMOReal getWidth() const
Returns the lane's width.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static const SUMOTime myLookaheadTime
LinkDirection getDirection() const
Returns the direction the vehicle passing this link take.
std::map< const SUMOVehicle *, ApproachingVehicleInformation > myApproachingVehicles
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
bool lastWasContMajor() const
whether this is a link past an internal junction which currently has priority
This is an uncontrolled, all-way stop link.
bool fromInternalLane() const
return whether the fromLane of this link is an internal lane
#define UNUSED_PARAMETER(x)
This is an uncontrolled, zipper-merge link.
bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime, std::vector< const SUMOVehicle * > *collectFoes=0) const
Returns the information whether this link is blocked Valid after the vehicles have set their requests...
MSAbstractLaneChangeModel & getLaneChangeModel()
MSLink * computeParallelLink(int direction)
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
SUMOReal myLength
The length of the link.
SUMOReal getInternalLengthsAfter() const
Returns the cumulative length of all internal lanes after this link.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const
return the expected time at which the given vehicle will clear the link
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime, SUMOReal posLat=0, std::vector< const SUMOVehicle * > *collectFoes=0) const
Returns the information whether the link may be passed.
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Representation of a vehicle.
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
static MSPModel * getModel()
bool isInternalJunctionLink() const
return whether the fromLane and the toLane of this link are internal lanes
MSLane * getLane() const
Returns the connected lane.
static const SUMOTime myLookaheadTimeZipper
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
std::set< MSLink * > myBlockedFoeLinks
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
virtual SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const =0
Computes the vehicle's follow speed (no dawdling)
bool blockedByFoe(const SUMOVehicle *veh, const ApproachingVehicleInformation &avi, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime) const
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
std::vector< LinkLeader > LinkLeaders
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
void initParallelLinks()
initialize parallel links (to be called after all links are loaded)
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
int getIndex() const
Returns the lane's index.
bool isInternal() const
return whether this edge is an internal edge
static bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel)
return whether the given vehicles may NOT merge safely
SUMOReal getLength() const
Returns the length of this link.
static bool maybeOccupied(MSLane *lane)
returns whether the given lane may still be occupied by a vehicle currently on it ...
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
virtual SUMOReal getLateralPositionOnLane() const =0
Get the vehicle's lateral position on the lane.
bool havePriority() const
Returns whether this link is a major link.
bool willHaveBlockedFoe() const
const MSTrafficLightLogic * myLogic
the controlling logic or 0
static MSLink * getConnectingLink(const MSLane &from, const MSLane &to)
Returns the link connecting both lanes Both lanes have to be non-internal; 0 may be returned if no co...
The edge is a normal street.
MSLane * getViaLaneOrLane() const
return the via lane if it exists and the lane otherwise
MSLane * myLaneBefore
The lane approaching this link.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
static SUMOReal gLateralResolution
MSJunction * myJunction
the junction to which this link belongs
bool haveRed() const
Returns whether this link is blocked by a red (or redyellow) traffic light.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
void writeApproaching(OutputDevice &od, const std::string fromLaneID) const
write information about all approaching vehicles to the given output device
bool isFrontOnLane(const MSLane *lane) const
Returns the information whether the front of the vehicle is on the given lane.
AnyVehicleIterator anyVehiclesEnd() const
end iterator for iterating over all vehicles touching this lane in downstream direction ...
SUMOReal getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
static SUMOTime gIgnoreJunctionBlocker
const PositionVector & getShape() const
Returns this lane's shape.
The parent class for traffic light logics.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
const MSJunction * getFromJunction() const
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
SUMOReal myFoeVisibilityDistance
distance from which an approaching vehicle is able to see all relevant foes and may accelerate if the...
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
const MSLane * getLaneBefore() const
return the internalLaneBefore if it exists and the laneBefore otherwise
MSLane * getLane() const
Returns the lane the vehicle is on.
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
The edge is an internal edge.
SUMOReal interpolateGeometryPosToLanePos(SUMOReal geometryPos) const
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 ...
AnyVehicleIterator anyVehiclesBegin() const
begin iterator for iterating over all vehicles touching this lane in downstream direction ...
Representation of a lane in the micro simulation.
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
MSLink(MSLane *predLane, MSLane *succLane, LinkDirection dir, LinkState state, SUMOReal length, SUMOReal foeVisibilityDistance, bool keepClear, MSTrafficLightLogic *logic, int tlLinkIdx)
Constructor for simulation not using internal lanes.
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders of this links junction
bool isExitLink() const
return whether the fromLane of this link is an internal lane and toLane is a normal lane ...
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::vector< const MSLane * > myFoeLanes
const std::string & getID() const
Returns the name of the vehicle.