46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
51 #ifdef DEBUG_VEHICLE_GUI_SELECTION
62 : myAllowsSwap(allowSwap) {
63 assert(lanes->size() > 1);
67 for (std::vector<MSLane*>::iterator lane = lanes->begin(); lane != lanes->end(); ++lane) {
72 ce.
veh = (*lane)->myVehicles.rbegin();
92 bool haveChanged =
change();
109 if (vehicles.empty()) {
110 ce->veh = vehicles.rend();
114 ce->veh = vehicles.rbegin();
115 if (vehicles.size() == 1) {
119 ce->follow = *(vehicles.rbegin() + 1);
135 #ifdef DEBUG_VEHICLE_GUI_SELECTION
150 const std::vector<MSVehicle::LaneQ>& preb = vehicle->
getBestLanes();
153 ((std::vector<MSVehicle::LaneQ>&) preb)[i].occupation =
myChanger[i].dens + preb[i].nextOccupation;
167 bool changingAllowed1 = (state1 &
LCA_BLOCKED) == 0;
169 if ((state1 &
LCA_RIGHT) != 0 && changingAllowed1) {
177 if ((state1 & LCA_RIGHT) != 0 && (state1 & LCA_URGENT) != 0) {
178 (
myCandi - 1)->lastBlocked = vehicle;
189 state2 =
change2left(leader, lLead, lFollow, preb);
193 bool changingAllowed2 = (state2 &
LCA_BLOCKED) == 0;
196 if ((state2 &
LCA_LEFT) != 0 && changingAllowed2) {
204 if ((state2 & LCA_LEFT) != 0 && (state2 & LCA_URGENT) != 0) {
205 (
myCandi + 1)->lastBlocked = vehicle;
229 if (target->hoppedVeh != 0) {
230 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
249 MSLane::VehCont::iterator i = find(target->lane->myTmpVehicles.begin(), target->lane->myTmpVehicles.end(), prohibitor);
250 if (i != target->lane->myTmpVehicles.end()) {
252 assert(bla == prohibitor);
253 target->lane->myTmpVehicles.erase(i);
255 target->hoppedVeh = vehicle;
256 target->lane->myTmpVehicles.insert(target->lane->myTmpVehicles.begin(), vehicle);
257 myCandi->hoppedVeh = prohibitor;
258 myCandi->lane->myTmpVehicles.insert(
myCandi->lane->myTmpVehicles.begin(), prohibitor);
299 to->hoppedVeh = vehicle;
302 to->lane->myTmpVehicles.insert(to->lane->myTmpVehicles.begin(), vehicle);
305 from->lane->myTmpVehicles.insert(from->lane->myTmpVehicles.begin(), vehicle);
308 to->dens += to->hoppedVeh->getVehicleType().getLengthWithGap();
312 std::pair<MSVehicle* const, SUMOReal>
317 MSLane* targetLane = target->lane;
323 MSLinkCont::const_iterator link = targetLane->
succLinkSec(*
veh(
myCandi), 1, *targetLane, bestLaneConts);
325 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
327 MSLane* nextLane = (*link)->getLane();
329 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
333 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
339 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
343 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
348 std::pair<MSVehicle* const, SUMOReal>
353 if (target->hoppedVeh != 0) {
354 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
356 neighLead = target->hoppedVeh;
359 if (neighLead == 0) {
360 MSLane* targetLane = target->lane;
369 return std::pair<MSVehicle* const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
372 return target->lane->getLeaderOnConsecutive(dist, seen, speed, *
veh(
myCandi), bestLaneConts);
380 std::pair<MSVehicle* const, SUMOReal>
384 if (target->hoppedVeh != 0) {
385 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
387 neighFollow = target->hoppedVeh;
390 if (neighFollow == 0) {
391 SUMOReal speed = target->lane->getSpeedLimit();
402 return std::pair<MSVehicle* const, SUMOReal>(neighFollow, candi->
getPositionOnLane() - candi->
getVehicleType().
getLength() - neighFollow->getPositionOnLane() - neighFollow->getVehicleType().getMinGap());
416 if (!vehHasChanged) {
447 ce->lane->swapAfterLaneChange(t);
466 assert(
veh(ce) != 0);
467 assert(
veh(max) != 0);
468 if (
veh(max)->getPositionOnLane() <
veh(ce)->getPositionOnLane()) {
473 assert(
veh(max) != 0);
480 const std::pair<MSVehicle* const, SUMOReal>& rLead,
481 const std::pair<MSVehicle* const, SUMOReal>& rFollow,
482 const std::vector<MSVehicle::LaneQ>& preb)
const {
490 if (rFollow.first != 0 && rFollow.second < 0) {
493 if (rLead.first != 0 && rLead.second < 0) {
497 if (rFollow.first != 0) {
505 if (rLead.first != 0) {
514 msg, blocked, leader, rLead, rFollow, *(
myCandi - 1)->lane, preb, &(
myCandi->lastBlocked));
520 const std::pair<MSVehicle* const, SUMOReal>& rLead,
521 const std::pair<MSVehicle* const, SUMOReal>& rFollow,
522 const std::vector<MSVehicle::LaneQ>& preb)
const {
530 if (rFollow.first != 0 && rFollow.second < 0) {
533 if (rLead.first != 0 && rLead.second < 0) {
537 if (rFollow.first != 0) {
544 if (rLead.first != 0) {
552 msg, blocked, leader, rLead, rFollow, *(
myCandi + 1)->lane, preb, &(
myCandi->lastBlocked));
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
virtual const std::vector< LaneQ > & getBestLanes(bool forceRebuild=false, MSLane *startLane=0) const
Returns the description of best lanes to use in order to continue the route.
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)
int change2right(const std::pair< MSVehicle *const, SUMOReal > &leader, const std::pair< MSVehicle *const, SUMOReal > &rLead, const std::pair< MSVehicle *const, SUMOReal > &rFollow, const std::vector< MSVehicle::LaneQ > &preb) const
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.
virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, unsigned int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts) const
std::vector< MSVehicle * > VehCont
Container for vehicles.
SUMOReal getLength() const
Get vehicle's length [m].
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
bool overlapWithHopped(ChangerIt target) const
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.
MSVehicle * lead
the vehicle in front of the current vehicle
The action is due to the wish to follow the route (navigational lc)
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.
int change2left(const std::pair< MSVehicle *const, SUMOReal > &leader, const std::pair< MSVehicle *const, SUMOReal > &rLead, const std::pair< MSVehicle *const, SUMOReal > &rFollow, const std::vector< MSVehicle::LaneQ > &preb) const
MSAbstractLaneChangeModel & getLaneChangeModel()
SUMOReal getPartialOccupatorEnd() const
Returns the position of the in-lapping vehicle's end.
virtual int wantsChangeToLeft(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)=0
Called to examine whether the vehicle wants to change to left This method gets the information about ...
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)
vehicle want's to change to right lane
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 setOwnState(int state)
The vehicle is blocked by left follower.
std::pair< MSVehicle *const, SUMOReal > getRealThisLeader(const ChangerIt &target) const
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
virtual int wantsChangeToRight(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)=0
Called to examine whether the vehicle wants to change to right This method gets the information about...
virtual MSVehicle * getLastVehicle() const
returns the last vehicle
MSLaneChanger()
Default constructor.
void updateLanes(SUMOTime t)
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.
vehicle want's to change to left lane
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.
SUMOReal myPos
the stored position
virtual void prepareStep()
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.
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.
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
GUISelectedStorage gSelected
A global holder of selected objects.
Representation of a lane in the micro simulation.
virtual void fulfillChangeRequest(MSVehicle::ChangeRequest request)
The vehicle is blocked by right leader.
The action is due to the wish to be faster (tactical lc)