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
19
20
21
22
23
24
25
26
27
28 public class ToledoCFTester
29 {
30
31
32
33
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 }