View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.toledo;
2   
3   import org.djunits.unit.DurationUnit;
4   import org.djunits.unit.LengthUnit;
5   import org.djunits.unit.SpeedUnit;
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Duration;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.djunits.value.vdouble.scalar.Speed;
10  import org.djunits.value.vdouble.scalar.Time;
11  import org.opentrafficsim.base.parameters.ParameterException;
12  import org.opentrafficsim.base.parameters.ParameterSet;
13  import org.opentrafficsim.core.gtu.GtuException;
14  import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterable;
15  import org.opentrafficsim.road.gtu.lane.perception.PerceptionIterableSet;
16  import org.opentrafficsim.road.gtu.lane.perception.headway.Headway;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.CarFollowingUtil.CarFollowingHeadway;
18  
19  /**
20   * <p>
21   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * </p>
24   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
26   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
27   */
28  
29  public class ToledoCfTester
30  {
31  
32      /**
33       * @param args String[]; arguments for the run (should be empty at the moment)
34       * @throws ParameterException when Toledo parameters cannot be found
35       * @throws GtuException when CarFollowingHeadway cannot be calculated
36       */
37      public static void main(final String[] args) throws ParameterException, GtuException
38      {
39  
40          ParameterSet params = new ParameterSet();
41          params.setDefaultParameters(ToledoCarFollowing.class);
42          ToledoCarFollowing cf = new ToledoCarFollowing();
43  
44          Speed desiredSpeed = new Speed(120, SpeedUnit.KM_PER_HOUR);
45          Duration dt = new Duration(0.5, DurationUnit.SECOND);
46          Time t = Time.ZERO;
47  
48          Speed speed = Speed.ZERO;
49          Length x = Length.ZERO;
50          Length leader = new Length(300, LengthUnit.METER);
51  
52          while (x.eq0() || speed.gt0())
53          {
54              Length s = leader.minus(x);
55              PerceptionIterable<Headway> leaders = new PerceptionIterableSet<>(new CarFollowingHeadway(s, Speed.ZERO));
56              Length desiredHeadway = cf.desiredHeadway(params, speed);
57              Acceleration a = cf.followingAcceleration(params, speed, desiredSpeed, desiredHeadway, leaders);
58              System.out.println("t=" + t + ", v=" + speed + ", s=" + s + ", a=" + a);
59  
60              a = Acceleration.max(a, speed.divide(dt).neg());
61              t = t.plus(dt);
62              x = new Length(x.si + speed.si * dt.si + .5 * a.si * dt.si * dt.si, LengthUnit.SI);
63              speed = new Speed(speed.si + a.si * dt.si, SpeedUnit.SI);
64  
65          }
66  
67      }
68  
69  }