48 #ifdef CHECK_MEMORY_LEAKS 50 #endif // CHECK_MEMORY_LEAKS 57 : myAllowsSwap(allowSwap) {
58 assert(lanes->size() > 1);
62 for (std::vector<MSLane*>::const_iterator lane = lanes->begin(); lane != lanes->end(); ++lane) {
67 ce.
veh = (*lane)->myVehicles.rbegin();
87 bool haveChanged =
change();
101 ce->firstBlocked = 0;
105 if (vehicles.empty()) {
106 ce->veh = vehicles.rend();
110 ce->veh = vehicles.rbegin();
111 if (vehicles.size() == 1) {
115 ce->follow = *(vehicles.rbegin() + 1);
131 #ifdef DEBUG_VEHICLE_GUI_SELECTION 147 for (
int i = 0; i < (int)
myChanger.size(); ++i) {
150 const std::vector<MSVehicle::LaneQ>& preb = vehicle->
getBestLanes();
156 bool changingAllowed1 = (state1 &
LCA_BLOCKED) == 0;
158 if ((state1 &
LCA_RIGHT) != 0 && changingAllowed1) {
162 if ((state1 & LCA_RIGHT) != 0 && (state1 &
LCA_URGENT) != 0) {
163 (
myCandi - 1)->lastBlocked = vehicle;
164 if ((
myCandi - 1)->firstBlocked == 0) {
165 (
myCandi - 1)->firstBlocked = vehicle;
176 bool changingAllowed2 = (state2 &
LCA_BLOCKED) == 0;
178 if ((state2 &
LCA_LEFT) != 0 && changingAllowed2) {
182 if ((state2 & LCA_LEFT) != 0 && (state2 &
LCA_URGENT) != 0) {
183 (
myCandi + 1)->lastBlocked = vehicle;
184 if ((
myCandi + 1)->firstBlocked == 0) {
185 (
myCandi + 1)->firstBlocked = vehicle;
213 if (target->hoppedVeh != 0) {
214 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
233 MSLane::VehCont::iterator i = find(target->lane->myTmpVehicles.begin(), target->lane->myTmpVehicles.end(), prohibitor);
234 if (i != target->lane->myTmpVehicles.end()) {
235 assert(*i == prohibitor);
236 target->lane->myTmpVehicles.erase(i);
238 target->hoppedVeh = vehicle;
239 target->lane->myTmpVehicles.insert(target->lane->myTmpVehicles.begin(), vehicle);
240 myCandi->hoppedVeh = prohibitor;
241 myCandi->lane->myTmpVehicles.insert(
myCandi->lane->myTmpVehicles.begin(), prohibitor);
282 to->hoppedVeh = vehicle;
285 to->lane->myTmpVehicles.insert(to->lane->myTmpVehicles.begin(), vehicle);
288 from->lane->myTmpVehicles.insert(from->lane->myTmpVehicles.begin(), vehicle);
291 to->dens += to->hoppedVeh->getVehicleType().getLengthWithGap();
295 std::pair<MSVehicle* const, SUMOReal>
300 if (target->hoppedVeh != 0) {
301 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
303 neighLead = target->hoppedVeh;
306 if (neighLead == 0) {
307 MSLane* targetLane = target->lane;
316 return std::pair<MSVehicle* const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
319 return target->lane->getLeaderOnConsecutive(dist, seen, speed, *
veh(
myCandi), bestLaneConts);
327 std::pair<MSVehicle* const, SUMOReal>
331 if (target->hoppedVeh != 0) {
332 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
334 neighFollow = target->hoppedVeh;
337 if (neighFollow == 0) {
339 return target->lane->getFollowerOnConsecutive(
344 return std::pair<MSVehicle* const, SUMOReal>(neighFollow,
390 ce->lane->swapAfterLaneChange(t);
409 assert(
veh(ce) != 0);
410 assert(
veh(max) != 0);
411 if (
veh(max)->getPositionOnLane() <
veh(ce)->getPositionOnLane()) {
416 assert(
veh(max) != 0);
423 const std::pair<MSVehicle* const, SUMOReal>& leader,
424 const std::vector<MSVehicle::LaneQ>& preb)
const {
433 if (neighFollow.first != 0 && neighFollow.second < 0) {
436 if (neighLead.first != 0 && neighLead.second < 0) {
440 if (neighFollow.first != 0) {
443 blocked |= blockedByFollower;
448 if (neighLead.first != 0) {
451 blocked |= blockedByLeader;
457 laneOffset, msg, blocked, leader, neighLead, neighFollow, *(target->lane), preb, &(
myCandi->lastBlocked), &(
myCandi->firstBlocked));
467 std::pair<MSVehicle* const, SUMOReal> neighLead2 = targetLane->
getCriticalLeader(dist, seen, speed, *vehicle);
468 if (neighLead2.first != 0 && neighLead2.first != neighLead.first
470 vehicle->
getSpeed(), neighLead2.first->getSpeed(), neighLead2.first->getCarFollowModel().getMaxDecel()))) {
471 state |= blockedByLeader;
484 unsigned int view = 1;
486 MSLinkCont::const_iterator link =
MSLane::succLinkSec(*vehicle, view, *nextLane, bestLaneConts);
487 while (!nextLane->
isLinkEnd(link) && seen <= space2change) {
491 || (nextLane->
getEdge().
isInternal() && (*link)->getViaLaneOrLane()->getEdge().isInternal())
496 #ifdef HAVE_INTERNAL_LANES 497 if ((*link)->getViaLane() == 0) {
503 nextLane = (*link)->getViaLaneOrLane();
509 if ((state & LCA_BLOCKED) == 0) {
517 MSLinkCont::const_iterator link =
MSLane::succLinkSec(*vehicle, view, *nextLane, bestLaneConts);
518 while (!nextLane->
isLinkEnd(link) && seen <= space2change && seen <= dist) {
519 nextLane = (*link)->getViaLaneOrLane();
521 if (targetLane == 0) {
525 std::pair<MSVehicle* const, SUMOReal> neighLead2 = targetLane->
getLeader(vehicle, -seen,
true);
526 if (neighLead2.first != 0 && neighLead2.first != neighLead.first
528 vehicle->
getSpeed(), neighLead2.first->getSpeed(), neighLead2.first->getCarFollowModel().getMaxDecel()))) {
529 state |= blockedByLeader;
533 #ifdef HAVE_INTERNAL_LANES 534 if ((*link)->getViaLane() == 0) {
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
MSVehicle * firstBlocked
the first vehicle on this edge that wants to change to this lane
MSEdge & getEdge() const
Returns the lane's edge.
Representation of a vehicle in the micro simulation.
bool isLinkEnd(MSLinkCont::const_iterator &i) const
MSLane * lane
the lane the vehicle is on
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
State myState
This Vehicles driving state (pos and speed)
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
std::pair< MSVehicle *const, SUMOReal > getRealLeader(const ChangerIt &target) const
bool hasInfluencer() const
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
MSLane::VehCont::reverse_iterator veh
the regarded vehicle
bool isVTDControlled() const
void initChanger()
Initialize the changer before looping over all vehicles.
SUMOReal getLength() const
Returns the lane's length.
std::vector< MSVehicle * > VehCont
Container for vehicles.
SUMOReal getLength() const
Get vehicle's length [m].
MSVehicle * veh(ConstChangerIt ce) const
SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum.
SUMOReal mySpeed
the stored speed
void startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0) ...
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
std::pair< MSVehicle *const, SUMOReal > getCriticalLeader(SUMOReal dist, SUMOReal seen, SUMOReal speed, const MSVehicle &veh) const
Returns the most dangerous leader and the distance to him.
MSVehicle * lead
the vehicle in front of the current vehicle
The action is urgent (to be defined by lc-model)
MSVehicle * follow
the vehicle following the current vehicle
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
The link is a (hard) left direction.
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, unsigned int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
MSAbstractLaneChangeModel & getLaneChangeModel()
std::string gDebugSelectedVehicle
SUMOReal getPartialOccupatorEnd() const
Returns the position of the in-lapping vehicle's end.
A class responsible for exchanging messages between cars involved in lane-change interaction.
The vehicle changes lanes (micro only)
std::pair< MSVehicle *const, SUMOReal > getRealFollower(const ChangerIt &target) const
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time.
void updateChanger(bool vehHasChanged)
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the subpart of best lanes that describes the vehicle's current lane and their successors...
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
void setOwnState(int state)
The vehicle is blocked by left follower.
The link is a (hard) right direction.
std::pair< MSVehicle *const, SUMOReal > getLeader(const MSVehicle *veh, const SUMOReal vehPos, bool checkNext) const
Returns the immediate leader of veh and the distance to veh starting on this lane.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
MSLaneChanger()
Default constructor.
int checkChange(int laneOffset, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
bool isInternal() const
return whether this edge is an internal edge
void updateLanes(SUMOTime t)
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
MSVehicle * lastBlocked
the vehicle that really wants to change to this lane
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
void leaveLane(const MSMoveReminder::Notification reason)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
Influencer & getInfluencer()
Returns the velocity/lane influencer.
bool myAllowsSwap
Whether blocking vehicles may be swapped.
~MSLaneChanger()
Destructor.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
SUMOReal getSpeed() const
Returns the vehicle's current speed.
virtual void changed(int dir)=0
SUMOReal myPos
the stored position
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
MSVehicle * getPartialOccupator() const
Returns the vehicle which laps into this lane.
void registerUnchanged(MSVehicle *vehicle)
The vehicle is blocked by right follower.
void adaptBestLanesOccupation(int laneIndex, SUMOReal density)
update occupation from MSLaneChanger
virtual int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)=0
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
The vehicle is blocked by left leader.
MSVehicle * hoppedVeh
last vehicle that changed into this lane
MSLane * getLane() const
Returns the lane the vehicle is on.
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
static SUMOTime gLaneChangeDuration
Representation of a lane in the micro simulation.
The vehicle is blocked by right leader.
const std::string & getID() const
Returns the name of the vehicle.