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 public class LmrsFactory extends AbstractLaneBasedTacticalPlannerFactory<Lmrs> implements Serializable
39 {
40
41
42 private static final long serialVersionUID = 20160811L;
43
44
45 private final Synchronization synchronization;
46
47
48 private final Cooperation cooperation;
49
50
51 private final GapAcceptance gapAcceptance;
52
53
54 private final Tailgating tailgating;
55
56
57 private final Set<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
58
59
60 private final Set<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
61
62
63 private final Set<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();
64
65
66
67
68
69
70
71 public LmrsFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
72 final PerceptionFactory perceptionFactory)
73 {
74 super(carFollowingModelFactory, perceptionFactory);
75 this.synchronization = Synchronization.PASSIVE;
76 this.cooperation = Cooperation.PASSIVE;
77 this.gapAcceptance = GapAcceptance.INFORMED;
78 this.tailgating = Tailgating.NONE;
79 }
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public LmrsFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
95 final PerceptionFactory perceptionFactory, final Synchronization synchronization, final Cooperation cooperation,
96 final GapAcceptance gapAcceptance, final Tailgating tailgating, final Set<MandatoryIncentive> mandatoryIncentives,
97 final Set<VoluntaryIncentive> voluntaryIncentives, final Set<AccelerationIncentive> accelerationIncentives)
98 {
99 super(carFollowingModelFactory, perceptionFactory);
100 this.synchronization = synchronization;
101 this.cooperation = cooperation;
102 this.gapAcceptance = gapAcceptance;
103 this.tailgating = tailgating;
104 this.mandatoryIncentives.addAll(mandatoryIncentives);
105 this.voluntaryIncentives.addAll(voluntaryIncentives);
106 this.accelerationIncentives.addAll(accelerationIncentives);
107 }
108
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 }