diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java index 4f3be54ca6..3280d424ef 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java @@ -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); } /** diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/IDM.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/IDM.java index 45db32167b..7e85324afe 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/IDM.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/IDM.java @@ -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; @@ -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 @@ -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); diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/MOBIL.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/MOBIL.java index f809707b79..37516da78f 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/MOBIL.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/carfollowing/MOBIL.java @@ -98,10 +98,11 @@ public static ImmutablePair 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)) { @@ -147,7 +148,7 @@ public static ImmutablePair 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; @@ -166,10 +167,10 @@ public static ImmutablePair 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