61 #define ZIPPER_ADAPT_TIME 10 63 #define JM_CROSSING_GAP_DEFAULT 10 70 myLaneBefore(predLane),
78 myFoeVisibilityDistance(foeVisibilityDistance),
81 myKeepClear(keepClear),
83 myInternalLaneBefore(0),
98 const std::vector<MSLink*>& foeLinks,
99 const std::vector<MSLane*>& foeLanes,
100 MSLane* internalLaneBefore) {
110 for (std::vector<MSLane*>::const_iterator it_lane = foeLanes.begin(); it_lane != foeLanes.end(); ++it_lane) {
117 if (internalLaneBefore != 0) {
119 lane = internalLaneBefore;
125 #ifdef MSLink_DEBUG_CROSSING_POINTS 129 const bool beforeInternalJunction = lane->
getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
132 for (std::vector<const MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
134 if (sameTarget && !beforeInternalJunction) {
138 #ifdef MSLink_DEBUG_CROSSING_POINTS 140 <<
" " << lane->
getID()
141 <<
" merges with " << (*it_lane)->getID()
142 <<
" nextLane " << lane->
getLinkCont()[0]->getViaLaneOrLane()->getID()
149 #ifdef MSLink_DEBUG_CROSSING_POINTS 152 bool haveIntersection =
true;
153 if (intersections1.size() == 0) {
154 intersections1.push_back(-10000.0);
155 haveIntersection =
false;
156 }
else if (intersections1.size() > 1) {
157 std::sort(intersections1.begin(), intersections1.end());
159 std::vector<double> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->
getShape());
160 #ifdef MSLink_DEBUG_CROSSING_POINTS 163 if (intersections2.size() == 0) {
164 intersections2.push_back(0);
165 }
else if (intersections2.size() > 1) {
166 std::sort(intersections2.begin(), intersections2.end());
168 if (haveIntersection) {
170 intersections1.back() -= (*it_lane)->getWidth() / 2;
171 intersections2.back() -= lane->
getWidth() / 2;
174 intersections2.back() = (*it_lane)->interpolateGeometryPosToLanePos(intersections2.back());
179 intersections1.back() = 0;
184 lane->
getLength() - intersections1.back(),
185 (*it_lane)->getLength() - intersections2.back()));
187 #ifdef MSLink_DEBUG_CROSSING_POINTS 189 <<
" intersection of " << lane->
getID()
191 <<
" with " << (*it_lane)->getID()
192 <<
" totalLength=" << (*it_lane)->getLength()
204 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
205 const MSLane* sibling = (*it)->getViaLane();
206 if (sibling != lane && sibling != 0) {
208 #ifdef MSLink_DEBUG_CROSSING_POINTS 211 if (intersections1.size() > 0) {
212 std::sort(intersections1.begin(), intersections1.end());
216 lane->
getLength() - intersections1.back(),
217 sibling->
getLength() - intersections1.back()));
219 #ifdef MSLink_DEBUG_CROSSING_POINTS 220 std::cout <<
" adding same-origin foe" << sibling->
getID()
235 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
236 const MSEdge* target = &((*it)->getLane()->getEdge());
237 if (*it !=
this && target == myTarget) {
245 for (MSLinkCont::const_iterator it = predLinks2.begin(); it != predLinks2.end(); ++it) {
246 const MSEdge* target = &((*it)->getLane()->getEdge());
257 std::pair<double, double>
262 const bool setRequest,
const SUMOTime arrivalTimeBraking,
const double arrivalSpeedBraking,
const SUMOTime waitingTime,
double dist) {
266 arrivalTimeBraking, arrivalSpeedBraking, waitingTime, dist)));
280 if ((*i)->isBlockingAnyone()) {
296 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
307 const double leaveSpeed,
const double vehicleLength)
const {
314 double impatience,
double decel,
SUMOTime waitingTime,
double posLat,
315 std::vector<const SUMOVehicle*>* collectFoes,
bool ignoreRed,
const SUMOVehicle* ego)
const {
326 const MSLink* foeLink = *it;
335 && (arrivalTime > i->second.arrivalTime
339 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
false,
340 impatience, decel, waitingTime)) {
341 #ifdef MSLink_DEBUG_OPENED 343 std::cout <<
SIMTIME <<
" blocked by " << foe->
getID() <<
" arrival=" << arrivalTime <<
" foeArrival=" << i->second.arrivalTime <<
"\n";
346 if (collectFoes == 0) {
347 #ifdef MSLink_DEBUG_OPENED 354 collectFoes->push_back(i->first);
365 return collectFoes == 0 || collectFoes->size() == 0;
371 #ifdef MSLink_DEBUG_OPENED 379 if ((*i)->haveRed()) {
383 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
384 impatience, decel, waitingTime, collectFoes, ego)) {
388 if (collectFoes != 0 && collectFoes->size() > 0) {
397 bool sameTargetLane,
double impatience,
double decel,
SUMOTime waitingTime,
398 std::vector<const SUMOVehicle*>* collectFoes,
const SUMOVehicle* ego)
const {
400 if (i->first != ego &&
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, sameTargetLane,
401 impatience, decel, waitingTime)) {
402 if (collectFoes == 0) {
405 collectFoes->push_back(i->first);
415 bool sameTargetLane,
double impatience,
double decel,
SUMOTime waitingTime)
const {
416 #ifdef MSLink_DEBUG_OPENED 419 <<
" foeVeh=" << veh->
getID()
430 assert(waitingTime > 0);
442 if (sameTargetLane && (arrivalTime - avi.
leavingTime < lookAhead
445 #ifdef MSLink_DEBUG_OPENED 447 std::cout <<
" blocked (cannot follow)\n";
452 }
else if (foeArrivalTime > leaveTime) {
454 if (sameTargetLane && (foeArrivalTime - leaveTime < lookAhead
457 #ifdef MSLink_DEBUG_OPENED 459 std::cout <<
" blocked (cannot lead)\n";
466 #ifdef MSLink_DEBUG_OPENED 468 std::cout <<
" blocked (hard conflict)\n";
485 assert(distLeft > 0);
496 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
500 for (std::vector<const MSLane*>::const_iterator i =
myFoeLanes.begin(); i !=
myFoeLanes.end(); ++i) {
501 if ((*i)->getVehicleNumberWithPartials() > 0) {
541 assert(predLink != 0);
556 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
558 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
560 std::sort(toSort.begin(), toSort.end());
561 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
612 double totalDist = 0.;
613 bool foundCrossing =
false;
620 foundCrossing =
true;
638 for (foe_ix = 0; foe_ix != (int)
myFoeLanes.size(); ++foe_ix) {
645 #ifdef MSLink_DEBUG_CROSSING_POINTS 652 if (dist == -10000.) {
656 #ifdef MSLink_DEBUG_CROSSING_POINTS 658 <<
"' at distance " << dist <<
" (approach along '" 719 for (
int i = 0; i < (int)
myFoeLanes.size(); ++i) {
725 const double crossingWidth = (sameTarget || sameSource) ? 0 : foeLane->
getWidth();
728 std::cout <<
" distToCrossing=" << distToCrossing <<
" foeLane=" << foeLane->
getID() <<
"\n";
730 if (distToCrossing + crossingWidth < 0) {
739 const bool contLane = (foeLane->
getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal());
741 const bool cannotIgnore = (contLane || sameTarget || sameSource) && ego != 0;
747 std::cout <<
" candiate leader=" << leader->
getID()
748 <<
" cannotIgnore=" << cannotIgnore
749 <<
" willPass=" << foeLane->
getLinkCont()[0]->getApproaching(leader).willPass
751 <<
" isOpposite=" << isOpposite <<
"\n";
763 bool fromLeft =
true;
768 gap = foeDistToCrossing - leaderBack;
772 distToCrossing += foeLane->
getWidth() / 2;
773 if (gap + foeCrossingWidth < 0) {
780 fromLeft = foeDistToCrossing > 0.5 * foeLane->
getLength();
781 }
else if ((contLane && !sameSource) || isOpposite) {
785 const double leaderBackDist = foeDistToCrossing - leaderBack;
787 std::cout <<
" distToCrossing=" << distToCrossing <<
" leader back=" << leaderBack <<
" backDist=" << leaderBackDist <<
"\n";
789 if (leaderBackDist + foeCrossingWidth < 0) {
797 std::cout <<
" leader=" << leader->
getID() <<
" contLane=" << contLane <<
" cannotIgnore=" << cannotIgnore <<
"\n";
801 const bool stopAsap = leader->
isFrontOnLane(foeLane) ? cannotIgnore : sameTarget;
802 result.push_back(
LinkLeader(leader, gap, stopAsap ? -1 : distToCrossing, fromLeft));
813 const double vehSideOffset = (foeDistToCrossing +
myLaneBefore->
getWidth() * 0.5 - vehWidth * 0.5
831 for (std::set<MSTransportable*>::const_iterator it = persons.begin(); it != persons.end(); ++it) {
834 if (collectBlockers != 0) {
835 collectBlockers->push_back(p);
844 const MSLane* foeLane = *it;
862 <<
" foeLane=" << foeLane->
getID()
863 <<
" leader=" << leader->
getID()
866 <<
" egoLat=" << posLat
867 <<
" leaderLat=" << posLatLeader
870 <<
" foeIndex=" << foeLane->
getIndex()
876 if ((posLat < posLatLeader && myInternalLaneBefore->
getIndex() > foeLane->
getIndex())
879 std::cout <<
SIMTIME <<
" blocked by " << leader->
getID() <<
" (sublane split) foeLane=" << foeLane->
getID() <<
"\n";
881 result.push_back(
LinkLeader(leader, gap, -1));
913 if (direction == -1) {
915 }
else if (direction == 1) {
928 if (before != 0 && after != 0) {
962 std::vector<const SUMOVehicle*>* collectFoes)
const {
969 throw ProcessError(
"Zipper junctions with more than two conflicting lanes are not supported (at junction '" 973 const double secondsToArrival =
STEPS2TIME(arrivalTime - now);
987 const double vSafeOrig = vSafe;
988 for (std::vector<const SUMOVehicle*>::const_iterator i = collectFoes->begin(); i != collectFoes->end(); ++i) {
1013 const double followInTime = vSafeOrig + (follow - vSafeOrig) /
MAX2((
double)1, secondsToArrival /
TS);
1014 vSafe =
MIN2(vSafe, followInTime);
1035 followDist > leaderDist &&
bool gDebugFlag1
global utility flags for debugging
double getMinGap() const
Get the free space in front of vehicles of this class.
static double gLateralResolution
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.
double getWidth() const
Returns the lane's width.
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 isLeader(const MSVehicle *ego, const MSVehicle *foe) const
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)
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
LinkState myState
The state of the link.
LinkLeaders getLeaderInfo(const MSVehicle *ego, double dist, std::vector< const MSPerson * > *collectBlockers=0, bool isShadowLink=false) const
Returns all potential link leaders (vehicles on foeLanes) Valid during the planMove() phase...
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
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.
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const =0
Computes the vehicle's follow speed (no dawdling)
const std::map< const SUMOVehicle *, ApproachingVehicleInformation > & getApproaching() const
return all approaching vehicles
double getLatOffset(const MSLane *lane) const
Get the offset that that must be added to interpret myState.myPosLat for the given lane...
double getInternalLengthsBefore() const
Returns the cumulative length of all internal lanes before this link.
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
double getLength() const
Returns the length of this link.
bool myHasFoes
Whether any foe links exist.
This is an uncontrolled, minor link, has to stop.
The base class for an intersection.
std::vector< MSLink * > mySublaneFoeLinks
MSLane * getViaLane() const
Returns the following inner lane.
std::vector< double > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
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)
LinkDirection myDirection
An abstract (hopefully human readable) definition of the link's direction.
static const double ZIPPER_ADAPT_DIST
double getLength() const
Returns the lane's length.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
bool blockedByFoe(const SUMOVehicle *veh, const ApproachingVehicleInformation &avi, SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed, bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime) const
static const SUMOTime myLookaheadTime
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
std::vector< std::pair< double, double > > myLengthsBehindCrossing
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.
double getLength() const
Returns the vehicle's length.
bool lastWasContMajor() const
whether this is a link past an internal junction which currently has priority
This is an uncontrolled, all-way stop link.
std::vector< MSLane * > mySublaneFoeLanes
bool fromInternalLane() const
return whether the fromLane of this link is an internal lane
void setApproaching(const SUMOVehicle *approaching, const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const bool setRequest, const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking, const SUMOTime waitingTime, double dist)
Sets the information about an approaching vehicle.
This is an uncontrolled, zipper-merge link.
MSAbstractLaneChangeModel & getLaneChangeModel()
MSLink * computeParallelLink(int direction)
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
SumoXMLEdgeFunc getFunction() const
Returns the edge type (SumoXMLEdgeFunc)
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
const MSLane * myInternalLaneBefore
bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const
Returns the information whether a vehicle is approaching on one of the link's foe streams...
int getIndex() const
Returns the respond index (for visualization)
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
double getZipperSpeed(const MSVehicle *ego, const double dist, double vSafe, SUMOTime arrivalTime, std::vector< const SUMOVehicle * > *collectFoes) const
return the speed at which ego vehicle must approach the zipper link
const MSVehicleType & getVehicleType() const
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
MSLink * getEntryLink() const
Returns the entry link if this is an internal lane, else 0.
const SUMOVTypeParameter & getParameter() const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Representation of a vehicle.
bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength, double impatience, double decel, SUMOTime waitingTime, double posLat=0, std::vector< const SUMOVehicle * > *collectFoes=0, bool ignoreRed=false, const SUMOVehicle *ego=0) const
Returns the information whether the link may be passed.
static bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel)
return whether the given vehicles may NOT merge safely
MSLink * getCorrespondingExitLink() const
returns the corresponding exit link for entryLinks to a junction.
static MSPModel * getModel()
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
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
static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle *follow, const MSVehicle *leader)
whether fllower could stay behind leader (possibly by braking)
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
bool isStopped() const
Returns whether the vehicle is at a stop.
std::pair< double, double > getLastIntersections(const MSLane *lane, const MSLane *foe)
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
std::vector< LinkLeader > LinkLeaders
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
void initParallelLinks()
initialize parallel links (to be called after all links are loaded)
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
virtual double getLateralPositionOnLane() const =0
Get the vehicle's lateral position on the lane.
int getIndex() const
Returns the lane's index.
bool isInternal() const
return whether this edge is an internal edge
double getJMParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
MSLink(MSLane *predLane, MSLane *succLane, MSLane *via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic *logic, int tlLinkIdx)
Constructor for simulation which uses internal lanes.
double getLength() const
Get vehicle's length [m].
static bool maybeOccupied(MSLane *lane)
returns whether the given lane may still be occupied by a vehicle currently on it ...
double getLengthsBeforeCrossing(const MSLane *foeLane) const
Returns the sum of the lengths along internal lanes following this link to the crossing with the give...
double getLengthBeforeCrossing(const MSLane *foeLane) const
Returns the internal length from the beginning of the link's internal lane before to the crossing wit...
bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed, bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime, std::vector< const SUMOVehicle * > *collectFoes=0, const SUMOVehicle *ego=0) const
Returns the information whether this link is blocked Valid after the vehicles have set their requests...
const MSLane * myWalkingAreaFoe
bool havePriority() const
Returns whether this link is a major link.
bool willHaveBlockedFoe() const
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...
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.
MSJunction * myJunction
the junction to which this link belongs
double getInternalLengthsAfter() const
Returns the cumulative length of all internal lanes after this link.
bool haveRed() const
Returns whether this link is blocked by a red (or redyellow) traffic light.
#define JM_CROSSING_GAP_DEFAULT
virtual const std::string & getID() const =0
Get the vehicle's ID.
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
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.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
AnyVehicleIterator anyVehiclesEnd() const
end iterator for iterating over all vehicles touching this lane in downstream direction ...
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.
const std::set< MSTransportable * > & getPersons() const
Returns this edge's persons set.
bool closeTag()
Closes the most recently opened tag.
MSLane *const myInternalLane
The following junction-internal lane if used.
static const double SAFETY_GAP
const MSJunction * getFromJunction() const
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
double interpolateGeometryPosToLanePos(double geometryPos) const
const double INVALID_DOUBLE
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
virtual bool blockedAtDist(const MSLane *lane, double vehSide, double vehWidth, double oncomingGap, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries ...
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)
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
SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const
return the expected time at which the given vehicle will clear the link
const std::string & getID() const
Returns the name of the vehicle.
double getSpeed() const
Returns the vehicle's current speed.