View Javadoc
1   package org.opentrafficsim.demo.sdm;
2   
3   import java.util.LinkedHashSet;
4   import java.util.Set;
5   
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Duration;
8   import org.opentrafficsim.base.parameters.ParameterException;
9   import org.opentrafficsim.base.parameters.ParameterSet;
10  import org.opentrafficsim.base.parameters.ParameterTypes;
11  import org.opentrafficsim.base.parameters.Parameters;
12  import org.opentrafficsim.core.gtu.GTUException;
13  import org.opentrafficsim.core.gtu.GTUType;
14  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterFactoryByType;
15  import org.opentrafficsim.core.gtu.perception.DirectEgoPerception;
16  import org.opentrafficsim.core.network.Node;
17  import org.opentrafficsim.road.gtu.generator.od.StrategicalPlannerFactorySupplierOD;
18  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
19  import org.opentrafficsim.road.gtu.lane.perception.CategoricalLanePerception;
20  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
21  import org.opentrafficsim.road.gtu.lane.perception.PerceptionFactory;
22  import org.opentrafficsim.road.gtu.lane.perception.categories.AnticipationTrafficPerception;
23  import org.opentrafficsim.road.gtu.lane.perception.categories.DirectInfrastructurePerception;
24  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.Anticipation;
25  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.DirectNeighborsPerception;
26  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.Estimation;
27  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.HeadwayGtuType;
28  import org.opentrafficsim.road.gtu.lane.perception.mental.AdaptationHeadway;
29  import org.opentrafficsim.road.gtu.lane.perception.mental.AdaptationSituationalAwareness;
30  import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller;
31  import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller.BehavioralAdaptation;
32  import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller.Task;
33  import org.opentrafficsim.road.gtu.lane.perception.mental.TaskCarFollowing;
34  import org.opentrafficsim.road.gtu.lane.tactical.following.IDMPlusFactory;
35  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.AccelerationIncentive;
36  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.IncentiveKeep;
37  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.IncentiveRoute;
38  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.IncentiveSpeedWithCourtesy;
39  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.IncentiveStayRight;
40  import org.opentrafficsim.road.gtu.lane.tactical.lmrs.LMRSFactory;
41  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Cooperation;
42  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.GapAcceptance;
43  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.MandatoryIncentive;
44  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Synchronization;
45  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
46  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.VoluntaryIncentive;
47  import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlannerFactory;
48  import org.opentrafficsim.road.gtu.strategical.od.Category;
49  import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlannerFactory;
50  
51  import nl.tudelft.simulation.jstats.streams.StreamInterface;
52  
53  /**
54   * Regular strategical planner with LMRS using Fuller perception.
55   * <p>
56   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
57   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
58   * <p>
59   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 6 nov. 2018 <br>
60   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
61   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
62   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
63   */
64  
65  public class SdmStrategicalPlannerFactory implements StrategicalPlannerFactorySupplierOD
66  {
67  
68      /** Car factory. */
69      private final LaneBasedStrategicalPlannerFactory<?> carFactory;
70  
71      /** Truck factory. */
72      private final LaneBasedStrategicalPlannerFactory<?> truckFactory;
73  
74      /**
75       * Constructor.
76       * @param stream StreamInterface; random number stream
77       * @param simulation SdmSimulation; simulation to obtain properties from
78       */
79      @SuppressWarnings("synthetic-access")
80      SdmStrategicalPlannerFactory(final StreamInterface stream, final SdmSimulation simulation)
81      {
82          ParameterFactoryByType paramFactory = new ParameterFactoryByType();
83  
84          paramFactory.addParameter(Fuller.TC, simulation.getDoubleProperty("TC"));
85          paramFactory.addParameter(Fuller.TS_CRIT, simulation.getDoubleProperty("TS_CRIT"));
86          paramFactory.addParameter(Fuller.TS_MAX, simulation.getDoubleProperty("TS_MAX"));
87  
88          paramFactory.addParameter(AdaptationSituationalAwareness.SA_MIN, simulation.getDoubleProperty("SA_MIN"));
89          paramFactory.addParameter(AdaptationSituationalAwareness.SA_MAX, simulation.getDoubleProperty("SA_MAX"));
90          paramFactory.addParameter(AdaptationSituationalAwareness.TR_MAX, simulation.getDurationProperty("TR_MAX"));
91  
92          paramFactory.addParameter(AdaptationHeadway.BETA_T, simulation.getDoubleProperty("BETA_T"));
93  
94          paramFactory.addParameter(ParameterTypes.DT, simulation.getDurationProperty("DT"));
95          paramFactory.addParameter(ParameterTypes.TMIN, simulation.getDurationProperty("TMIN"));
96          paramFactory.addParameter(ParameterTypes.TMAX, simulation.getDurationProperty("TMAX"));
97          paramFactory.addParameter(ParameterTypes.T, simulation.getDurationProperty("TMAX"));
98          paramFactory.addParameter(GTUType.CAR, ParameterTypes.A, Acceleration.createSI(simulation.getDoubleProperty("A_CAR")));
99          paramFactory.addParameter(GTUType.TRUCK, ParameterTypes.A,
100                 Acceleration.createSI(simulation.getDoubleProperty("A_TRUCK")));
101         paramFactory.addParameter(ParameterTypes.B, Acceleration.createSI(simulation.getDoubleProperty("B")));
102 
103         Set<MandatoryIncentive> mandatoryIncentives = new LinkedHashSet<>();
104         mandatoryIncentives.add(new IncentiveRoute());
105         Set<VoluntaryIncentive> voluntaryIncentives = new LinkedHashSet<>();
106         voluntaryIncentives.add(new IncentiveSpeedWithCourtesy());
107         voluntaryIncentives.add(new IncentiveKeep());
108         Set<AccelerationIncentive> accelerationIncentives = new LinkedHashSet<>();
109         // accelerationIncentives.add(new AccelerationNoRightOvertake());
110         PerceptionFactory perceptionFactory = new SdmPerception();
111         this.carFactory = new LaneBasedStrategicalRoutePlannerFactory(new LMRSFactory(new IDMPlusFactory(stream),
112                 perceptionFactory, Synchronization.ALIGN_GAP, Cooperation.PASSIVE, GapAcceptance.INFORMED, Tailgating.NONE,
113                 mandatoryIncentives, voluntaryIncentives, accelerationIncentives), paramFactory);
114 
115         voluntaryIncentives = new LinkedHashSet<>(voluntaryIncentives);
116         voluntaryIncentives.add(new IncentiveStayRight());
117         this.truckFactory = new LaneBasedStrategicalRoutePlannerFactory(new LMRSFactory(new IDMPlusFactory(stream),
118                 perceptionFactory, Synchronization.ALIGN_GAP, Cooperation.PASSIVE, GapAcceptance.INFORMED, Tailgating.NONE,
119                 mandatoryIncentives, voluntaryIncentives, accelerationIncentives), paramFactory);
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public LaneBasedStrategicalPlannerFactory<?> getFactory(final Node origin, final Node destination, final Category category,
125             final StreamInterface randomStream) throws GTUException
126     {
127         if (category.get(GTUType.class).isOfType(GTUType.TRUCK))
128         {
129             return this.truckFactory;
130         }
131         return this.carFactory;
132     }
133 
134     /**
135      * Factory for perception with Fuller.
136      * <p>
137      * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
138      * <br>
139      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
140      * <p>
141      * @version $Revision$, $LastChangedDate$, by $Author$, initial version 6 nov. 2018 <br>
142      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
143      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
144      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
145      */
146     private class SdmPerception implements PerceptionFactory
147     {
148         /** {@inheritDoc} */
149         @Override
150         public Parameters getParameters() throws ParameterException
151         {
152             ParameterSet params = new ParameterSet();
153             params.setDefaultParameters(Fuller.class);
154             params.setDefaultParameters(AdaptationSituationalAwareness.class);
155             params.setDefaultParameter(AdaptationHeadway.BETA_T);
156             params.setDefaultParameter(ParameterTypes.PERCEPTION);
157             params.setDefaultParameter(ParameterTypes.LOOKBACK);
158             params.setDefaultParameter(ParameterTypes.LOOKAHEAD);
159             params.setParameter(ParameterTypes.TR, Duration.ZERO);
160             return params;
161         }
162 
163         /** {@inheritDoc} */
164         @Override
165         public LanePerception generatePerception(final LaneBasedGTU gtu)
166         {
167             Set<Task> tasks = new LinkedHashSet<>();
168             tasks.add(new TaskCarFollowing());
169             Set<BehavioralAdaptation> adaptations = new LinkedHashSet<>();
170             adaptations.add(new AdaptationSituationalAwareness());
171             adaptations.add(new AdaptationHeadway());
172             CategoricalLanePerception perception = new CategoricalLanePerception(gtu, new Fuller(tasks, adaptations));
173             perception.addPerceptionCategory(new DirectEgoPerception<>(perception));
174             perception.addPerceptionCategory(new AnticipationTrafficPerception(perception));
175             perception.addPerceptionCategory(new DirectInfrastructurePerception(perception));
176             perception.addPerceptionCategory(new DirectNeighborsPerception(perception,
177                     new HeadwayGtuType.PerceivedHeadwayGtuType(Estimation.UNDERESTIMATION, Anticipation.CONSTANT_SPEED)));
178             return perception;
179         }
180     }
181 
182 }