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-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
23   * <p>
24   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 20, 2016 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
28   */
29  
30  public class ToledoCFTester
31  {
32  
33      /**
34       * @param args String[]; arguments for the run (should be empty at the moment)
35       * @throws ParameterException when Toledo parameters cannot be found
36       * @throws GTUException when CarFollowingHeadway cannot be calculated
37       */
38      public static void main(final String[] args) throws ParameterException, GTUException
39      {
40  
41          ParameterSet params = new ParameterSet();
42          params.setDefaultParameters(ToledoCarFollowing.class);
43          ToledoCarFollowing cf = new ToledoCarFollowing();
44  
45          Speed desiredSpeed = new Speed(120, SpeedUnit.KM_PER_HOUR);
46          Duration dt = new Duration(0.5, DurationUnit.SECOND);
47          Time t = Time.ZERO;
48  
49          Speed speed = Speed.ZERO;
50          Length x = Length.ZERO;
51          Length leader = new Length(300, LengthUnit.METER);
52  
53          while (x.eq0() || speed.gt0())
54          {
55              Length s = leader.minus(x);
56              PerceptionIterable<Headway> leaders = new PerceptionIterableSet<>(new CarFollowingHeadway(s, Speed.ZERO));
57              Length desiredHeadway = cf.desiredHeadway(params, speed);
58              Acceleration a = cf.followingAcceleration(params, speed, desiredSpeed, desiredHeadway, leaders);
59              System.out.println("t=" + t + ", v=" + speed + ", s=" + s + ", a=" + a);
60  
61              a = Acceleration.max(a, speed.divideBy(dt).neg());
62              t = t.plus(dt);
63              x = new Length(x.si + speed.si * dt.si + .5 * a.si * dt.si * dt.si, LengthUnit.SI);
64              speed = new Speed(speed.si + a.si * dt.si, SpeedUnit.SI);
65  
66          }
67  
68      }
69  
70  }