47 #ifdef CHECK_MEMORY_LEAKS 49 #endif // CHECK_MEMORY_LEAKS 63 #define ZIPPER_ADAPT_TIME 10 68 #ifndef HAVE_INTERNAL_LANES 71 myLaneBefore(predLane),
79 myFoeVisibilityDistance(foeVisibilityDistance),
82 myKeepClear(keepClear),
104 myInternalLaneBefore(0),
118 const std::vector<MSLink*>& foeLinks,
119 const std::vector<MSLane*>& foeLanes,
120 MSLane* internalLaneBefore) {
125 for (std::vector<MSLane*>::const_iterator it_lane = foeLanes.begin(); it_lane != foeLanes.end(); ++it_lane) {
130 #ifdef HAVE_INTERNAL_LANES 131 myInternalLaneBefore = internalLaneBefore;
133 if (internalLaneBefore != 0) {
135 lane = internalLaneBefore;
141 #ifdef MSLink_DEBUG_CROSSING_POINTS 145 const bool beforeInternalJunction = lane->
getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
148 for (std::vector<const MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
150 if (sameTarget && !beforeInternalJunction) {
153 myLengthsBehindCrossing.push_back(std::make_pair(0, 0));
154 #ifdef MSLink_DEBUG_CROSSING_POINTS 156 <<
" " << lane->
getID()
157 <<
" merges with " << (*it_lane)->getID()
158 <<
" nextLane " << lane->
getLinkCont()[0]->getViaLaneOrLane()->getID()
159 <<
" dist1=" << myLengthsBehindCrossing.back().first
160 <<
" dist2=" << myLengthsBehindCrossing.back().second
165 #ifdef MSLink_DEBUG_CROSSING_POINTS 168 bool haveIntersection =
true;
169 if (intersections1.size() == 0) {
170 intersections1.push_back(-10000.0);
171 haveIntersection =
false;
172 }
else if (intersections1.size() > 1) {
173 std::sort(intersections1.begin(), intersections1.end());
175 std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->
getShape());
176 #ifdef MSLink_DEBUG_CROSSING_POINTS 179 if (intersections2.size() == 0) {
180 intersections2.push_back(0);
181 }
else if (intersections2.size() > 1) {
182 std::sort(intersections2.begin(), intersections2.end());
184 if (haveIntersection) {
186 intersections1.back() -= (*it_lane)->getWidth() / 2;
187 intersections2.back() -= lane->
getWidth() / 2;
190 intersections2.back() = (*it_lane)->interpolateGeometryPosToLanePos(intersections2.back());
195 intersections1.back() = 0;
199 myLengthsBehindCrossing.push_back(std::make_pair(
200 lane->
getLength() - intersections1.back(),
201 (*it_lane)->getLength() - intersections2.back()));
203 #ifdef MSLink_DEBUG_CROSSING_POINTS 205 <<
" intersection of " << lane->
getID()
207 <<
" with " << (*it_lane)->getID()
208 <<
" totalLength=" << (*it_lane)->getLength()
209 <<
" dist1=" << myLengthsBehindCrossing.back().first
210 <<
" dist2=" << myLengthsBehindCrossing.back().second
220 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
221 const MSLane* sibling = (*it)->getViaLane();
222 if (sibling != lane && sibling != 0) {
224 #ifdef MSLink_DEBUG_CROSSING_POINTS 227 if (intersections1.size() > 0) {
228 std::sort(intersections1.begin(), intersections1.end());
231 myLengthsBehindCrossing.push_back(std::make_pair(
232 lane->
getLength() - intersections1.back(),
233 sibling->
getLength() - intersections1.back()));
235 #ifdef MSLink_DEBUG_CROSSING_POINTS 236 std::cout <<
" adding same-origin foe" << sibling->
getID()
237 <<
" dist1=" << myLengthsBehindCrossing.back().first
238 <<
" dist2=" << myLengthsBehindCrossing.back().second
253 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
254 const MSEdge* target = &((*it)->getLane()->getEdge());
255 if (*it !=
this && target == myTarget) {
263 std::pair<SUMOReal, SUMOReal>
272 arrivalTimeBraking, arrivalSpeedBraking, waitingTime, dist)));
286 if ((*i)->isBlockingAnyone()) {
302 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
321 std::vector<const SUMOVehicle*>* collectFoes)
const {
332 const MSLink* foeLink = *it;
341 && (arrivalTime > i->second.arrivalTime
345 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
false,
346 impatience, decel, waitingTime)) {
348 if (collectFoes == 0) {
352 collectFoes->push_back(i->first);
363 return collectFoes == 0 || collectFoes->size() == 0;
370 if ((*i)->haveRed()) {
374 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
375 impatience, decel, waitingTime, collectFoes)) {
379 if (collectFoes != 0 && collectFoes->size() > 0) {
389 std::vector<const SUMOVehicle*>* collectFoes)
const {
391 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, sameTargetLane,
392 impatience, decel, waitingTime)) {
393 if (collectFoes == 0) {
396 collectFoes->push_back(i->first);
411 assert(waitingTime > 0);
423 if (sameTargetLane && (arrivalTime - avi.
leavingTime < lookAhead
428 }
else if (foeArrivalTime > leaveTime) {
430 if (sameTargetLane && (foeArrivalTime - leaveTime < lookAhead
451 assert(distLeft > 0);
462 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
466 for (std::vector<const MSLane*>::const_iterator i =
myFoeLanes.begin(); i !=
myFoeLanes.end(); ++i) {
467 if ((*i)->getVehicleNumberWithPartials() > 0) {
498 #ifdef HAVE_INTERNAL_LANES 499 if (myInternalLane != 0) {
500 approachedLane = myInternalLane;
507 const std::vector<MSLane::IncomingLaneInfo> possibleLanes = approachedLane->
getIncomingLanes();
508 std::vector<MSLane::IncomingLaneInfo>::const_iterator i;
509 for (i = possibleLanes.begin(); i != possibleLanes.end(); i++) {
512 for (MSLinkCont::const_iterator j = outgoingLinks.begin(); j != outgoingLinks.end(); j++) {
525 #ifdef HAVE_INTERNAL_LANES 526 if (myInternalLane == 0 ||
myAmCont) {
536 assert(predLink != 0);
551 #ifdef HAVE_INTERNAL_LANES 552 const std::string via = getViaLane() == 0 ?
"" : getViaLane()->
getID();
554 const std::string via =
"";
558 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
560 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
562 std::sort(toSort.begin(), toSort.end());
563 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
585 #ifdef HAVE_INTERNAL_LANES 586 MSLane* lane = myInternalLane;
597 #ifdef HAVE_INTERNAL_LANES 599 MSLink::getViaLane()
const {
600 return myInternalLane;
622 MSLink::getLeaderInfo(
SUMOReal dist,
SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers)
const {
629 for (
int i = 0; i < (int)
myFoeLanes.size(); ++i) {
632 const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
634 const bool sameSource = (myInternalLaneBefore != 0 && myInternalLaneBefore->getLogicalPredecessorLane() == foeLane->
getLogicalPredecessorLane());
635 const SUMOReal crossingWidth = (sameTarget || sameSource) ? 0 : foeLane->
getWidth();
636 const SUMOReal foeCrossingWidth = (sameTarget || sameSource) ? 0 : myInternalLaneBefore->getWidth();
638 std::cout <<
" distToCrossing=" << distToCrossing <<
" foeLane=" << foeLane->
getID() <<
"\n";
640 if (distToCrossing + crossingWidth < 0) {
643 const SUMOReal foeDistToCrossing = foeLane->
getLength() - myLengthsBehindCrossing[i].second;
651 const bool cannotIgnore = contLane || sameTarget || sameSource;
655 if (!cannotIgnore && !foeLane->
getLinkCont()[0]->getApproaching(leader).willPass && leader->
isFrontOnLane(foeLane)) {
662 if (contLane && !sameSource) {
666 const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
668 std::cout <<
" distToCrossing=" << distToCrossing <<
" leader back=" << leaderBack <<
" backDist=" << leaderBackDist <<
"\n";
670 if (leaderBackDist + foeCrossingWidth < 0) {
675 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
678 std::cout <<
" leader=" << leader->
getID() <<
" contLane=" << contLane <<
" cannotIgnore=" << cannotIgnore <<
"\n";
682 const bool stopAsap = leader->
isFrontOnLane(foeLane) ? cannotIgnore : sameTarget;
683 result.push_back(
LinkLeader(leader, gap, stopAsap ? -1 : distToCrossing));
689 if (distToPeds >= -MSPModel::SAFETY_GAP &&
MSPModel::getModel()->blockedAtDist(foeLane, foeDistToCrossing, collectBlockers)) {
701 #ifdef HAVE_INTERNAL_LANES 702 if (myInternalLane != 0) {
703 return myInternalLane;
712 #ifdef HAVE_INTERNAL_LANES 714 if (myInternalLaneBefore != 0) {
726 if (direction == -1) {
728 }
else if (direction == 1) {
741 if (before != 0 && after != 0) {
768 #ifdef HAVE_INTERNAL_LANES 769 return myInternalLaneBefore;
779 std::vector<const SUMOVehicle*>* collectFoes)
const {
786 throw ProcessError(
"Zipper junctions with more than two conflicting lanes are not supported (at junction '" 805 for (std::vector<const SUMOVehicle*>::const_iterator i = collectFoes->begin(); i != collectFoes->end(); ++i) {
830 const SUMOReal followInTime = vSafeOrig + (follow - vSafeOrig) /
MAX2((
SUMOReal)1, secondsToArrival /
TS);
831 vSafe =
MIN2(vSafe, followInTime);
852 followDist > leaderDist &&
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
bool gDebugFlag1
global utility flags for debugging
SUMOReal getWidth() const
Returns the lane's width.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
SUMOReal getLength() const
Returns the lane's length.
int myIndex
The position within this respond.
MSEdge & getEdge() const
Returns the lane's edge.
Representation of a vehicle in the micro simulation.
static const SUMOReal SAFETY_GAP
MSLane * myLane
The lane behind the junction approached by this link.
bool keepClear() const
whether the junction after this link must be kept clear
void addBlockedLink(MSLink *link)
SUMOTime myMesoTLSPenalty
penalty time for mesoscopic simulation
LinkState myState
The state of the link.
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
LinkDirection getDirection() const
Returns the direction the vehicle passing this link take.
std::pair< SUMOReal, SUMOReal > getLastIntersections(const MSLane *lane, const MSLane *foe)
MSLane * getLane() const
Returns the connected lane.
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.
MSLane * getLane() const
Returns the lane the vehicle is on.
static const SUMOReal ZIPPER_ADAPT_DIST
const int myTLIndex
the traffic light index
bool myHasFoes
Whether any foe links exist.
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)
This is an uncontrolled, minor link, has to stop.
The base class for an intersection.
std::vector< MSLink * > mySublaneFoeLinks
const MSLane * getLaneBefore() const
return the internalLaneBefore if it exists and the laneBefore otherwise
SUMOTime myLastStateChange
The time of the last state change.
std::vector< MSLink * > myFoeLinks
#define ZIPPER_ADAPT_TIME
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
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.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static const SUMOTime myLookaheadTime
const PositionVector & getShape() const
Returns this lane's shape.
bool hasFoes() const
Returns whether this link belongs to a junction where more than one edge is incoming.
std::map< const SUMOVehicle *, ApproachingVehicleInformation > myApproachingVehicles
const std::string & getID() const
Returns the id.
SUMOReal getLength() const
Returns the length of this link.
SUMOReal interpolateGeometryPosToLanePos(SUMOReal geometryPos) const
This is an uncontrolled, all-way stop link.
#define UNUSED_PARAMETER(x)
bool isInternalJunctionLink() const
return whether the fromLane and the toLane of this link are internal lanes
This is an uncontrolled, zipper-merge link.
#define WRITE_WARNING(msg)
MSLink * computeParallelLink(int direction)
MSLink * getParallelLink(int direction) const
return the link that is parallel to this lane or 0
bool isFrontOnLane(const MSLane *lane) const
Returns the information whether the front of the vehicle is on the given lane.
SUMOReal myLength
The length of the link.
bool willHaveBlockedFoe() const
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
bool fromInternalLane() const
return whether the fromLane of this link is an internal lane
bool lastWasContMajor() const
whether this is a link past an internal junction which currently has priority
A road/street connecting two junctions.
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 MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
int getIndex() const
Returns the lane's index.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
bool isExitLink() const
return whether the fromLane of this link is an internal lane and toLane is a normal lane ...
Representation of a vehicle.
static MSPModel * getModel()
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
static const SUMOTime myLookaheadTimeZipper
void writeApproaching(OutputDevice &od, const std::string fromLaneID) const
write information about all approaching vehicles to the given output device
std::set< MSLink * > myBlockedFoeLinks
bool havePriority() const
Returns whether this link is a major link.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
AnyVehicleIterator anyVehiclesEnd() const
end iterator for iterating over all vehicles touching this lane in downstream direction ...
const MSLane * getInternalLaneBefore() const
return myInternalLaneBefore (always 0 when compiled without internal lanes)
AnyVehicleIterator anyVehiclesBegin() const
begin iterator for iterating over all vehicles touching this lane in downstream direction ...
std::vector< LinkLeader > LinkLeaders
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.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
void initParallelLinks()
initialize parallel links (to be called after all links are loaded)
virtual SUMOReal getLateralPositionOnLane() const =0
Get the vehicle's lateral position on the lane.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
bool isInternal() const
return whether this edge is an internal edge
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 ...
static bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel)
return whether the given vehicles may NOT merge safely
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
static bool maybeOccupied(MSLane *lane)
returns whether the given lane may still be occupied by a vehicle currently on it ...
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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.
const MSJunction * getFromJunction() const
MSLane * myLaneBefore
The lane approaching this link.
MSLane * getApproachingLane() const
Returns the lane leading to this link.
static SUMOReal gLateralResolution
MSJunction * myJunction
the junction to which this link belongs
MSVehicle * getLastAnyVehicle() const
returns the last vehicle that is fully or partially on this lane
MSLane * getViaLaneOrLane() const
return the via lane if it exists and the lane otherwise
int getIndex() const
Returns the respond index (for visualization)
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
static SUMOTime gIgnoreJunctionBlocker
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
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.
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 std::map< const SUMOVehicle *, ApproachingVehicleInformation > & getApproaching() const
return all approaching vehicles
The edge is an internal edge.
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
SUMOReal getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
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
SUMOReal getSpeed() const
Returns the vehicle's current speed.
bool haveRed() const
Returns whether this link is blocked by a red (or redyellow) traffic light.
SUMOReal getInternalLengthsAfter() const
Returns the cumulative length of all internal lanes after this link.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
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...
std::vector< const MSLane * > myFoeLanes
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
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...