View Javadoc
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   * Factory for a tactical planner using LMRS with any car-following model.
30   * <p>
31   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
32   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
33   * <p>
34   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
35   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
36   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
37   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
38   */
39  public class LMRSFactory extends AbstractLaneBasedTacticalPlannerFactory<LMRS> implements Serializable
40  {
41  
42      /** */
43      private static final long serialVersionUID = 20160811L;
44  
45      /** Type of synchronization. */
46      private final Synchronization synchronization;
47  
48      /** Type of cooperation. */
49      private final Cooperation cooperation;
50  
51      /** Type of gap-acceptance. */
52      private final GapAcceptance gapAcceptance;
53  
54      /** Type of tail gating. */
55      private final Tailgating tailGating;
56  
57      /** Mandatory incentives. */
58      private final Set<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
59  
60      /** Mandatory incentives. */
61      private final Set<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
62  
63      /** Mandatory incentives. */
64      private final Set<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();
65  
66      /**
67       * Constructor using default incentives and passive synchronization.
68       * @param carFollowingModelFactory CarFollowingModelFactory&lt;? extends CarFollowingModel&gt;; factory of the car-following
69       *            model
70       * @param perceptionFactory PerceptionFactory; perception factory
71       * @throws GTUException if the supplied car-following model does not have an accessible empty constructor
72       */
73      public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
74              final PerceptionFactory perceptionFactory) throws GTUException
75      {
76          super(carFollowingModelFactory, perceptionFactory);
77          this.synchronization = Synchronization.PASSIVE;
78          this.cooperation = Cooperation.PASSIVE;
79          this.gapAcceptance = GapAcceptance.INFORMED;
80          this.tailGating = Tailgating.NONE;
81      }
82  
83      /**
84       * Constructor with full control over incentives and type of synchronization.
85       * @param carFollowingModelFactory CarFollowingModelFactory&lt;? extends CarFollowingModel&gt;; factory of the car-following
86       *            model
87       * @param perceptionFactory PerceptionFactory; perception factory
88       * @param synchronization Synchronization; type of synchronization
89       * @param cooperation Cooperation; type of cooperation
90       * @param gapAcceptance GapAcceptance; gap-acceptance
91       * @param tailGating Tailgating; tail gating
92       * @param mandatoryIncentives mandatory incentives; note that order may matter
93       * @param voluntaryIncentives voluntary incentives; note that order may matter
94       * @param accelerationIncentives Set&lt;AccelerationIncentive&gt;; acceleration incentives
95       */
96      public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
97              final PerceptionFactory perceptionFactory, final Synchronization synchronization, final Cooperation cooperation,
98              final GapAcceptance gapAcceptance, final Tailgating tailGating, final Set<MandatoryIncentive> mandatoryIncentives,
99              final Set<VoluntaryIncentive> voluntaryIncentives, final Set<AccelerationIncentive> accelerationIncentives)
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     /** {@inheritDoc} */
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     /** {@inheritDoc} */
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     /** {@inheritDoc} */
148     @Override
149     public final String toString()
150     {
151         return "LMRSFactory [car-following=" + getCarFollowingModelFactoryString() + "]";
152     }
153 
154 }