48 #ifdef CHECK_MEMORY_LEAKS
50 #endif // CHECK_MEMORY_LEAKS
53 #ifdef DEBUG_VEHICLE_GUI_SELECTION
64 : myAllowsSwap(allowSwap) {
65 assert(lanes->size() > 1);
69 for (std::vector<MSLane*>::iterator lane = lanes->begin(); lane != lanes->end(); ++lane) {
74 ce.
veh = (*lane)->myVehicles.rbegin();
95 bool haveChanged =
change();
109 ce->firstBlocked = 0;
113 if (vehicles.empty()) {
114 ce->veh = vehicles.rend();
118 ce->veh = vehicles.rbegin();
119 if (vehicles.size() == 1) {
123 ce->follow = *(vehicles.rbegin() + 1);
139 #ifdef DEBUG_VEHICLE_GUI_SELECTION
158 const std::vector<MSVehicle::LaneQ>& preb = vehicle->
getBestLanes();
164 bool changingAllowed1 = (state1 &
LCA_BLOCKED) == 0;
166 if ((state1 &
LCA_RIGHT) != 0 && changingAllowed1) {
170 if ((state1 & LCA_RIGHT) != 0 && (state1 &
LCA_URGENT) != 0) {
171 (
myCandi - 1)->lastBlocked = vehicle;
172 if ((
myCandi - 1)->firstBlocked == 0) {
173 (
myCandi - 1)->firstBlocked = vehicle;
184 bool changingAllowed2 = (state2 &
LCA_BLOCKED) == 0;
186 if ((state2 &
LCA_LEFT) != 0 && changingAllowed2) {
190 if ((state2 & LCA_LEFT) != 0 && (state2 &
LCA_URGENT) != 0) {
191 (
myCandi + 1)->lastBlocked = vehicle;
192 if ((
myCandi + 1)->firstBlocked == 0) {
193 (
myCandi + 1)->firstBlocked = vehicle;
218 if (target->hoppedVeh != 0) {
219 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
238 MSLane::VehCont::iterator i = find(target->lane->myTmpVehicles.begin(), target->lane->myTmpVehicles.end(), prohibitor);
239 if (i != target->lane->myTmpVehicles.end()) {
240 assert(*i == prohibitor);
241 target->lane->myTmpVehicles.erase(i);
243 target->hoppedVeh = vehicle;
244 target->lane->myTmpVehicles.insert(target->lane->myTmpVehicles.begin(), vehicle);
245 myCandi->hoppedVeh = prohibitor;
246 myCandi->lane->myTmpVehicles.insert(
myCandi->lane->myTmpVehicles.begin(), prohibitor);
287 to->hoppedVeh = vehicle;
290 to->lane->myTmpVehicles.insert(to->lane->myTmpVehicles.begin(), vehicle);
293 from->lane->myTmpVehicles.insert(from->lane->myTmpVehicles.begin(), vehicle);
296 to->dens += to->hoppedVeh->getVehicleType().getLengthWithGap();
300 std::pair<MSVehicle* const, SUMOReal>
305 MSLane* targetLane = target->lane;
313 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
315 MSLane* nextLane = (*link)->getLane();
317 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
321 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
327 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
331 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
336 std::pair<MSVehicle* const, SUMOReal>
341 if (target->hoppedVeh != 0) {
342 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
344 neighLead = target->hoppedVeh;
347 if (neighLead == 0) {
348 MSLane* targetLane = target->lane;
357 return std::pair<MSVehicle* const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
360 return target->lane->getLeaderOnConsecutive(dist, seen, speed, *
veh(
myCandi), bestLaneConts);
368 std::pair<MSVehicle* const, SUMOReal>
372 if (target->hoppedVeh != 0) {
373 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
375 neighFollow = target->hoppedVeh;
378 if (neighFollow == 0) {
379 SUMOReal speed = target->lane->getSpeedLimit();
389 return std::pair<MSVehicle* const, SUMOReal>(neighFollow, candi->
getPositionOnLane() - candi->
getVehicleType().
getLength() - neighFollow->getPositionOnLane() - neighFollow->getVehicleType().getMinGap());
403 if (!vehHasChanged) {
434 ce->lane->swapAfterLaneChange(t);
453 assert(
veh(ce) != 0);
454 assert(
veh(max) != 0);
455 if (
veh(max)->getPositionOnLane() <
veh(ce)->getPositionOnLane()) {
460 assert(
veh(max) != 0);
467 const std::pair<MSVehicle* const, SUMOReal>& leader,
468 const std::vector<MSVehicle::LaneQ>& preb)
const {
477 if (neighFollow.first != 0 && neighFollow.second < 0) {
480 if (neighLead.first != 0 && neighLead.second < 0) {
484 if (neighFollow.first != 0) {
487 blocked |= blockedByFollower;
492 if (neighLead.first != 0) {
495 blocked |= blockedByLeader;
501 laneOffset, msg, blocked, leader, neighLead, neighFollow, *(target->lane), preb, &(
myCandi->lastBlocked), &(
myCandi->firstBlocked));
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
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.
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.
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 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.
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, unsigned int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
MSAbstractLaneChangeModel & getLaneChangeModel()
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
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 MSVehicle * getLastVehicle() const
returns the last vehicle
MSLaneChanger()
Default constructor.
int checkChange(int laneOffset, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
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.
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...
GUISelectedStorage gSelected
A global holder of selected objects.
Representation of a lane in the micro simulation.
The vehicle is blocked by right leader.