LMRSFactory.java

  1. package org.opentrafficsim.road.gtu.lane.tactical.lmrs;

  2. import java.io.Serializable;
  3. import java.util.LinkedHashSet;
  4. import java.util.Set;

  5. import org.opentrafficsim.base.parameters.ParameterException;
  6. import org.opentrafficsim.base.parameters.ParameterSet;
  7. import org.opentrafficsim.base.parameters.ParameterTypes;
  8. import org.opentrafficsim.base.parameters.Parameters;
  9. import org.opentrafficsim.core.gtu.GTUException;
  10. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  11. import org.opentrafficsim.road.gtu.lane.perception.PerceptionFactory;
  12. import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlannerFactory;
  13. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  14. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModelFactory;
  15. import org.opentrafficsim.road.gtu.lane.tactical.util.ConflictUtil;
  16. import org.opentrafficsim.road.gtu.lane.tactical.util.TrafficLightUtil;
  17. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Cooperation;
  18. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.GapAcceptance;
  19. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
  20. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsUtil;
  21. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
  22. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Synchronization;
  23. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
  24. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;

  25. /**
  26.  * Factory for a tactical planner using LMRS with any car-following model.
  27.  * <p>
  28.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  29.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  30.  * <p>
  31.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 2, 2016 <br>
  32.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  33.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  34.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  35.  */
  36. public class LMRSFactory extends AbstractLaneBasedTacticalPlannerFactory<LMRS> implements Serializable
  37. {

  38.     /** */
  39.     private static final long serialVersionUID = 20160811L;

  40.     /** Type of synchronization. */
  41.     private final Synchronization synchronization;

  42.     /** Type of cooperation. */
  43.     private final Cooperation cooperation;

  44.     /** Type of gap-acceptance. */
  45.     private final GapAcceptance gapAcceptance;

  46.     /** Type of tail gating. */
  47.     private final Tailgating tailGating;

  48.     /** Mandatory incentives. */
  49.     private final Set<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();

  50.     /** Mandatory incentives. */
  51.     private final Set<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();

  52.     /** Mandatory incentives. */
  53.     private final Set<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();

  54.     /**
  55.      * Constructor using default incentives and passive synchronization.
  56.      * @param carFollowingModelFactory factory of the car-following model
  57.      * @param perceptionFactory perception factory
  58.      * @throws GTUException if the supplied car-following model does not have an accessible empty constructor
  59.      */
  60.     public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
  61.             final PerceptionFactory perceptionFactory) throws GTUException
  62.     {
  63.         super(carFollowingModelFactory, perceptionFactory);
  64.         this.synchronization = Synchronization.PASSIVE;
  65.         this.cooperation = Cooperation.PASSIVE;
  66.         this.gapAcceptance = GapAcceptance.INFORMED;
  67.         this.tailGating = Tailgating.NONE;
  68.     }

  69.     /**
  70.      * Constructor with full control over incentives and type of synchronization.
  71.      * @param carFollowingModelFactory factory of the car-following model
  72.      * @param perceptionFactory perception factory
  73.      * @param synchronization type of synchronization
  74.      * @param cooperation type of cooperation
  75.      * @param gapAcceptance gap-acceptance
  76.      * @param tailGating tail gating
  77.      * @param mandatoryIncentives mandatory incentives; note that order may matter
  78.      * @param voluntaryIncentives voluntary incentives; note that order may matter
  79.      * @param accelerationIncentives acceleration incentives
  80.      * @throws GTUException if the supplied car-following model does not have an accessible empty constructor
  81.      */
  82.     public LMRSFactory(final CarFollowingModelFactory<? extends CarFollowingModel> carFollowingModelFactory,
  83.             final PerceptionFactory perceptionFactory, final Synchronization synchronization, final Cooperation cooperation,
  84.             final GapAcceptance gapAcceptance, final Tailgating tailGating, final Set<MandatoryIncentive> mandatoryIncentives,
  85.             final Set<VoluntaryIncentive> voluntaryIncentives, final Set<AccelerationIncentive> accelerationIncentives)
  86.             throws GTUException
  87.     {
  88.         super(carFollowingModelFactory, perceptionFactory);
  89.         this.synchronization = synchronization;
  90.         this.cooperation = cooperation;
  91.         this.gapAcceptance = gapAcceptance;
  92.         this.tailGating = tailGating;
  93.         this.mandatoryIncentives.addAll(mandatoryIncentives);
  94.         this.voluntaryIncentives.addAll(voluntaryIncentives);
  95.         this.accelerationIncentives.addAll(accelerationIncentives);
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public final Parameters getParameters() throws ParameterException
  100.     {
  101.         ParameterSet parameters = new ParameterSet();
  102.         parameters.setDefaultParameters(LmrsUtil.class);
  103.         parameters.setDefaultParameters(LmrsParameters.class);
  104.         parameters.setDefaultParameters(ConflictUtil.class);
  105.         parameters.setDefaultParameters(TrafficLightUtil.class);
  106.         getCarFollowingParameters().setAllIn(parameters);
  107.         getPerceptionFactory().getParameters().setAllIn(parameters);
  108.         parameters.setDefaultParameter(ParameterTypes.VCONG);
  109.         parameters.setDefaultParameter(ParameterTypes.T0);
  110.         parameters.setDefaultParameter(ParameterTypes.LCDUR);
  111.         return parameters;
  112.     }

  113.     /** {@inheritDoc} */
  114.     @Override
  115.     public final LMRS create(final LaneBasedGTU gtu) throws GTUException
  116.     {
  117.         LMRS lmrs = new LMRS(nextCarFollowingModel(gtu), gtu, getPerceptionFactory().generatePerception(gtu),
  118.                 this.synchronization, this.cooperation, this.gapAcceptance, this.tailGating);
  119.         if (this.mandatoryIncentives.isEmpty())
  120.         {
  121.             lmrs.setDefaultIncentives();
  122.         }
  123.         else
  124.         {
  125.             this.mandatoryIncentives.forEach(incentive -> lmrs.addMandatoryIncentive(incentive));
  126.             this.voluntaryIncentives.forEach(incentive -> lmrs.addVoluntaryIncentive(incentive));
  127.             this.accelerationIncentives.forEach(incentive -> lmrs.addAccelerationIncentive(incentive));
  128.         }
  129.         return lmrs;
  130.     }

  131.     /** {@inheritDoc} */
  132.     @Override
  133.     public final String toString()
  134.     {
  135.         return "LMRSFactory [car-following=" + getCarFollowingModelFactoryString() + "]";
  136.     }

  137. }