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
21
22
23
24
25
26
27
28
29
30 public class ToledoCFTester
31 {
32
33
34
35
36
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 =
57 new PerceptionIterableSet<>(new CarFollowingHeadway(s, Speed.ZERO));
58 Length desiredHeadway = cf.desiredHeadway(params, speed);
59 Acceleration a = cf.followingAcceleration(params, speed, desiredSpeed, desiredHeadway, leaders);
60 System.out.println("t=" + t + ", v=" + speed + ", s=" + s + ", a=" + a);
61
62 a = Acceleration.max(a, speed.divideBy(dt).neg());
63 t = t.plus(dt);
64 x = new Length(x.si + speed.si * dt.si + .5 * a.si * dt.si * dt.si, LengthUnit.SI);
65 speed = new Speed(speed.si + a.si * dt.si, SpeedUnit.SI);
66
67 }
68
69 }
70
71 }