33#define DEBUG_COND (myVehicle.isSelected())
64#define LC_ASSUMED_DECEL 1.0
115 myAccelerationLat(0),
117 myPreviousAngleOffset(0),
119 myLaneChangeCompletion(1.0),
120 myLaneChangeDirection(0),
121 myAlreadyChanged(false),
122 myShadowLane(nullptr),
123 myTargetLane(nullptr),
125 myLastLateralGapLeft(0.),
126 myLastLateralGapRight(0.),
128 myLastFollowerGap(0.),
129 myLastLeaderSecureGap(0.),
130 myLastFollowerSecureGap(0.),
131 myLastOrigLeaderGap(0.),
132 myLastOrigLeaderSecureGap(0.),
133 myLastLeaderSpeed(0),
134 myLastFollowerSpeed(0),
135 myLastOrigLeaderSpeed(0),
136 myDontResetLCGaps(false),
145 myLastLaneChangeOffset(0),
148 myPreviousManeuverDist(0.) {
201 myLeftLeaders = std::make_shared<MSLeaderDistanceInfo>(leaders);
202 }
else if (dir == 1) {
217 }
else if (dir == 1) {
236const std::shared_ptr<MSLeaderDistanceInfo>
240 }
else if (dir == 1) {
249const std::shared_ptr<MSLeaderDistanceInfo>
253 }
else if (dir == 1) {
265 if (neighLeader ==
nullptr) {
292 if (leader.first == 0) {
296 if (leader.first->getSpeed() < (80.0 / 3.6)) {
349 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" primaryLaneChanged source=" << source->
getID() <<
" target=" << target->
getID() <<
" stayOpposite\n";
399 if (maneuverDist != 0) {
419 return DIST2SPEED(maneuverDist / stepsToChange);
487#ifdef DEBUG_SHADOWLANE
489 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" posLat=" << posLat <<
" overlap=" << overlap <<
"\n";
495 }
else if (overlap > NUMERICAL_EPS) {
496 const int shadowDirection = posLat < 0 ? -1 : 1;
520 std::cout <<
SIMTIME <<
" cleanupShadowLane\n";
527 std::cout <<
SIMTIME <<
" cleanupShadowLane2\n";
539 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
546 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
548 if (*it !=
nullptr) {
574 }
else if (dir < 0) {
586#ifdef DEBUG_SHADOWLANE
588 std::cout <<
SIMTIME <<
" updateShadowLane()\n";
594 std::vector<MSLane*> passed;
599 assert(further.size() == 0);
602 assert(further.size() == furtherPosLat.size());
604 for (
int i = 0; i < (int)further.size(); ++i) {
606#ifdef DEBUG_SHADOWLANE
608 std::cout <<
SIMTIME <<
" further=" << further[i]->getID() <<
" (posLat=" << furtherPosLat[i] <<
") shadowFurther=" <<
Named::getIDSecure(shadowFurther) <<
"\n";
611 if (shadowFurther !=
nullptr && shadowFurther->
getLinkTo(passed.back()) !=
nullptr) {
612 passed.push_back(shadowFurther);
615 std::reverse(passed.begin(), passed.end());
624#ifdef DEBUG_SHADOWLANE
629 std::cout << std::endl;
633#ifdef DEBUG_SHADOWLANE
664#ifdef DEBUG_TARGET_LANE
669 <<
"\n oldTarget: " << (oldTarget ==
nullptr ?
"NULL" : oldTarget->
getID())
670 <<
" oldFurtherTargets: " <<
toString(oldFurtherTargets);
678 if (oldTargetLane !=
nullptr) {
679 oldTargetLane->resetManeuverReservation(&
myVehicle);
694 if (furtherTargetLane !=
nullptr) {
699#ifdef DEBUG_TARGET_LANE
728 if (targetDir == 0) {
771 if (remainingManeuverDist == 0) {
777 assert(remainingManeuverDist >= 0);
784 const double v0 = speed;
785 const double D = remainingManeuverDist;
786 const double b = decel;
803 const double vm = (wmax - wmin) / f;
804 double distSoFar = 0.;
805 double timeSoFar = 0.;
808 const double wmaxTime = (v0 - vm) / b;
809 const double d1 = wmax * wmaxTime;
814 timeSoFar += wmaxTime;
825 const double t = v / b;
826 const double d2 = (wmin + 0.5 * f * v) * t;
828 if (distSoFar + d2 >= D) {
830 const double x = 0.5 * f * b;
831 const double y = wmin + f * v;
835 const double p = 0.5 * y / x;
836 const double q = (D - distSoFar) / x;
837 assert(p * p - q > 0);
838 const double t2 = p + sqrt(p * p - q);
839 return timeSoFar + t2;
849 double maneuverDist = remainingManeuverDist;
850 const double vModel =
computeSpeedLat(maneuverDist, maneuverDist, urgent);
851 double result = D / vModel;
861 return timeSoFar + (D - distSoFar) / wmin;
909 const int dir = (newstate &
LCA_RIGHT) != 0 ? -1 : ((newstate &
LCA_LEFT) != 0 ? 1 : 0);
915 }
else if (((newstate &
LCA_RIGHT) != 0 && dir < 0)
916 || ((newstate &
LCA_LEFT) != 0 && dir > 0)) {
938 std::cout <<
" traci influenced maneuverDist=" << maneuverDist <<
"\n";
955 if (follower.first != 0) {
956 myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
964 if (leader.first != 0) {
973 if (leader.first != 0) {
1009 for (
int i = rightmost; i <= leftmost; ++i) {
1011 if (vehDist.first != 0) {
1013 const MSVehicle* follower = vehDist.first;
1015 if (netGap < myLastFollowerGap && netGap >= 0) {
1029 for (
int i = rightmost; i <= leftmost; ++i) {
1031 if (vehDist.first != 0) {
1032 const MSVehicle* leader = vehDist.first;
1035 if (netGap < myLastLeaderGap && netGap >= 0) {
1049 for (
int i = rightmost; i <= leftmost; ++i) {
1051 if (vehDist.first != 0) {
1052 const MSVehicle* leader = vehDist.first;
1055 if (netGap < myLastOrigLeaderGap && netGap >= 0) {
1109 std::vector<std::string> lcState;
1115 if (lcState.size() > 0) {
std::pair< const MSVehicle *, double > CLeaderDist
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const long long int VTYPEPARS_MAXSPEED_LAT_SET
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ SVC_EMERGENCY
public emergency vehicles
@ SVC_MOPED
vehicle is a moped
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_URGENT
The action is urgent (to be defined by lc-model)
@ 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_MAXDISTLATSTANDING
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_LCSTATE
The state of the lanechange model.
@ SUMO_ATTR_LCA_OVERTAKE_RIGHT
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
#define UNUSED_PARAMETER(x)
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Interface for lane-change models.
bool isStrategicBlocked() const
double getForwardPos() const
get vehicle position relative to the forward direction lane
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
double myPreviousAngleOffset
the angle offset of the previous time step resulting from lane change and sigma
virtual double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
virtual double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
virtual double estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel, bool urgent) const
Calculates the maximal time needed to complete a lane change maneuver if lcMaxSpeedLatFactor and lcMa...
virtual void resetSpeedLat()
std::shared_ptr< MSLeaderDistanceInfo > myLeftLeaders
int myPreviousState
lane changing state from the previous simulation step
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
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
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
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
virtual void saveState(OutputDevice &out) const
Save the state of the laneChangeModel.
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
void saveLCState(const int dir, int stateWithoutTraCI, const int state)
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
std::vector< MSLink * > myApproachedByShadow
links which are approached by the shadow vehicle
void addLCSpeedAdvice(const double vSafe, bool ownAdvice=true)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
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
int & getCanceledState(const int dir)
double myLastFollowerSpeed
double myMaxSpeedLatFactor
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.
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...
std::vector< std::pair< double, bool > > myLCAccelerationAdvices
void setShadowApproachingInformation(MSLink *link) const
set approach information for the shadow vehicle
int getNormalizedLaneIndex()
brief return lane index that treats opposite lanes like normal lanes to the left of the forward lanes
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.
double myOvertakeRightParam
static bool myLCEndedOutput
double getMaxSpeedLat2() const
return the max of maxSpeedLat and lcMaxSpeedLatStanding
std::vector< double > myShadowFurtherLanesPosLat
double myLastFollowerSecureGap
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
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...
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
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the laneChangeModel from the given attributes.
MSAbstractLaneChangeModel(MSVehicle &v, const LaneChangeModel model)
Constructor.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
double calcAngleOffset()
return the angle offset during a continuous change maneuver
double myAngleOffset
the current angle offset resulting from lane change and sigma
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
virtual bool avoidOvertakeRight() const
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
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getLength() const
Returns the vehicle's length.
double getWidth() const
Returns the vehicle's width.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
virtual double getSecureGap(const MSVehicle *const veh, 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)
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
A device which collects info on the vehicle trip (mainly on departure and arrival)
static double gLateralResolution
static bool gLefthand
Whether lefthand-drive is being simulated.
static bool gSublane
whether sublane simulation is enabled (sublane model or continuous lanechanging)
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 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)
double getLength() const
Returns the lane's length.
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
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.
MSLane * getParallelOpposite() const
return the opposite direction lane of this lanes edge or nullptr
MSEdge & getEdge() const
Returns the lane's edge.
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)
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
bool isOpposite
whether this an opposite-direction stop
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...
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
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
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.
const MSLane * getLane() const
Returns the lane the vehicle is 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.
const std::vector< MSLane * > & getFurtherLanes() const
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getPositionOnLane() const
Get the vehicle's position along the lane.
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it's primary lane
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
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.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
double x() const
Returns the x-position.
double y() const
Returns the y-position.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
std::map< SumoXMLAttr, std::string > SubParams
sub-model parameters
const SubParams & getLCParams() const
Returns the LC parameter.