46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
61 #ifndef HAVE_INTERNAL_LANES
80 myJunctionInlane(via),
91 const std::vector<MSLink*>& foeLinks,
92 const std::vector<MSLane*>& foeLanes,
93 MSLane* internalLaneBefore) {
100 #ifdef MSLink_DEBUG_CROSSING_POINTS
103 #ifdef HAVE_INTERNAL_LANES
105 if (internalLaneBefore != 0) {
107 lane = internalLaneBefore;
114 for (std::vector<MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
118 myLengthsBehindCrossing.push_back(std::make_pair(0, 0));
119 #ifdef MSLink_DEBUG_CROSSING_POINTS
121 <<
" " << lane->
getID()
122 <<
" merges with " << (*it_lane)->getID()
123 <<
" nextLane " << lane->
getLinkCont()[0]->getViaLaneOrLane()->getID()
124 <<
" dist1=" << myLengthsBehindCrossing.back().first
125 <<
" dist2=" << myLengthsBehindCrossing.back().second
131 if (intersections1.size() == 0) {
132 intersections1.push_back(10000.0);
133 }
else if (intersections1.size() > 1) {
134 std::sort(intersections1.begin(), intersections1.end());
136 std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(lane->
getShape());
138 if (intersections2.size() == 0) {
139 intersections2.push_back(0);
140 }
else if (intersections2.size() > 1) {
141 std::sort(intersections2.begin(), intersections2.end());
143 myLengthsBehindCrossing.push_back(std::make_pair(
144 lane->
getLength() - intersections1.back(),
145 (*it_lane)->getLength() - intersections2.back()));
146 #ifdef MSLink_DEBUG_CROSSING_POINTS
148 <<
" intersection of " << lane->
getID()
150 <<
" with " << (*it_lane)->getID()
151 <<
" totalLength=" << (*it_lane)->getLength()
152 <<
" dist1=" << myLengthsBehindCrossing.back().first
153 <<
" dist2=" << myLengthsBehindCrossing.back().second
167 const bool setRequest,
const SUMOTime arrivalTimeBraking,
const SUMOReal arrivalSpeedBraking,
const SUMOTime waitingTime) {
171 arrivalTimeBraking, arrivalSpeedBraking, waitingTime)));
185 if ((*i)->isBlockingAnyone()) {
201 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
220 std::vector<const SUMOVehicle*>* collectFoes)
const {
234 if ((*i)->haveRed()) {
239 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
240 impatience, decel, waitingTime, collectFoes)) {
251 std::vector<const SUMOVehicle*>* collectFoes)
const {
253 if (!i->second.willPass) {
257 assert(waitingTime > 0);
258 if (waitingTime > i->second.waitingTime) {
261 if (waitingTime == i->second.waitingTime && arrivalTime < i->second.arrivalTime) {
265 const SUMOTime foeArrivalTime = (
SUMOTime)((1.0 - impatience) * i->second.arrivalTime + impatience * i->second.arrivalTimeBraking);
266 if (i->second.leavingTime < arrivalTime) {
268 if (sameTargetLane && (arrivalTime - i->second.leavingTime <
myLookaheadTime
270 i->first->getVehicleType().getCarFollowModel().getMaxDecel(), decel))) {
271 if (collectFoes == 0) {
274 collectFoes->push_back(i->first);
277 }
else if (foeArrivalTime > leaveTime) {
281 decel, i->first->getVehicleType().getCarFollowModel().getMaxDecel()))) {
282 if (collectFoes == 0) {
285 collectFoes->push_back(i->first);
290 if (collectFoes == 0) {
293 collectFoes->push_back(i->first);
314 assert(distLeft > 0);
325 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
330 if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) {
358 #ifdef HAVE_INTERNAL_LANES
359 if (myJunctionInlane == 0 ||
myAmCont) {
369 assert(predLink != 0);
384 #ifdef HAVE_INTERNAL_LANES
385 const std::string via = getViaLane() == 0 ?
"" : getViaLane()->getID();
387 const std::string via =
"";
391 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
393 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
395 std::sort(toSort.begin(), toSort.end());
396 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
415 #ifdef HAVE_INTERNAL_LANES
417 MSLink::getViaLane()
const {
418 return myJunctionInlane;
423 MSLink::getLeaderInfo(
SUMOReal dist,
SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers)
const {
428 || (myJunctionInlane != 0 && myJunctionInlane->getLogicalPredecessorLane()->getEdge().isInternal()))) {
431 for (
size_t i = 0; i <
myFoeLanes.size(); ++i) {
434 const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
436 if (distToCrossing < 0) {
439 const SUMOReal foeDistToCrossing = foeLane->
getLength() - myLengthsBehindCrossing[i].second;
448 const bool cannotIgnore = contLane || sameTarget;
451 for (MSLane::VehCont::const_iterator it_veh = vehicles.begin(); it_veh != vehicles.end(); ++it_veh) {
461 const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
463 if (leaderBackDist < 0) {
468 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
470 result.push_back(LinkLeader(leader, gap, cannotIgnore ? -1 : distToCrossing));
485 if (leaderBackDist < 0) {
490 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
492 result.push_back(LinkLeader(leader, gap, sameTarget ? -1 : distToCrossing));
498 result.push_back(LinkLeader((
MSVehicle*)0, -1, distToPeds));
509 #ifdef HAVE_INTERNAL_LANES
510 if (myJunctionInlane != 0) {
511 return myJunctionInlane;
const MSJunction * myJunction
the junction to which this link belongs
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.
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
MSLane * myLane
The lane approached by this link.
void addBlockedLink(MSLink *link)
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
LinkState myState
The state of the link.
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
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.
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.
std::vector< MSLink * > myFoeLinks
void setTLState(LinkState state, SUMOTime t)
Sets the current tl-state.
std::vector< MSVehicle * > VehCont
Container for vehicles.
std::string time2string(SUMOTime t)
SUMOReal getLength() const
Get vehicle's length [m].
LinkDirection myDirection
An abstract (hopefully human readable) definition of the link's direction.
SUMOReal getWidth() const
Returns the lane's width.
LinkDirection getDirection() const
Returns the direction the vehicle passing this link take.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
std::map< const SUMOVehicle *, ApproachingVehicleInformation > myApproachingVehicles
bool lastWasContMajor() const
whether this is a link past an internal junction which currently has priority
This is an uncontrolled, all-way stop link.
#define UNUSED_PARAMETER(x)
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...
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
SUMOReal getPartialOccupatorEnd() const
Returns the position of the in-lapping vehicle's end.
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.
MSLane * getLogicalPredecessorLane() const
Representation of a vehicle.
static MSPModel * getModel()
MSLane * getLane() const
Returns the connected lane.
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.
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].
MSVehicle * getLastVehicle() const
returns the last vehicle
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
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)
std::vector< MSLane * > myFoeLanes
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
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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
static SUMOTime gIgnoreJunctionBlocker
Information whether the simulation regards internal lanes.
const PositionVector & getShape() const
Returns this lane's shape.
MSLink(MSLane *succLane, LinkDirection dir, LinkState state, SUMOReal length)
Constructor for simulation not using internal lanes.
MSVehicle * getPartialOccupator() const
Returns the vehicle which laps into this lane.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
static const bool gUseMesoSim
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)
Sets the information about an approaching vehicle.
const MSJunction * getFromJunction() const
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
The 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 SUMOTime myLookaheadTime
Representation of a lane in the micro simulation.
bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime, std::vector< const SUMOVehicle * > *collectFoes=0) const
Returns the information whether the link may be passed.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.