43 #ifdef CHECK_MEMORY_LEAKS
45 #endif // CHECK_MEMORY_LEAKS
57 #ifndef HAVE_INTERNAL_LANES
64 myState(state), myDirection(dir), myLength(length) {}
71 myState(state), myDirection(dir), myLength(length),
82 const std::vector<MSLink*>& foeLinks,
83 const std::vector<MSLane*>& foeLanes,
84 MSLane* internalLaneBefore) {
90 #ifdef HAVE_INTERNAL_LANES
91 if (internalLaneBefore != 0) {
93 for (std::vector<MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
96 myLengthsBehindCrossing.push_back(std::make_pair(0, 0));
100 if (intersections1.size() == 0) {
101 intersections1.push_back(0);
102 }
else if (intersections1.size() > 1) {
103 std::sort(intersections1.begin(), intersections1.end());
105 std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(internalLaneBefore->
getShape());
107 if (intersections2.size() == 0) {
108 intersections2.push_back(0);
109 }
else if (intersections2.size() > 1) {
110 std::sort(intersections2.begin(), intersections2.end());
112 myLengthsBehindCrossing.push_back(std::make_pair(
113 internalLaneBefore->
getLength() - intersections1.back(),
114 (*it_lane)->getLength() - intersections2.back()));
134 const bool setRequest,
const SUMOTime arrivalTimeBraking,
const SUMOReal arrivalSpeedBraking,
const SUMOTime waitingTime) {
138 arrivalTimeBraking, arrivalSpeedBraking, waitingTime)));
152 if ((*i)->isBlockingAnyone()) {
168 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
179 return arrivalTime +
TIME2STEPS((
getLength() + vehicleLength) / (0.5 * (arrivalSpeed + leaveSpeed)));
186 std::vector<const SUMOVehicle*>* collectFoes)
const {
205 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
206 impatience, decel, waitingTime, collectFoes)) {
217 std::vector<const SUMOVehicle*>* collectFoes)
const {
219 if (!i->second.willPass) {
223 assert(waitingTime > 0);
224 if (waitingTime > i->second.waitingTime) {
227 if (waitingTime == i->second.waitingTime && arrivalTime < i->second.arrivalTime) {
231 const SUMOTime foeArrivalTime = (
SUMOTime)((1.0 - impatience) * i->second.arrivalTime + impatience * i->second.arrivalTimeBraking);
232 if (i->second.leavingTime < arrivalTime) {
234 if (sameTargetLane && (arrivalTime - i->second.leavingTime <
myLookaheadTime
236 i->first->getVehicleType().getCarFollowModel().getMaxDecel(), decel))) {
237 if (collectFoes == 0) {
240 collectFoes->push_back(i->first);
243 }
else if (foeArrivalTime > leaveTime) {
247 decel, i->first->getVehicleType().getCarFollowModel().getMaxDecel()))) {
248 if (collectFoes == 0) {
251 collectFoes->push_back(i->first);
256 if (collectFoes == 0) {
259 collectFoes->push_back(i->first);
280 assert(distLeft > 0);
291 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
296 if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) {
324 #ifdef HAVE_INTERNAL_LANES
325 if (myJunctionInlane == 0 ||
myAmCont) {
335 assert(predLink != 0);
350 #ifdef HAVE_INTERNAL_LANES
351 const std::string via = getViaLane() == 0 ?
"" : getViaLane()->getID();
353 const std::string via =
"";
357 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
359 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
361 std::sort(toSort.begin(), toSort.end());
362 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
381 #ifdef HAVE_INTERNAL_LANES
383 MSLink::getViaLane()
const {
384 return myJunctionInlane;
395 for (
size_t i = 0; i <
myFoeLanes.size(); ++i) {
398 const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
400 if (distToCrossing < 0) {
403 const SUMOReal foeDistToCrossing = foeLane->
getLength() - myLengthsBehindCrossing[i].second;
412 const bool cannotIgnore = contLane || sameTarget;
415 for (MSLane::VehCont::const_iterator it_veh = vehicles.begin(); it_veh != vehicles.end(); ++it_veh) {
425 const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
427 if (leaderBackDist < 0) {
432 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
434 result.push_back(std::make_pair(std::make_pair(leader, gap), sameTarget ? -1 : distToCrossing));
449 if (leaderBackDist < 0) {
454 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
456 result.push_back(std::make_pair(std::make_pair(leader, gap), sameTarget ? -1 : distToCrossing));
468 #ifdef HAVE_INTERNAL_LANES
469 if (myJunctionInlane != 0) {
470 return myJunctionInlane;
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
MSEdge & getEdge() const
Returns the lane's edge.
Representation of a vehicle in the micro simulation.
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.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
This is an uncontrolled, minor link, has to stop.
SUMOReal getLength() const
Returns the lane's length.
std::vector< MSLink * > myFoeLinks
bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel=DEFAULT_VEH_DECEL) const
Returns the information whether a vehicle is approaching on one of the link's foe streams...
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.
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)...
MSLane * getLogicalPredecessorLane() const
unsigned int myIndex
The position within this respond.
Representation of a vehicle.
MSLane * getLane() const
Returns the connected lane.
bool myIsCrossing
Whether any foe links 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.
void setRequestInformation(unsigned int index, bool isCrossing, bool isCont, const std::vector< MSLink * > &foeLinks, const std::vector< MSLane * > &foeLanes, MSLane *internalLaneBefore=0)
Sets the request information.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
virtual 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
The link has red light (must brake)
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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 isCrossing() const
Returns whether this link belongs to a junction where more than one edge is incoming.
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.
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
std::vector< std::pair< std::pair< MSVehicle *, SUMOReal >, SUMOReal > > LinkLeaders
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
SUMOTime getLeaveTime(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const
return the expected time at which the given vehicle will clear the link
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.