33 #define DEBUG_COND (myVehicle.isSelected())
74 throw ProcessError(
"Lane change model '" +
toString(lcm) +
"' is not compatible with sublane simulation");
104 myAccelerationLat(0),
106 myLaneChangeCompletion(1.0),
107 myLaneChangeDirection(0),
108 myAlreadyChanged(false),
109 myShadowLane(nullptr),
110 myTargetLane(nullptr),
111 myCarFollowModel(v.getCarFollowModel()),
113 myLastLateralGapLeft(0.),
114 myLastLateralGapRight(0.),
116 myLastFollowerGap(0.),
117 myLastLeaderSecureGap(0.),
118 myLastFollowerSecureGap(0.),
119 myLastOrigLeaderGap(0.),
120 myLastOrigLeaderSecureGap(0.),
121 myLastLeaderSpeed(0),
122 myLastFollowerSpeed(0),
123 myLastOrigLeaderSpeed(0),
124 myDontResetLCGaps(false),
128 myLastLaneChangeOffset(0),
131 myPreviousManeuverDist(0.) {
156 #ifdef DEBUG_MANEUVER
184 myLeftLeaders = std::make_shared<MSLeaderDistanceInfo>(leaders);
185 }
else if (dir == 1) {
200 }
else if (dir == 1) {
219 const std::shared_ptr<MSLeaderDistanceInfo>
223 }
else if (dir == 1) {
232 const std::shared_ptr<MSLeaderDistanceInfo>
236 }
else if (dir == 1) {
248 if (neighLeader ==
nullptr) {
268 if (leader.first == 0) {
272 if (leader.first->getSpeed() < (80.0 / 3.6)) {
315 #ifdef DEBUG_OPPOSITE
362 if (maneuverDist != 0) {
382 return DIST2SPEED(maneuverDist / stepsToChange);
422 #ifdef DEBUG_OPPOSITE
437 #ifdef DEBUG_SHADOWLANE
439 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" posLat=" << posLat <<
" overlap=" << overlap <<
"\n";
445 }
else if (overlap > NUMERICAL_EPS) {
446 const int shadowDirection = posLat < 0 ? -1 : 1;
470 std::cout <<
SIMTIME <<
" cleanupShadowLane\n";
477 std::cout <<
SIMTIME <<
" cleanupShadowLane2\n";
479 (*it)->resetPartialOccupation(&
myVehicle);
489 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
496 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
498 if (*it !=
nullptr) {
499 (*it)->resetManeuverReservation(&
myVehicle);
520 }
else if (dir < 0) {
532 #ifdef DEBUG_SHADOWLANE
534 std::cout <<
SIMTIME <<
" updateShadowLane()\n";
540 std::vector<MSLane*> passed;
545 assert(further.size() == furtherPosLat.size());
547 for (
int i = 0; i < (int)further.size(); ++i) {
549 #ifdef DEBUG_SHADOWLANE
551 std::cout <<
SIMTIME <<
" further=" << further[i]->getID() <<
" (posLat=" << furtherPosLat[i] <<
") shadowFurther=" <<
Named::getIDSecure(shadowFurther) <<
"\n";
554 if (shadowFurther !=
nullptr && shadowFurther->
getLinkTo(passed.back()) !=
nullptr) {
555 passed.push_back(shadowFurther);
558 std::reverse(passed.begin(), passed.end());
566 #ifdef DEBUG_SHADOWLANE
571 std::cout << std::endl;
575 #ifdef DEBUG_SHADOWLANE
604 #ifdef DEBUG_TARGET_LANE
609 <<
"\n oldTarget: " << (oldTarget ==
nullptr ?
"NULL" : oldTarget->
getID())
610 <<
" oldFurtherTargets: " <<
toString(oldFurtherTargets);
618 if (oldTargetLane !=
nullptr) {
619 oldTargetLane->resetManeuverReservation(&
myVehicle);
634 if (furtherTargetLane !=
nullptr) {
639 #ifdef DEBUG_TARGET_LANE
668 if (targetDir == 0) {
706 if (remainingManeuverDist == 0) {
712 assert(remainingManeuverDist >= 0);
719 const double v0 = speed;
720 const double D = remainingManeuverDist;
721 const double b = decel;
738 const double vm = (wmax - wmin) / f;
739 double distSoFar = 0.;
740 double timeSoFar = 0.;
743 const double wmaxTime = (v0 - vm) / b;
744 const double d1 = wmax * wmaxTime;
749 timeSoFar += wmaxTime;
760 const double t = v / b;
761 const double d2 = (wmin + 0.5 * f * v) * t;
763 if (distSoFar + d2 >= D) {
765 const double x = 0.5 * f * b;
766 const double y = wmin + f * v;
770 const double p = 0.5 * y / x;
771 const double q = (D - distSoFar) / x;
772 assert(p * p - q > 0);
773 const double t2 = p + sqrt(p * p - q);
774 return timeSoFar + t2;
784 double maneuverDist = remainingManeuverDist;
794 return timeSoFar + (D - distSoFar) / wmin;
839 const int dir = (newstate &
LCA_RIGHT) != 0 ? -1 : ((newstate &
LCA_LEFT) != 0 ? 1 : 0);
845 }
else if (((newstate &
LCA_RIGHT) != 0 && dir < 0)
846 || ((newstate &
LCA_LEFT) != 0 && dir > 0)) {
868 std::cout <<
" traci influenced maneuverDist=" << maneuverDist <<
"\n";
885 if (follower.first != 0) {
886 myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
894 if (leader.first != 0) {
903 if (leader.first != 0) {
939 for (
int i = rightmost; i <= leftmost; ++i) {
941 if (vehDist.first != 0) {
943 const MSVehicle* follower = vehDist.first;
945 if (netGap < myLastFollowerGap && netGap >= 0) {
959 for (
int i = rightmost; i <= leftmost; ++i) {
961 if (vehDist.first != 0) {
965 if (netGap < myLastLeaderGap && netGap >= 0) {
979 for (
int i = rightmost; i <= leftmost; ++i) {
981 if (vehDist.first != 0) {
985 if (netGap < myLastOrigLeaderGap && netGap >= 0) {
std::pair< const MSVehicle *, double > CLeaderDist
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
const int VTYPEPARS_MAXSPEED_LAT_SET
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ LCA_UNKNOWN
The action has not been determined.
@ LCA_BLOCKED
blocked in all directions
@ LCA_STAY
Needs to stay on the current lane.
@ LCA_LEFT
Wants go to the left.
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
@ LCA_AMBACKBLOCKER_STANDING
@ LCA_TRACI
The action is due to a TraCI request.
@ LCA_RIGHT
Wants go to the right.
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
const double SUMO_const_laneWidth
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Interface for lane-change models.
bool isStrategicBlocked() const
void saveLCState(const int dir, const int stateWithoutTraCI, const int state)
double myAccelerationLat
the current lateral acceleration
void setFollowerGaps(CLeaderDist follower, double secGap)
std::vector< MSLane * > myFurtherTargetLanes
MSLane * updateTargetLane()
bool myAlreadyChanged
whether the vehicle has already moved this step
bool myAmOpposite
whether the vehicle is driving in the opposite direction
double getPreviousManeuverDist() const
std::shared_ptr< MSLeaderDistanceInfo > myRightFollowers
std::shared_ptr< MSLeaderDistanceInfo > myRightLeaders
virtual void setOwnState(const int state)
bool pastMidpoint() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver
virtual double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
std::shared_ptr< MSLeaderDistanceInfo > myLeftLeaders
int myPreviousState
lane changing state from the previous simulation step
virtual double estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel) const
Calculates the maximal time needed to complete a lane change maneuver if lcMaxSpeedLatFactor and lcMa...
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model)
int myOwnState
The current state of the vehicle.
double myLastOrigLeaderGap
acutal and secure distance to closest leader vehicle on the original when performing lane change
virtual bool predInteraction(const std::pair< MSVehicle *, double > &leader)
void laneChangeOutput(const std::string &tag, MSLane *source, MSLane *target, int direction, double maneuverDist=0)
called once the vehicle ends a lane change manoeuvre (non-instant)
virtual void prepareStep()
bool myDontResetLCGaps
Flag to prevent resetting the memorized values for LC relevant gaps until the LC output is triggered ...
int myPreviousState2
lane changing state from step before the previous simulation step
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
const std::shared_ptr< MSLeaderDistanceInfo > getFollowers(const int dir)
Returns the neighboring, lc-relevant followers for the last step in the requested direction.
double myLastLateralGapRight
double myCommittedSpeed
the speed when committing to a change maneuver
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
std::pair< int, int > mySavedStateLeft
void initLastLaneChangeOffset(int dir)
std::shared_ptr< MSLeaderDistanceInfo > myLeftFollowers
Cached info on lc-relevant neighboring vehicles.
static bool myLCOutput
whether to record lane-changing
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
std::pair< int, int > mySavedStateRight
double myLastLeaderSecureGap
the minimum longitudinal distances to vehicles on the target lane that would be necessary for stringe...
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
static const double NO_NEIGHBOR
int & getCanceledState(const int dir)
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
std::vector< MSLink * > myApproachedByShadow
links which are approached by the shadow vehicle
static bool myLCStartedOutput
void setLeaderGaps(CLeaderDist, double secGap)
const std::shared_ptr< MSLeaderDistanceInfo > getLeaders(const int dir)
Returns the neighboring, lc-relevant leaders for the last step in the requested direction.
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
double myLastFollowerSpeed
double myMaxSpeedLatFactor
const LaneChangeModel myModel
the type of this model
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
double myLastLeaderGap
the actual minimum longitudinal distances to vehicles on the target lane
SUMOTime remainingTime() const
Compute the remaining time until LC completion.
virtual double computeSpeedLat(double latDist, double &maneuverDist) const
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
void setOrigLeaderGaps(CLeaderDist, double secGap)
void setManeuverDist(const double dist)
Updates the remaining distance for the current maneuver while it is continued within non-action steps...
void setShadowApproachingInformation(MSLink *link) const
set approach information for the shadow vehicle
static MSAbstractLaneChangeModel * build(LaneChangeModel lcm, MSVehicle &vehicle)
Factory method for instantiating new lane changing models.
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
void setSpeedLat(double speedLat)
set the lateral speed and update lateral acceleraton
MSLane * myTargetLane
The target lane for the vehicle's current maneuver.
MSLane * determineTargetLane(int &targetDir) const
double myPreviousManeuverDist
Maneuver distance from the previous simulation step.
static bool myLCEndedOutput
std::vector< double > myShadowFurtherLanesPosLat
double myLastFollowerSecureGap
double myLastOrigLeaderSecureGap
double myLastOrigLeaderSpeed
MSLane * myShadowLane
A lane that is partially occupied by the front of the vehicle but that is not the primary lane.
double mySpeedLat
the current lateral speed
virtual void updateSafeLatDist(const double travelledLatDist)
Updates the value of safe lateral distances (in SL2015) during maneuver continuation in non-action st...
void checkTraCICommands()
Check for commands issued for the vehicle via TraCI and apply the appropriate state changes For the s...
const MSCFModel & myCarFollowModel
The vehicle's car following model.
double myManeuverDist
The complete lateral distance the vehicle wants to travel to finish its maneuver Only used by sublane...
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
void primaryLaneChanged(MSLane *source, MSLane *target, int direction)
called once when the vehicles primary lane changes
int getShadowDirection() const
return the direction in which the current shadow lane lies
double myMaxSpeedLatStanding
double myLastLeaderSpeed
speeds of surrounding vehicles at the time of lane change
MSAbstractLaneChangeModel(MSVehicle &v, const LaneChangeModel model)
Constructor.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
double myLastLateralGapLeft
the minimum lateral gaps to other vehicles that were found when last changing to the left and right
SUMOTime myLastLaneChangeOffset
virtual ~MSAbstractLaneChangeModel()
Destructor.
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
double getAngleOffset() const
return the angle offset during a continuous change maneuver
void memorizeGapsAtLCInit()
Control for resetting the memorized values for LC relevant gaps until the LC output is triggered in t...
double myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
std::vector< MSLane * > myShadowFurtherLanes
virtual bool congested(const MSVehicle *const neighLeader)
void clearNeighbors()
Clear info on neighboring vehicle from previous step.
void saveNeighbors(const int dir, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &leaders)
Saves the lane change relevant vehicles, which are currently on neighboring lanes in the given direct...
void removeShadowApproachingInformation() const
double getWidth() const
Returns the vehicle's width.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual double getSecureGap(const MSVehicle *const, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
static double gLateralResolution
static SUMOTime gLaneChangeDuration
A lane change model developed by D. Krajzewicz between 2004 and 2010.
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013.
A lane change model developed by J. Erdmann.
Representation of a lane in the micro simulation.
MSLane * getParallelLane(int offset, bool includeOpposite=true) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
virtual void resetManeuverReservation(MSVehicle *v)
Unregisters a vehicle, which previously registered for maneuvering into this lane.
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
void enteredByLaneChange(MSVehicle *v)
virtual double setPartialOccupation(MSVehicle *v)
Sets the information about a vehicle lapping into this lane.
int getIndex() const
Returns the lane's index.
void leftByLaneChange(MSVehicle *v)
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
MSEdge & getEdge() const
Returns the lane's edge.
virtual void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
virtual void setManeuverReservation(MSVehicle *v)
Registers the lane change intentions (towards this lane) for the given vehicle.
double getWidth() const
Returns the lane's width.
saves leader/follower vehicles and their distances relative to an ego vehicle
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
Notification
Definition of a vehicle state.
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
double getLatDist() const
Representation of a vehicle in the micro simulation.
const std::vector< double > & getFurtherLanesPosLat() const
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
const std::vector< MSLane * > & getFurtherLanes() const
MSAbstractLaneChangeModel & getLaneChangeModel()
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
void fixPosition()
repair errors in vehicle position after changing between internal edges
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
double lateralDistanceToLane(const int offset) const
Get the minimal lateral distance required to move fully onto the lane at given offset.
void leaveLane(const MSMoveReminder::Notification reason, const MSLane *approachedLane=0)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
void switchOffSignal(int signal)
Switches the given signal off.
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Influencer & getInfluencer()
double updateFurtherLanes(std::vector< MSLane * > &furtherLanes, std::vector< double > &furtherLanesPosLat, const std::vector< MSLane * > &passedLanes)
update a vector of further lanes and return the new backPos
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
double getSpeed() const
Returns the vehicle's current speed.
double getPositionOnLane() const
Get the vehicle's position along the lane.
const MSLane * getLane() const
Returns the lane the vehicle is on.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it's primary lane
bool hasInfluencer() const
void switchOnSignal(int signal)
Switches the given signal on.
void updateDriveItems()
Check whether the drive items (myLFLinkLanes) are up to date, and update them if required.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
const std::string & getID() const
Returns the name of the vehicle type.
bool wasSet(int what) const
Returns whether the given parameter was set.
const SUMOVTypeParameter & getParameter() const
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
double x() const
Returns the x-position.
double y() const
Returns the y-position.
std::map< SumoXMLAttr, std::string > SubParams
sub-model parameters
const SubParams & getLCParams() const
Returns the LC parameter.