43 #ifdef CHECK_MEMORY_LEAKS
45 #endif // CHECK_MEMORY_LEAKS
57 #ifndef HAVE_INTERNAL_LANES
63 myRequestIdx(0), myRespondIdx(0),
64 myState(state), myDirection(dir), myLength(length) {}
70 myRequestIdx(0), myRespondIdx(0),
71 myState(state), myDirection(dir), myLength(length),
82 const std::vector<MSLink*>& foeLinks,
83 const std::vector<MSLane*>& foeLanes,
84 MSLane* internalLaneBefore) {
91 #ifdef HAVE_INTERNAL_LANES
92 if (internalLaneBefore != 0) {
94 for (std::vector<MSLane*>::const_iterator it_lane =
myFoeLanes.begin(); it_lane !=
myFoeLanes.end(); ++it_lane) {
97 myLengthsBehindCrossing.push_back(std::make_pair(0, 0));
101 if (intersections1.size() == 0) {
102 intersections1.push_back(0);
103 }
else if (intersections1.size() > 1) {
104 std::sort(intersections1.begin(), intersections1.end());
106 std::vector<SUMOReal> intersections2 = (*it_lane)->getShape().intersectsAtLengths2D(internalLaneBefore->
getShape());
108 if (intersections2.size() == 0) {
109 intersections2.push_back(0);
110 }
else if (intersections2.size() > 1) {
111 std::sort(intersections2.begin(), intersections2.end());
113 myLengthsBehindCrossing.push_back(std::make_pair(
114 internalLaneBefore->
getLength() - intersections1.back(),
115 (*it_lane)->getLength() - intersections2.back()));
135 const bool setRequest,
const SUMOTime arrivalTimeBraking,
const SUMOReal arrivalSpeedBraking,
const SUMOTime waitingTime) {
139 arrivalTimeBraking, arrivalSpeedBraking, waitingTime)));
153 if ((*i)->isBlockingAnyone()) {
169 std::map<const SUMOVehicle*, ApproachingVehicleInformation>::const_iterator i =
myApproachingVehicles.find(veh);
180 return arrivalTime +
TIME2STEPS((
getLength() + vehicleLength) / (0.5 * (arrivalSpeed + leaveSpeed)));
187 std::vector<const SUMOVehicle*>* collectFoes)
const {
206 if ((*i)->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed,
myLane == (*i)->getLane(),
207 impatience, decel, waitingTime, collectFoes)) {
218 std::vector<const SUMOVehicle*>* collectFoes)
const {
220 if (!i->second.willPass) {
224 assert(waitingTime > 0);
225 if (waitingTime > i->second.waitingTime) {
228 if (waitingTime == i->second.waitingTime && arrivalTime < i->second.arrivalTime) {
232 const SUMOTime foeArrivalTime = (
SUMOTime)((1.0 - impatience) * i->second.arrivalTime + impatience * i->second.arrivalTimeBraking);
233 if (i->second.leavingTime < arrivalTime) {
235 if (sameTargetLane && (arrivalTime - i->second.leavingTime <
myLookaheadTime
237 i->first->getVehicleType().getCarFollowModel().getMaxDecel(), decel))) {
238 if (collectFoes == 0) {
241 collectFoes->push_back(i->first);
244 }
else if (foeArrivalTime > leaveTime) {
248 decel, i->first->getVehicleType().getCarFollowModel().getMaxDecel()))) {
249 if (collectFoes == 0) {
252 collectFoes->push_back(i->first);
257 if (collectFoes == 0) {
260 collectFoes->push_back(i->first);
281 assert(distLeft > 0);
292 if ((*i)->blockedAtTime(arrivalTime, leaveTime, speed, speed,
myLane == (*i)->getLane(), 0, decel, 0)) {
297 if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) {
328 #ifdef HAVE_INTERNAL_LANES
329 const std::string via = getViaLane() == 0 ?
"" : getViaLane()->getID();
331 const std::string via =
"";
335 std::vector<std::pair<SUMOTime, const SUMOVehicle*> > toSort;
337 toSort.push_back(std::make_pair(it->second.arrivalTime, it->first));
339 std::sort(toSort.begin(), toSort.end());
340 for (std::vector<std::pair<SUMOTime, const SUMOVehicle*> >::const_iterator it = toSort.begin(); it != toSort.end(); ++it) {
356 #ifdef HAVE_INTERNAL_LANES
358 MSLink::getViaLane()
const {
359 return myJunctionInlane;
370 for (
size_t i = 0; i <
myFoeLanes.size(); ++i) {
373 const SUMOReal distToCrossing = dist - myLengthsBehindCrossing[i].first;
375 if (distToCrossing < 0) {
378 const SUMOReal foeDistToCrossing = foeLane->
getLength() - myLengthsBehindCrossing[i].second;
387 const bool cannotIgnore = contLane || sameTarget;
390 for (MSLane::VehCont::const_iterator it_veh = vehicles.begin(); it_veh != vehicles.end(); ++it_veh) {
400 const SUMOReal leaderBackDist = foeDistToCrossing - leaderBack;
402 if (leaderBackDist < 0) {
407 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
409 result.push_back(std::make_pair(leader, gap));
424 if (leaderBackDist < 0) {
429 gap = distToCrossing - leaderBackDist - (sameTarget ? minGap : 0);
431 result.push_back(std::make_pair(leader, gap));
443 #ifdef HAVE_INTERNAL_LANES
444 if (myJunctionInlane != 0) {
445 return myJunctionInlane;
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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].
std::vector< std::pair< MSVehicle *, SUMOReal > > LinkLeaders
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
This is an uncontrolled, all-way stop link.
#define UNUSED_PARAMETER(x)
unsigned int myRequestIdx
The position of the link within this request.
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)...
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.
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 ...
std::vector< MSLane * > myFoeLanes
bool willHaveBlockedFoe() const
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.
void setRequestInformation(unsigned int requestIdx, unsigned int respondIdx, bool isCrossing, bool isCont, const std::vector< MSLink * > &foeLinks, const std::vector< MSLane * > &foeLanes, MSLane *internalLaneBefore=0)
Sets the request information.
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.
unsigned int myRespondIdx
The position within this respond.
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
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.
unsigned int getRespondIndex() const
Returns the respond index (for visualization)
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.