33#define DEBUG_COND (myVehicle.isSelected())
65#define LC_ASSUMED_DECEL 1.0
116 myAccelerationLat(0),
118 myPreviousAngleOffset(0),
120 myLaneChangeCompletion(1.0),
121 myLaneChangeDirection(0),
122 myAlreadyChanged(false),
123 myShadowLane(nullptr),
124 myTargetLane(nullptr),
126 myLastLateralGapLeft(0.),
127 myLastLateralGapRight(0.),
129 myLastFollowerGap(0.),
130 myLastLeaderSecureGap(0.),
131 myLastFollowerSecureGap(0.),
132 myLastOrigLeaderGap(0.),
133 myLastOrigLeaderSecureGap(0.),
134 myLastLeaderSpeed(0),
135 myLastFollowerSpeed(0),
136 myLastOrigLeaderSpeed(0),
137 myDontResetLCGaps(false),
147 myLastLaneChangeOffset(0),
150 myPreviousManeuverDist(0.) {
203 myLeftLeaders = std::make_shared<MSLeaderDistanceInfo>(leaders);
204 }
else if (dir == 1) {
219 }
else if (dir == 1) {
238const std::shared_ptr<MSLeaderDistanceInfo>
242 }
else if (dir == 1) {
251const std::shared_ptr<MSLeaderDistanceInfo>
255 }
else if (dir == 1) {
267 if (neighLeader ==
nullptr) {
294 if (leader.first == 0) {
298 if (leader.first->getSpeed() < (80.0 / 3.6)) {
351 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" primaryLaneChanged source=" << source->
getID() <<
" target=" << target->
getID() <<
" stayOpposite\n";
401 if (maneuverDist != 0) {
421 return DIST2SPEED(maneuverDist / stepsToChange);
489#ifdef DEBUG_SHADOWLANE
491 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" posLat=" << posLat <<
" overlap=" << overlap <<
"\n";
497 }
else if (overlap > NUMERICAL_EPS) {
498 const int shadowDirection = posLat < 0 ? -1 : 1;
522 std::cout <<
SIMTIME <<
" cleanupShadowLane\n";
529 std::cout <<
SIMTIME <<
" cleanupShadowLane2\n";
541 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
548 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
550 if (*it !=
nullptr) {
576 }
else if (dir < 0) {
588#ifdef DEBUG_SHADOWLANE
590 std::cout <<
SIMTIME <<
" updateShadowLane()\n";
596 std::vector<MSLane*> passed;
601 assert(further.size() == 0);
604 assert(further.size() == furtherPosLat.size());
606 for (
int i = 0; i < (int)further.size(); ++i) {
608#ifdef DEBUG_SHADOWLANE
610 std::cout <<
SIMTIME <<
" further=" << further[i]->getID() <<
" (posLat=" << furtherPosLat[i] <<
") shadowFurther=" <<
Named::getIDSecure(shadowFurther) <<
"\n";
613 if (shadowFurther !=
nullptr && shadowFurther->
getLinkTo(passed.back()) !=
nullptr) {
614 passed.push_back(shadowFurther);
617 std::reverse(passed.begin(), passed.end());
626#ifdef DEBUG_SHADOWLANE
631 std::cout << std::endl;
635#ifdef DEBUG_SHADOWLANE
666#ifdef DEBUG_TARGET_LANE
671 <<
"\n oldTarget: " << (oldTarget ==
nullptr ?
"NULL" : oldTarget->
getID())
672 <<
" oldFurtherTargets: " <<
toString(oldFurtherTargets);
680 if (oldTargetLane !=
nullptr) {
681 oldTargetLane->resetManeuverReservation(&
myVehicle);
696 if (furtherTargetLane !=
nullptr) {
701#ifdef DEBUG_TARGET_LANE
730 if (targetDir == 0) {
773 if (remainingManeuverDist == 0) {
779 assert(remainingManeuverDist >= 0);
786 const double v0 = speed;
787 const double D = remainingManeuverDist;
788 const double b = decel;
805 const double vm = (wmax - wmin) / f;
806 double distSoFar = 0.;
807 double timeSoFar = 0.;
810 const double wmaxTime = (v0 - vm) / b;
811 const double d1 = wmax * wmaxTime;
816 timeSoFar += wmaxTime;
827 const double t = v / b;
828 const double d2 = (wmin + 0.5 * f * v) * t;
830 if (distSoFar + d2 >= D) {
832 const double x = 0.5 * f * b;
833 const double y = wmin + f * v;
837 const double p = 0.5 * y / x;
838 const double q = (D - distSoFar) / x;
839 assert(p * p - q > 0);
840 const double t2 = p + sqrt(p * p - q);
841 return timeSoFar + t2;
851 double maneuverDist = remainingManeuverDist;
852 const double vModel =
computeSpeedLat(maneuverDist, maneuverDist, urgent);
853 double result = D / vModel;
863 return timeSoFar + (D - distSoFar) / wmin;
911 const int dir = (newstate &
LCA_RIGHT) != 0 ? -1 : ((newstate &
LCA_LEFT) != 0 ? 1 : 0);
917 }
else if (((newstate &
LCA_RIGHT) != 0 && dir < 0)
918 || ((newstate &
LCA_LEFT) != 0 && dir > 0)) {
940 std::cout <<
" traci influenced maneuverDist=" << maneuverDist <<
"\n";
957 if (follower.first != 0) {
958 myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
966 if (leader.first != 0) {
975 if (leader.first != 0) {
1011 for (
int i = rightmost; i <= leftmost; ++i) {
1013 if (vehDist.first != 0) {
1015 const MSVehicle* follower = vehDist.first;
1017 if (netGap < myLastFollowerGap && netGap >= 0) {
1031 for (
int i = rightmost; i <= leftmost; ++i) {
1033 if (vehDist.first != 0) {
1034 const MSVehicle* leader = vehDist.first;
1037 if (netGap < myLastLeaderGap && netGap >= 0) {
1051 for (
int i = rightmost; i <= leftmost; ++i) {
1053 if (vehDist.first != 0) {
1054 const MSVehicle* leader = vehDist.first;
1057 if (netGap < myLastOrigLeaderGap && netGap >= 0) {
1111 std::vector<std::string> lcState;
1117 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_LCA_STRATEGIC_LOOKAHEAD
@ 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
static const double UNDEFINED_LOOKAHEAD
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.