View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.LinkedHashSet;
4   
5   import org.djutils.immutablecollections.Immutable;
6   import org.djutils.immutablecollections.ImmutableLinkedHashSet;
7   import org.djutils.immutablecollections.ImmutableSet;
8   import org.opentrafficsim.base.parameters.ParameterTypeClassList;
9   import org.opentrafficsim.base.parameters.constraint.ClassCollectionConstraint;
10  import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
11  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
12  import org.opentrafficsim.road.gtu.lane.tactical.AbstractLaneBasedTacticalPlanner;
13  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
14  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
15  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
16  
17  /**
18   * <p>
19   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * </p>
22   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
24   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
25   */
26  public abstract class AbstractIncentivesTacticalPlanner extends AbstractLaneBasedTacticalPlanner
27  {
28  
29      /** */
30      private static final long serialVersionUID = 20190731L;
31  
32      /**
33       * Constructor.
34       * @param carFollowingModel CarFollowingModel; Car-following model.
35       * @param gtu LaneBasedGtu; GTU
36       * @param lanePerception LanePerception; perception
37       */
38      public AbstractIncentivesTacticalPlanner(final CarFollowingModel carFollowingModel, final LaneBasedGtu gtu,
39              final LanePerception lanePerception)
40      {
41          super(carFollowingModel, gtu, lanePerception);
42      }
43  
44      /** Parameter type for mandatory lane change incentives. */
45      public static final ParameterTypeClassList<MandatoryIncentive> MANDATORY = new ParameterTypeClassList<>("man.incent.",
46              "Mandatory lane-change incentives.", ParameterTypeClassList.getValueClass(MandatoryIncentive.class));
47  
48      /** Parameter type for voluntary lane change incentives. */
49      public static final ParameterTypeClassList<VoluntaryIncentive> VOLUNTARY = new ParameterTypeClassList<>("vol.incent.",
50              "Voluntary lane-change incentives.", ParameterTypeClassList.getValueClass(VoluntaryIncentive.class));
51  
52      /** Parameter type for acceleration incentives. */
53      public static final ParameterTypeClassList<AccelerationIncentive> ACCELERATION = new ParameterTypeClassList<>("acc.incent.",
54              "Acceleration incentives.", ParameterTypeClassList.getValueClass(AccelerationIncentive.class),
55              ClassCollectionConstraint.newInstance(AccelerationBusStop.class));
56  
57      /** Set of mandatory lane change incentives. */
58      private final LinkedHashSet<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
59  
60      /** Set of voluntary lane change incentives. */
61      private final LinkedHashSet<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
62  
63      /** Set of acceleration incentives. */
64      private final LinkedHashSet<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();
65  
66      /** Immutable set of mandatory lane change incentives. */
67      private final ImmutableSet<MandatoryIncentive> immutableMandatoryIncentives =
68              new ImmutableLinkedHashSet<>(this.mandatoryIncentives, Immutable.WRAP);
69  
70      /** Immutable set of voluntary lane change incentives. */
71      private final ImmutableSet<VoluntaryIncentive> immutableVoluntaryIncentives =
72              new ImmutableLinkedHashSet<>(this.voluntaryIncentives, Immutable.WRAP);
73  
74      /** Immutable set of acceleration lane change incentives. */
75      private final ImmutableSet<AccelerationIncentive> immutableAccelerationIncentives =
76              new ImmutableLinkedHashSet<>(this.accelerationIncentives, Immutable.WRAP);
77  
78      /**
79       * Adds a mandatory incentive. Ignores {@code null}.
80       * @param incentive MandatoryIncentive; Incentive to add.
81       */
82      public final void addMandatoryIncentive(final MandatoryIncentive incentive)
83      {
84          if (incentive != null)
85          {
86              this.mandatoryIncentives.add(incentive);
87          }
88      }
89  
90      /**
91       * Adds a voluntary incentive. Ignores {@code null}.
92       * @param incentive VoluntaryIncentive; Incentive to add.
93       */
94      public final void addVoluntaryIncentive(final VoluntaryIncentive incentive)
95      {
96          if (incentive != null)
97          {
98              this.voluntaryIncentives.add(incentive);
99          }
100     }
101 
102     /**
103      * Adds an acceleration incentive. Ignores {@code null}.
104      * @param incentive AccelerationIncentive; Incentive to add.
105      */
106     public final void addAccelerationIncentive(final AccelerationIncentive incentive)
107     {
108         if (incentive != null)
109         {
110             this.accelerationIncentives.add(incentive);
111         }
112     }
113 
114     /**
115      * Sets the default lane change incentives.
116      */
117     public final void setDefaultIncentives()
118     {
119         this.mandatoryIncentives.clear();
120         this.voluntaryIncentives.clear();
121         this.accelerationIncentives.clear();
122         this.mandatoryIncentives.add(new IncentiveRoute());
123         // this.mandatoryIncentives.add(new IncentiveGetInLane());
124         this.voluntaryIncentives.add(new IncentiveSpeedWithCourtesy());
125         this.voluntaryIncentives.add(new IncentiveKeep());
126         this.voluntaryIncentives.add(new IncentiveQueue());
127         this.accelerationIncentives.add(new AccelerationSpeedLimitTransition());
128         this.accelerationIncentives.add(new AccelerationTrafficLights());
129         this.accelerationIncentives.add(new AccelerationConflicts());
130     }
131 
132     /**
133      * Returns the mandatory incentives.
134      * @return ImmutableSet&lt;MandatoryIncentive&gt;; set of mandatory incentives
135      */
136     public final ImmutableSet<MandatoryIncentive> getMandatoryIncentives()
137     {
138         return this.immutableMandatoryIncentives;
139     }
140 
141     /**
142      * Returns the voluntary incentives.
143      * @return ImmutableSet&lt;VoluntaryIncentive&gt;; set of voluntary incentives
144      */
145     public final ImmutableSet<VoluntaryIncentive> getVoluntaryIncentives()
146     {
147         return this.immutableVoluntaryIncentives;
148     }
149 
150     /**
151      * Returns the acceleration incentives.
152      * @return ImmutableSet&lt;AccelerationIncentive&gt;; set of acceleration incentives
153      */
154     public final ImmutableSet<AccelerationIncentive> getAccelerationIncentives()
155     {
156         return this.immutableAccelerationIncentives;
157     }
158 
159 }