33 #define DEBUG_COND (myVehicle.isSelected())
78 throw ProcessError(
"Lane change model '" +
toString(lcm) +
"' is not compatible with sublane simulation");
108 myAccelerationLat(0),
110 myLaneChangeCompletion(1.0),
111 myLaneChangeDirection(0),
112 myAlreadyChanged(false),
113 myShadowLane(nullptr),
114 myTargetLane(nullptr),
116 myLastLateralGapLeft(0.),
117 myLastLateralGapRight(0.),
119 myLastFollowerGap(0.),
120 myLastLeaderSecureGap(0.),
121 myLastFollowerSecureGap(0.),
122 myLastOrigLeaderGap(0.),
123 myLastOrigLeaderSecureGap(0.),
124 myLastLeaderSpeed(0),
125 myLastFollowerSpeed(0),
126 myLastOrigLeaderSpeed(0),
127 myDontResetLCGaps(false),
135 myLastLaneChangeOffset(0),
138 myPreviousManeuverDist(0.) {
163 #ifdef DEBUG_MANEUVER
191 myLeftLeaders = std::make_shared<MSLeaderDistanceInfo>(leaders);
192 }
else if (dir == 1) {
207 }
else if (dir == 1) {
226 const std::shared_ptr<MSLeaderDistanceInfo>
230 }
else if (dir == 1) {
239 const std::shared_ptr<MSLeaderDistanceInfo>
243 }
else if (dir == 1) {
255 if (neighLeader ==
nullptr) {
275 if (leader.first == 0) {
279 if (leader.first->getSpeed() < (80.0 / 3.6)) {
322 #ifdef DEBUG_OPPOSITE
330 #ifdef DEBUG_OPPOSITE
332 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" primaryLaneChanged source=" << source->
getID() <<
" target=" << target->
getID() <<
" stayOpposite\n";
382 if (maneuverDist != 0) {
402 return DIST2SPEED(maneuverDist / stepsToChange);
445 #ifdef DEBUG_OPPOSITE
461 #ifdef DEBUG_SHADOWLANE
463 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" posLat=" << posLat <<
" overlap=" << overlap <<
"\n";
469 }
else if (overlap > NUMERICAL_EPS) {
470 const int shadowDirection = posLat < 0 ? -1 : 1;
494 std::cout <<
SIMTIME <<
" cleanupShadowLane\n";
501 std::cout <<
SIMTIME <<
" cleanupShadowLane2\n";
503 (*it)->resetPartialOccupation(&
myVehicle);
513 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
520 std::cout <<
SIMTIME <<
" cleanupTargetLane\n";
522 if (*it !=
nullptr) {
523 (*it)->resetManeuverReservation(&
myVehicle);
548 }
else if (dir < 0) {
560 #ifdef DEBUG_SHADOWLANE
562 std::cout <<
SIMTIME <<
" updateShadowLane()\n";
568 std::vector<MSLane*> passed;
573 assert(further.size() == 0);
576 assert(further.size() == furtherPosLat.size());
578 for (
int i = 0; i < (int)further.size(); ++i) {
580 #ifdef DEBUG_SHADOWLANE
582 std::cout <<
SIMTIME <<
" further=" << further[i]->getID() <<
" (posLat=" << furtherPosLat[i] <<
") shadowFurther=" <<
Named::getIDSecure(shadowFurther) <<
"\n";
585 if (shadowFurther !=
nullptr && shadowFurther->
getLinkTo(passed.back()) !=
nullptr) {
586 passed.push_back(shadowFurther);
589 std::reverse(passed.begin(), passed.end());
598 #ifdef DEBUG_SHADOWLANE
603 std::cout << std::endl;
607 #ifdef DEBUG_SHADOWLANE
638 #ifdef DEBUG_TARGET_LANE
643 <<
"\n oldTarget: " << (oldTarget ==
nullptr ?
"NULL" : oldTarget->
getID())
644 <<
" oldFurtherTargets: " <<
toString(oldFurtherTargets);
652 if (oldTargetLane !=
nullptr) {
653 oldTargetLane->resetManeuverReservation(&
myVehicle);
668 if (furtherTargetLane !=
nullptr) {
673 #ifdef DEBUG_TARGET_LANE
702 if (targetDir == 0) {
740 if (remainingManeuverDist == 0) {
746 assert(remainingManeuverDist >= 0);
753 const double v0 = speed;
754 const double D = remainingManeuverDist;
755 const double b = decel;
772 const double vm = (wmax - wmin) / f;
773 double distSoFar = 0.;
774 double timeSoFar = 0.;
777 const double wmaxTime = (v0 - vm) / b;
778 const double d1 = wmax * wmaxTime;
783 timeSoFar += wmaxTime;
794 const double t = v / b;
795 const double d2 = (wmin + 0.5 * f * v) * t;
797 if (distSoFar + d2 >= D) {
799 const double x = 0.5 * f * b;
800 const double y = wmin + f * v;
804 const double p = 0.5 * y / x;
805 const double q = (D - distSoFar) / x;
806 assert(p * p - q > 0);
807 const double t2 = p + sqrt(p * p - q);
808 return timeSoFar + t2;
818 double maneuverDist = remainingManeuverDist;
819 const double vModel =
computeSpeedLat(maneuverDist, maneuverDist, urgent);
828 return timeSoFar + (D - distSoFar) / wmin;
876 const int dir = (newstate &
LCA_RIGHT) != 0 ? -1 : ((newstate &
LCA_LEFT) != 0 ? 1 : 0);
882 }
else if (((newstate &
LCA_RIGHT) != 0 && dir < 0)
883 || ((newstate &
LCA_LEFT) != 0 && dir > 0)) {
905 std::cout <<
" traci influenced maneuverDist=" << maneuverDist <<
"\n";
922 if (follower.first != 0) {
923 myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
931 if (leader.first != 0) {
940 if (leader.first != 0) {
976 for (
int i = rightmost; i <= leftmost; ++i) {
978 if (vehDist.first != 0) {
980 const MSVehicle* follower = vehDist.first;
982 if (netGap < myLastFollowerGap && netGap >= 0) {
996 for (
int i = rightmost; i <= leftmost; ++i) {
998 if (vehDist.first != 0) {
1002 if (netGap < myLastLeaderGap && netGap >= 0) {
1016 for (
int i = rightmost; i <= leftmost; ++i) {
1018 if (vehDist.first != 0) {
1019 const MSVehicle* leader = vehDist.first;
1022 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
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ 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_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
double getForwardPos() const
get vehicle position relative to the forward direction lane
void saveLCState(const int dir, const int stateWithoutTraCI, const int state)
double myAccelerationLat
the current lateral acceleration
void setFollowerGaps(CLeaderDist follower, double secGap)
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
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.
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...
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
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.
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
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.
static bool myLCEndedOutput
double getMaxSpeedLat2() const
return the max of maxSpeedLat and lcMaxSpeedLatStanding
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...
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
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
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].
A device which collects info on the vehicle trip (mainly on departure and arrival)
static double gLateralResolution
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 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
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.
MSLane * getParallelOpposite() const
return the opposite direction lane of this lanes edge or nullptr
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...
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
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.
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.
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.
std::map< SumoXMLAttr, std::string > SubParams
sub-model parameters
const SubParams & getLCParams() const
Returns the LC parameter.