Idm.java
package org.opentrafficsim.road.gtu.lane.tactical.following;
import org.djunits.value.vdouble.scalar.Acceleration;
import org.djunits.value.vdouble.scalar.Length;
import org.djunits.value.vdouble.scalar.Speed;
import org.opentrafficsim.base.parameters.ParameterException;
import org.opentrafficsim.base.parameters.Parameters;
import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
/**
* Implementation of the IDM. See <a
* href=https://en.wikipedia.org/wiki/Intelligent_driver_model>https://en.wikipedia.org/wiki/Intelligent_driver_model</a>
* <p>
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* </p>
* @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
*/
public class Idm extends AbstractIdm
{
/**
* Default constructor using default models for desired headway and desired speed.
*/
public Idm()
{
super(HEADWAY, DESIRED_SPEED);
}
/**
* Constructor with modular models for desired headway and desired speed.
* @param desiredHeadwayModel DesiredHeadwayModel; desired headway model
* @param desiredSpeedModel DesiredSpeedModel; desired speed model
*/
public Idm(final DesiredHeadwayModel desiredHeadwayModel, final DesiredSpeedModel desiredSpeedModel)
{
super(desiredHeadwayModel, desiredSpeedModel);
}
/** {@inheritDoc} */
@Override
public final String getName()
{
return "IDM";
}
/** {@inheritDoc} */
@Override
public final String getLongName()
{
return "Intelligent Driver Model";
}
/** {@inheritDoc} */
@Override
protected final Acceleration combineInteractionTerm(final Acceleration aFree, final Parameters parameters,
final Speed speed, final Speed desiredSpeed, final Length desiredHeadway,
final PerceptionIterable<? extends Headway> leaders) throws ParameterException
{
Acceleration a = parameters.getParameter(A);
Headway leader = leaders.first();
double sRatio =
dynamicDesiredHeadway(parameters, speed, desiredHeadway, leader.getSpeed()).si / leader.getDistance().si;
double aInt = -a.si * sRatio * sRatio;
return Acceleration.instantiateSI(aFree.si + aInt);
}
}