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