Skip to content

Commit

Permalink
Adjust IDM formula
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc0711 committed Aug 17, 2021
1 parent 459548b commit 9d40547
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Expand Up @@ -1787,9 +1787,7 @@ private double computeSpeed(final IScope scope,

double dt = scope.getSimulation().getClock().getStepInSeconds();
double speed = getSpeed(vehicle) + acceleration * dt;
speed = Math.min(speed, getSpeedCoeff(vehicle) * RoadSkill.getMaxSpeed(road));
speed = Math.max(0.0, speed);
return speed;
return Math.max(0.0, speed);
}

/**
Expand Down
@@ -1,5 +1,6 @@
package simtools.gaml.extensions.traffic.carfollowing;

import static simtools.gaml.extensions.traffic.DrivingSkill.getSpeedCoeff;
import static simtools.gaml.extensions.traffic.DrivingSkill.getDeltaIDM;
import static simtools.gaml.extensions.traffic.DrivingSkill.getMaxAcceleration;
import static simtools.gaml.extensions.traffic.DrivingSkill.getMaxDeceleration;
Expand All @@ -11,6 +12,8 @@
import msi.gama.metamodel.agent.IAgent;
import msi.gama.runtime.IScope;

import simtools.gaml.extensions.traffic.RoadSkill;

public class IDM {
/**
* Computes the acceleration according to the Intelligent Driver Model
Expand All @@ -24,13 +27,14 @@ public class IDM {
*/
public static double computeAcceleration(final IScope scope,
final IAgent vehicle,
final IAgent road,
final double leadingDist,
final double leadingSpeed) {
// IDM params
double T = getTimeHeadway(vehicle);
double a = getMaxAcceleration(vehicle);
double b = getMaxDeceleration(vehicle);
double v0 = getMaxSpeed(vehicle);
double v0 = Math.min(getMaxSpeed(vehicle), getSpeedCoeff(vehicle) * RoadSkill.getMaxSpeed(road));
double s0 = getMinSafetyDistance(vehicle);
double delta = getDeltaIDM(vehicle);

Expand Down
Expand Up @@ -98,10 +98,11 @@ public static ImmutablePair<Integer, Double> chooseLane(final IScope scope,
setLeadingSpeed(vehicle, leadingSpeed);
setFollower(vehicle, currentBackVehicle);
// Calculate acc(M) - Acceleration of current vehicle M if no lane change occurs
stayAccelM = IDM.computeAcceleration(scope, vehicle, leadingDist, leadingSpeed);
stayAccelM = IDM.computeAcceleration(scope, vehicle, road, leadingDist, leadingSpeed);
// Do not allow changing lane when approaching intersections
// Reason: in some cases the vehicle is forced to slow down (e.g. approaching final target in path),
// but it can gain acceleration by switching lanes to follow a fast vehicle.
// TODO: do this when leader is not a intersection
if ((leadingVehicle != null &&
leadingVehicle.getSpecies().implementsSkill(RoadNodeSkill.SKILL_ROAD_NODE)) ||
getTimeSinceLC(vehicle) < getLCCooldown(vehicle)) {
Expand Down Expand Up @@ -147,7 +148,7 @@ public static ImmutablePair<Integer, Double> chooseLane(final IScope scope,
leadingSpeed = leadingSameDirection ? leadingSpeed : -leadingSpeed;

// Calculate acc'(M) - acceleration of M on new lane
double changeAccelM = IDM.computeAcceleration(scope, vehicle, leadingDist, leadingSpeed);
double changeAccelM = IDM.computeAcceleration(scope, vehicle, road, leadingDist, leadingSpeed);

// Find back vehicle B' on new lane
double stayAccelB;
Expand All @@ -166,10 +167,10 @@ public static ImmutablePair<Integer, Double> chooseLane(final IScope scope,
double backDist = newFollowerTriple.getMiddle();
// Calculate acc(B') - acceleration of B' if M does not change to this lane
// NOTE: in this case, the leading vehicle is the one we have found above for M
stayAccelB = IDM.computeAcceleration(scope, backVehicle, backDist + VL + leadingDist, leadingSpeed);
stayAccelB = IDM.computeAcceleration(scope, backVehicle, road, backDist + VL + leadingDist, leadingSpeed);
// Calculate acc'(B') - acceleration of B' if M changes to this lane
// NOTE: in this case, M is the new leading vehicle of B'
changeAccelB = IDM.computeAcceleration(scope, backVehicle, backDist, getSpeed(vehicle));
changeAccelB = IDM.computeAcceleration(scope, backVehicle, road, backDist, getSpeed(vehicle));
}

// MOBIL params
Expand Down

0 comments on commit 9d40547

Please sign in to comment.