47 #ifdef CHECK_MEMORY_LEAKS
49 #endif // CHECK_MEMORY_LEAKS
52 #ifdef DEBUG_VEHICLE_GUI_SELECTION
63 : myAllowsSwap(allowSwap) {
64 assert(lanes->size() > 1);
68 for (std::vector<MSLane*>::iterator lane = lanes->begin(); lane != lanes->end(); ++lane) {
73 ce.
veh = (*lane)->myVehicles.rbegin();
94 bool haveChanged =
change();
108 ce->firstBlocked = 0;
112 if (vehicles.empty()) {
113 ce->veh = vehicles.rend();
117 ce->veh = vehicles.rbegin();
118 if (vehicles.size() == 1) {
122 ce->follow = *(vehicles.rbegin() + 1);
138 #ifdef DEBUG_VEHICLE_GUI_SELECTION
153 const std::vector<MSVehicle::LaneQ>& preb = vehicle->
getBestLanes();
156 ((std::vector<MSVehicle::LaneQ>&) preb)[i].occupation =
myChanger[i].dens + preb[i].nextOccupation;
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()) {
241 assert(bla == prohibitor);
242 target->lane->myTmpVehicles.erase(i);
244 target->hoppedVeh = vehicle;
245 target->lane->myTmpVehicles.insert(target->lane->myTmpVehicles.begin(), vehicle);
246 myCandi->hoppedVeh = prohibitor;
247 myCandi->lane->myTmpVehicles.insert(
myCandi->lane->myTmpVehicles.begin(), prohibitor);
288 to->hoppedVeh = vehicle;
291 to->lane->myTmpVehicles.insert(to->lane->myTmpVehicles.begin(), vehicle);
294 from->lane->myTmpVehicles.insert(from->lane->myTmpVehicles.begin(), vehicle);
297 to->dens += to->hoppedVeh->getVehicleType().getLengthWithGap();
301 std::pair<MSVehicle* const, SUMOReal>
306 MSLane* targetLane = target->lane;
312 MSLinkCont::const_iterator link = targetLane->
succLinkSec(*
veh(
myCandi), 1, *targetLane, bestLaneConts);
314 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
316 MSLane* nextLane = (*link)->getLane();
318 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
322 return std::pair<MSVehicle*, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
328 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
332 return std::pair<MSVehicle* const, SUMOReal>(leader,
MAX2((
SUMOReal) 0, gap));
337 std::pair<MSVehicle* const, SUMOReal>
342 if (target->hoppedVeh != 0) {
343 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
345 neighLead = target->hoppedVeh;
348 if (neighLead == 0) {
349 MSLane* targetLane = target->lane;
358 return std::pair<MSVehicle* const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
361 return target->lane->getLeaderOnConsecutive(dist, seen, speed, *
veh(
myCandi), bestLaneConts);
369 std::pair<MSVehicle* const, SUMOReal>
373 if (target->hoppedVeh != 0) {
374 SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
376 neighFollow = target->hoppedVeh;
379 if (neighFollow == 0) {
380 SUMOReal speed = target->lane->getSpeedLimit();
391 return std::pair<MSVehicle* const, SUMOReal>(neighFollow, candi->
getPositionOnLane() - candi->
getVehicleType().
getLength() - neighFollow->getPositionOnLane() - neighFollow->getVehicleType().getMinGap());
405 if (!vehHasChanged) {
436 ce->lane->swapAfterLaneChange(t);
455 assert(
veh(ce) != 0);
456 assert(
veh(max) != 0);
457 if (
veh(max)->getPositionOnLane() <
veh(ce)->getPositionOnLane()) {
462 assert(
veh(max) != 0);
469 const std::pair<MSVehicle* const, SUMOReal>& leader,
470 const std::vector<MSVehicle::LaneQ>& preb)
const {
481 if (neighFollow.first != 0 && neighFollow.second < 0) {
484 if (neighLead.first != 0 && neighLead.second < 0) {
488 if (neighFollow.first != 0) {
496 if (neighLead.first != 0) {
505 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
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)
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 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.
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 setOwnState(int state)
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)
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.
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...
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.