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 public class ToledoCfTester
30 {
31
32
33
34
35
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 }