1 package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2
3 import java.io.Serializable;
4 import java.util.LinkedHashSet;
5 import java.util.Set;
6
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.perception.PerceptionFactory;
14 import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlannerFactory;
15 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
16 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModelFactory;
17 import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
18 import org.opentrafficsim.road.gtu.lane.tactical.util.TrafficLightUtil;
19 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Cooperation;
20 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.GapAcceptance;
21 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
22 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
23 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
24 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Synchronization;
25 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
26 import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
27
28
29
30
31
32
33
34
35
36
37
38
39 public class LMRSFactory extends AbstractLaneBasedTacticalPlannerFactory<LMRS> implements Serializable
40 {
41
42
43 private static final long serialVersionUID = 20160811L;
44
45
46 private final Synchronization synchronization;
47
48
49 private final Cooperation cooperation;
50
51
52 private final GapAcceptance gapAcceptance;
53
54
55 private final Tailgating tailGating;
56
57
58 private final Set<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
59
60
61 private final Set<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
62
63
64 private final Set<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();
65
66
67
68
69
70
71
72 public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
73 final PerceptionFactory perceptionFactory) throws GTUException
74 {
75 super(carFollowingModelFactory, perceptionFactory);
76 this.synchronization = Synchronization.PASSIVE;
77 this.cooperation = Cooperation.PASSIVE;
78 this.gapAcceptance = GapAcceptance.INFORMED;
79 this.tailGating = Tailgating.NONE;
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
96 final PerceptionFactory perceptionFactory, final Synchronization synchronization, final Cooperation cooperation,
97 final GapAcceptance gapAcceptance, final Tailgating tailGating, final Set<MandatoryIncentive> mandatoryIncentives,
98 final Set<VoluntaryIncentive> voluntaryIncentives, final Set<AccelerationIncentive> accelerationIncentives)
99 throws GTUException
100 {
101 super(carFollowingModelFactory, perceptionFactory);
102 this.synchronization = synchronization;
103 this.cooperation = cooperation;
104 this.gapAcceptance = gapAcceptance;
105 this.tailGating = tailGating;
106 this.mandatoryIncentives.addAll(mandatoryIncentives);
107 this.voluntaryIncentives.addAll(voluntaryIncentives);
108 this.accelerationIncentives.addAll(accelerationIncentives);
109 }
110
111
112 @Override
113 public final Parameters getParameters() throws ParameterException
114 {
115 ParameterSet parameters = new ParameterSet();
116 parameters.setDefaultParameters(LmrsUtil.class);
117 parameters.setDefaultParameters(LmrsParameters.class);
118 parameters.setDefaultParameters(ConflictUtil.class);
119 parameters.setDefaultParameters(TrafficLightUtil.class);
120 getCarFollowingParameters().setAllIn(parameters);
121 getPerceptionFactory().getParameters().setAllIn(parameters);
122 parameters.setDefaultParameter(ParameterTypes.VCONG);
123 parameters.setDefaultParameter(ParameterTypes.T0);
124 parameters.setDefaultParameter(ParameterTypes.LCDUR);
125 return parameters;
126 }
127
128
129 @Override
130 public final LMRS create(final LaneBasedGTU gtu) throws GTUException
131 {
132 LMRS lmrs = new LMRS(nextCarFollowingModel(gtu), gtu, getPerceptionFactory().generatePerception(gtu),
133 this.synchronization, this.cooperation, this.gapAcceptance, this.tailGating);
134 if (this.mandatoryIncentives.isEmpty())
135 {
136 lmrs.setDefaultIncentives();
137 }
138 else
139 {
140 this.mandatoryIncentives.forEach(incentive -> lmrs.addMandatoryIncentive(incentive));
141 this.voluntaryIncentives.forEach(incentive -> lmrs.addVoluntaryIncentive(incentive));
142 this.accelerationIncentives.forEach(incentive -> lmrs.addAccelerationIncentive(incentive));
143 }
144 return lmrs;
145 }
146
147
148 @Override
149 public final String toString()
150 {
151 return "LMRSFactory [car-following=" + getCarFollowingModelFactoryString() + "]";
152 }
153
154 }