1 package org.opentrafficsim.road.gtu.lane.tactical;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.opentrafficsim.base.parameters.ParameterException;
8 import org.opentrafficsim.base.parameters.ParameterSet;
9 import org.opentrafficsim.base.parameters.ParameterTypes;
10 import org.opentrafficsim.base.parameters.Parameters;
11 import org.opentrafficsim.core.gtu.GTUException;
12 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModelFactory;
14 import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld;
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory
29 implements LaneBasedTacticalPlannerFactory<LaneBasedGTUFollowingDirectedChangeTacticalPlanner>, Serializable
30 {
31
32
33 private static final long serialVersionUID = 20160811L;
34
35
36 private GTUFollowingModelOld carFollowingModel;
37
38
39 private CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory;
40
41
42
43
44
45
46 public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(
47 final CarFollowingModelFactory<? extends GTUFollowingModelOld> carFollowingModelFactory)
48 {
49 this.carFollowingModel = null;
50 this.carFollowingModelFactory = carFollowingModelFactory;
51 }
52
53
54
55
56
57 public LaneBasedGTUFollowingDirectedChangeTacticalPlannerFactory(final GTUFollowingModelOld carFollowingModel)
58 {
59 this.carFollowingModel = carFollowingModel;
60 }
61
62
63 @Override
64 public final LaneBasedGTUFollowingDirectedChangeTacticalPlanner create(final LaneBasedGTU gtu) throws GTUException
65 {
66 if (this.carFollowingModel != null)
67 {
68 return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModel, gtu);
69 }
70 return new LaneBasedGTUFollowingDirectedChangeTacticalPlanner(this.carFollowingModelFactory.generateCarFollowingModel(),
71 gtu);
72 }
73
74
75 @Override
76 public final Parameters getParameters()
77 {
78 Parameters params = new ParameterSet().setDefaultParameters(ParameterTypes.class);
79 try
80 {
81 params.setParameter(ParameterTypes.LOOKAHEAD, new Length(250, LengthUnit.SI));
82 }
83 catch (ParameterException pe)
84 {
85 throw new RuntimeException("Parameter type 'LOOKAHEAD' could not be set.", pe);
86 }
87 return params;
88 }
89
90
91 @Override
92 public final String toString()
93 {
94 return "LaneBasedGTUFollowingChange0TacticalPlannerFactory [car-following=" + this.carFollowingModel + "]";
95 }
96
97 }