60 #define ZIPPER_ADAPT_TIME 10 62 #define INVALID_DOUBLE std::numeric_limits<double>::max() 69 myLaneBefore(predLane),
77 myFoeVisibilityDistance(foeVisibilityDistance),
80 myKeepClear(keepClear),
82 myInternalLaneBefore(0),
96 const std::vector<MSLink*>& foeLinks,
97 const std::vector<MSLane*>& foeLanes,
98 MSLane* internalLaneBefore) {
108 for (std::vector<MSLane*>::const_iterator it_lane = foeLanes.begin(); it_lane != foeLanes.end(); ++it_lane) {
115 if (internalLaneBefore != 0) {
117 lane = internalLaneBefore;
123 #ifdef MSLink_DEBUG_CROSSING_POINTS 127 const bool beforeInternalJunction = lane->
getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
130 for (std::vector<const MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
132 if (sameTarget && !beforeInternalJunction) {
136 #ifdef MSLink_DEBUG_CROSSING_POINTS 138 <<
" " << lane->
getID()
139 <<
" merges with " << (*it_lane)->getID()
140 <<
" nextLane " << lane->
getLinkCont()[0]->getViaLaneOrLane()->getID()
147 #ifdef MSLink_DEBUG_CROSSING_POINTS 150 bool haveIntersection =
true;
151 if (intersections1.size() == 0) {
152 intersections1.push_back(-10000.0);
153 haveIntersection =
false;
154 }
else if (intersections1.size() > 1) {
155 std::sort(intersections1.begin(), intersections1.end());
157 std::vector<double> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->
getShape());
158 #ifdef MSLink_DEBUG_CROSSING_POINTS 161 if (intersections2.size() == 0) {
162 intersections2.push_back(0);
163 }
else if (intersections2.size() > 1) {
164 std::sort(intersections2.begin(), intersections2.end());
166 if (haveIntersection) {
168 intersections1.back() -= (*it_lane)->getWidth() / 2;
169 intersections2.back() -= lane->
getWidth() / 2;
172 intersections2.back() = (*it_lane)->interpolateGeometryPosToLanePos(intersections2.back());
177 intersections1.back() = 0;
182 lane->
getLength() - intersections1.back(),
183 (*it_lane)->getLength() - intersections2.back()));
185 #ifdef MSLink_DEBUG_CROSSING_POINTS 187 <<
" intersection of " << lane->
getID()
189 <<
" with " << (*it_lane)->getID()
190 <<
" totalLength=" << (*it_lane)->getLength()
202 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
203 const MSLane* sibling = (*it)->getViaLane();
204 if (sibling != lane && sibling != 0) {
206 #ifdef MSLink_DEBUG_CROSSING_POINTS 209 if (intersections1.size() > 0) {
210 std::sort(intersections1.begin(), intersections1.end());
214 lane->
getLength() - intersections1.back(),
215 sibling->
getLength() - intersections1.back()));
217 #ifdef MSLink_DEBUG_CROSSING_POINTS 218 std::cout <<
" adding same-origin foe" << sibling->
getID()
232 for (MSLinkCont::const_iterator it = predLinks.begin(); it != predLinks.end(); ++it) {
233 const MSEdge* target = &((*it)->getLane()->getEdge());
234 if (*it !=
this && target == myTarget) {
242 std::pair<double, double>
247 const bool setRequest,
const SUMOTime arrivalTimeBraking,
const double arrivalSpeedBraking,
const SUMOTime waitingTime,
double dist) {
251 arrivalTimeBraking, arrivalSpeedBraking, waitingTime, dist)));
265 if ((*i)->isBlockingAnyone()) {
281 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
292 const double leaveSpeed,
const double vehicleLength)
const {
299 double impatience,
double decel,
SUMOTime waitingTime,
double posLat,
300 std::vector<const SUMOVehicle*>* collectFoes)
const {
311 const MSLink* foeLink = *it;
320 && (arrivalTime > i->second.arrivalTime
324 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
false,
325 impatience, decel, waitingTime)) {
327 if (collectFoes == 0) {
331 collectFoes->push_back(i->first);
342 return collectFoes == 0 || collectFoes->size() == 0;
349 if ((*i)->haveRed()) {
353 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
354 impatience, decel, waitingTime, collectFoes)) {
358 if (collectFoes != 0 && collectFoes->size() > 0) {
367 bool sameTargetLane,
double impatience,
double decel,
SUMOTime waitingTime,
368 std::vector<const SUMOVehicle*>* collectFoes)
const {
370 if (
blockedByFoe(i->first, i->second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, sameTargetLane,
371 impatience, decel, waitingTime)) {
372 if (collectFoes == 0) {
375 collectFoes->push_back(i->first);
385 bool sameTargetLane,
double impatience,
double decel,
SUMOTime waitingTime)
const {
390 assert(waitingTime > 0);
402 if (sameTargetLane && (arrivalTime - avi.
leavingTime < lookAhead
407 }
else if (foeArrivalTime > leaveTime) {
409 if (sameTargetLane && (foeArrivalTime - leaveTime < lookAhead
430 assert(distLeft > 0);
441 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
445 for (std::vector<const MSLane*>::const_iterator i =
myFoeLanes.begin(); i !=
myFoeLanes.end(); ++i) {
446 if ((*i)->getVehicleNumberWithPartials() > 0) {
486 assert(predLink != 0);
501 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
503 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
505 std::sort(toSort.begin(), toSort.end());
506 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
548 assert(foeEntryLane != 0);
552 assert(egoEntryLane != 0);
556 for (std::vector<const MSLane*>::const_iterator i =
myFoeLanes.begin(); i !=
myFoeLanes.end(); ++i) {
557 if (*i == foeEntryLane) {
569 #ifdef MSLink_DEBUG_CROSSING_POINTS 572 <<
"\nLength on toString(getLaneBefore()) before crossing = " << res
580 MSLane* contLane = contLink->getViaLane();
586 #ifdef MSLink_DEBUG_CROSSING_POINTS 587 std::cout <<
"No crossing with entryLane.\nChecking crossing of contLane '" << contLane->
getID()
634 for (
int i = 0; i < (int)
myFoeLanes.size(); ++i) {
640 const double crossingWidth = (sameTarget || sameSource) ? 0 : foeLane->
getWidth();
643 std::cout <<
" distToCrossing=" << distToCrossing <<
" foeLane=" << foeLane->
getID() <<
"\n";
645 if (distToCrossing + crossingWidth < 0) {
656 const bool cannotIgnore = contLane || sameTarget || sameSource;
662 std::cout <<
" candiate leader=" << leader->
getID()
663 <<
" cannotIgnore=" << cannotIgnore
664 <<
" willPass=" << foeLane->
getLinkCont()[0]->getApproaching(leader).willPass
666 <<
" isOpposite=" << isOpposite <<
"\n";
668 if (!cannotIgnore && !foeLane->
getLinkCont()[0]->getApproaching(leader).willPass && leader->
isFrontOnLane(foeLane) && !isOpposite) {
675 if ((contLane && !sameSource) || isOpposite) {
679 const double leaderBackDist = foeDistToCrossing - leaderBack;
681 std::cout <<
" distToCrossing=" << distToCrossing <<
" leader back=" << leaderBack <<
" backDist=" << leaderBackDist <<
"\n";
683 if (leaderBackDist + foeCrossingWidth < 0) {
691 std::cout <<
" leader=" << leader->
getID() <<
" contLane=" << contLane <<
" cannotIgnore=" << cannotIgnore <<
"\n";
695 const bool stopAsap = leader->
isFrontOnLane(foeLane) ? cannotIgnore : sameTarget;
696 result.push_back(
LinkLeader(leader, gap, stopAsap ? -1 : distToCrossing));
702 if (distToPeds >= -MSPModel::SAFETY_GAP &&
MSPModel::getModel()->blockedAtDist(foeLane, foeDistToCrossing, collectBlockers)) {
733 if (direction == -1) {
735 }
else if (direction == 1) {
748 if (before != 0 && after != 0) {
782 std::vector<const SUMOVehicle*>* collectFoes)
const {
789 throw ProcessError(
"Zipper junctions with more than two conflicting lanes are not supported (at junction '" 793 const double secondsToArrival =
STEPS2TIME(arrivalTime - now);
807 const double vSafeOrig = vSafe;
808 for (std::vector<const SUMOVehicle*>::const_iterator i = collectFoes->begin(); i != collectFoes->end(); ++i) {
833 const double followInTime = vSafeOrig + (follow - vSafeOrig) /
MAX2((
double)1, secondsToArrival /
TS);
834 vSafe =
MIN2(vSafe, followInTime);
855 followDist > leaderDist &&
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
bool gDebugFlag1
global utility flags for debugging
static double gLateralResolution
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 ...
int myIndex
The position within this respond.
MSEdge & getEdge() const
Returns the lane's edge.
Representation of a vehicle in the micro simulation.
MSLane * myLane
The lane behind the junction approached by this link.
void addBlockedLink(MSLink *link)
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.
MSLane * getLane() const
Returns the connected lane.
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) const
Returns the information whether the link may be passed.
MSLane * getLane() const
Returns the lane the vehicle is on.
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)
bool myHasFoes
Whether any foe links exist.
This is an uncontrolled, minor link, has to stop.
LinkLeaders getLeaderInfo(const MSVehicle *ego, double dist, std::vector< const MSPerson *> *collectBlockers=0) const
Returns all potential link leaders (vehicles on foeLanes) Valid during the planMove() phase...
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
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.
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
static const double ZIPPER_ADAPT_DIST
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static const SUMOTime myLookaheadTime
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
double getLength() const
Returns the lane's length.
const PositionVector & getShape() const
Returns this lane's shape.
std::vector< std::pair< double, double > > myLengthsBehindCrossing
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.
double getInternalLengthsAfter() const
Returns the cumulative length of all internal lanes after this link.
This is an uncontrolled, all-way stop link.
double getWidth() const
Returns the lane's width.
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.
bool isLeader(const MSVehicle *ego, const MSVehicle *foe) const
bool isInternalJunctionLink() const
return whether the fromLane and the toLane of this link are internal lanes
This is an uncontrolled, zipper-merge link.
MSAbstractLaneChangeModel & getLaneChangeModel()
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.
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
double getLengthBeforeCrossing(const MSLink *foeEntryLink) const
Returns the complete internal lengths from the link until the crossing point with the given foe link'...
const MSLane * myInternalLaneBefore
bool lastWasContMajor() const
whether this is a link past an internal junction which currently has priority
A road/street connecting two junctions.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
int getIndex() const
Returns the lane's index.
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 MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
MSLane * getViaLane() const
Returns the following inner lane.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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 bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel)
return whether the given vehicles may NOT merge safely
static MSPModel * getModel()
double interpolateGeometryPosToLanePos(double geometryPos) const
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
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)
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.
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.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
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
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 ...
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
void initParallelLinks()
initialize parallel links (to be called after all links are loaded)
bool isInternal() const
return whether this edge is an internal edge
double getLength() const
Returns the length of this link.
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.
static bool maybeOccupied(MSLane *lane)
returns whether the given lane may still be occupied by a vehicle currently on it ...
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
Returns the information whether this link is blocked Valid after the vehicles have set their requests...
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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.
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
virtual double getLateralPositionOnLane() const =0
Get the vehicle's lateral position on the lane.
double getLength() const
Get vehicle's length [m].
static SUMOTime gIgnoreJunctionBlocker
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
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.
MSLane *const myInternalLane
The following junction-internal lane if used.
static const double SAFETY_GAP
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
const std::map< const SUMOVehicle *, ApproachingVehicleInformation > & getApproaching() const
return all approaching vehicles
double getSpeed() const
Returns the vehicle's current speed.
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.
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders of this links junction
bool haveRed() const
Returns whether this link is blocked by a red (or redyellow) traffic light.
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.
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.
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...
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.