View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.toledo;
2   
3   import java.util.SortedMap;
4   import java.util.TreeMap;
5   
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.unit.SpeedUnit;
8   import org.djunits.unit.TimeUnit;
9   import org.djunits.value.vdouble.scalar.Acceleration;
10  import org.djunits.value.vdouble.scalar.Duration;
11  import org.djunits.value.vdouble.scalar.Length;
12  import org.djunits.value.vdouble.scalar.Speed;
13  import org.djunits.value.vdouble.scalar.Time;
14  import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
15  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
16  
17  /**
18   * <p>
19   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 20, 2016 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26   */
27  
28  public class ToledoCFTester
29  {
30  
31      /**
32       * @param args arguments for the run (should be empty at the moment)
33       * @throws ParameterException when Toledo parameters cannot be found
34       */
35      public static void main(String[] args) throws ParameterException
36      {
37  
38          BehavioralCharacteristics bc = new BehavioralCharacteristics();
39          bc.setDefaultParameters(ToledoCarFollowing.class);
40          ToledoCarFollowing cf = new ToledoCarFollowing();
41  
42          Speed desiredSpeed = new Speed(120, SpeedUnit.KM_PER_HOUR);
43          Duration dt = new Duration(0.5, TimeUnit.SECOND);
44          Time t = Time.ZERO;
45  
46          Speed speed = Speed.ZERO;
47          Length x = Length.ZERO;
48          Length leader = new Length(300, LengthUnit.METER);
49  
50          SortedMap<Length, Speed> leaders = new TreeMap<>();
51          while (x.eq(Length.ZERO) || speed.gt(Speed.ZERO))
52          {
53              Length s = leader.minus(x);
54              leaders.clear();
55              leaders.put(s, Speed.ZERO);
56              Length desiredHeadway = cf.desiredHeadway(bc, speed);
57              Acceleration a = cf.followingAcceleration(bc, speed, desiredSpeed, desiredHeadway, leaders);
58              System.out.println("t=" + t + ", v=" + speed + ", s=" + s + ", a=" + a);
59  
60              a = Acceleration.max(a, speed.divideBy(dt).multiplyBy(-1.0));
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  }