View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import org.djunits.value.vdouble.scalar.Speed;
4   import org.opentrafficsim.base.parameters.ParameterException;
5   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
6   import org.opentrafficsim.base.parameters.ParameterTypeSpeed;
7   import org.opentrafficsim.base.parameters.Parameters;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
10  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
11  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
12  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.NeighborsPerception;
13  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
14  import org.opentrafficsim.road.gtu.lane.tactical.following.DesiredSpeedModel;
15  import org.opentrafficsim.road.gtu.lane.tactical.following.Initialisable;
16  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.LmrsParameters;
17  import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Tailgating;
18  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
19  
20  /**
21   * Wrapper of a base-desired speed model. The speed may be increased due to social pressure from the follower.
22   * <p>
23   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
25   * <p>
26   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 7 mrt. 2018 <br>
27   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
28   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
29   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
30   */
31  public class SocioDesiredSpeed implements DesiredSpeedModel, Initialisable
32  {
33  
34      /** Social pressure applied to the leader. */
35      protected static final ParameterTypeDouble RHO = Tailgating.RHO;
36  
37      /** Socio-speed sensitivity parameter. */
38      protected static final ParameterTypeDouble SOCIO = LmrsParameters.SOCIO;
39  
40      /** Vgain parameter; ego-speed sensitivity. */
41      protected static final ParameterTypeSpeed VGAIN = LmrsParameters.VGAIN;
42  
43      /** GTU. */
44      private LaneBasedGTU gtu;
45  
46      /** Base model for desired speed. */
47      private final DesiredSpeedModel baseModel;
48  
49      /**
50       * Constructor.
51       * @param baseModel DesiredSpeedModel; base model for desired speed
52       */
53      public SocioDesiredSpeed(final DesiredSpeedModel baseModel)
54      {
55          this.baseModel = baseModel;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
61      {
62          Speed desiredSpeed = this.baseModel.desiredSpeed(parameters, speedInfo);
63          if (this.gtu == null)
64          {
65              return desiredSpeed;
66          }
67          PerceptionCollectable<HeadwayGTU, LaneBasedGTU> followers;
68          LanePerception perception = this.gtu.getTacticalPlanner().getPerception();
69          NeighborsPerception neighbors = perception.getPerceptionCategoryOrNull(NeighborsPerception.class);
70          if (neighbors != null)
71          {
72              followers = neighbors.getFollowers(RelativeLane.CURRENT);
73              if (!followers.isEmpty())
74              {
75                  double sigma = parameters.getParameter(SOCIO);
76                  Speed vGain = parameters.getParameter(VGAIN);
77                  HeadwayGTU follower = followers.first();
78                  double rhoFollower = follower.getParameters().getParameter(RHO);
79                  desiredSpeed = Speed.createSI(desiredSpeed.si + rhoFollower * sigma * vGain.si);
80              }
81          }
82          return desiredSpeed;
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public void init(final LaneBasedGTU laneBasedGtu)
88      {
89          this.gtu = laneBasedGtu;
90      }
91  
92  }