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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
28   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
29   */
30  public class SocioDesiredSpeed implements DesiredSpeedModel, Initialisable
31  {
32  
33      /** Social pressure applied to the leader. */
34      protected static final ParameterTypeDouble RHO = Tailgating.RHO;
35  
36      /** Socio-speed sensitivity parameter. */
37      protected static final ParameterTypeDouble SOCIO = LmrsParameters.SOCIO;
38  
39      /** Vgain parameter; ego-speed sensitivity. */
40      protected static final ParameterTypeSpeed VGAIN = LmrsParameters.VGAIN;
41  
42      /** GTU. */
43      private LaneBasedGtu gtu;
44  
45      /** Base model for desired speed. */
46      private final DesiredSpeedModel baseModel;
47  
48      /**
49       * Constructor.
50       * @param baseModel DesiredSpeedModel; base model for desired speed
51       */
52      public SocioDesiredSpeed(final DesiredSpeedModel baseModel)
53      {
54          this.baseModel = baseModel;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public Speed desiredSpeed(final Parameters parameters, final SpeedLimitInfo speedInfo) throws ParameterException
60      {
61          Speed desiredSpeed = this.baseModel.desiredSpeed(parameters, speedInfo);
62          if (this.gtu == null)
63          {
64              return desiredSpeed;
65          }
66          PerceptionCollectable<HeadwayGtu, LaneBasedGtu> followers;
67          LanePerception perception = this.gtu.getTacticalPlanner().getPerception();
68          NeighborsPerception neighbors = perception.getPerceptionCategoryOrNull(NeighborsPerception.class);
69          if (neighbors != null)
70          {
71              followers = neighbors.getFollowers(RelativeLane.CURRENT);
72              if (!followers.isEmpty())
73              {
74                  double sigma = parameters.getParameter(SOCIO);
75                  Speed vGain = parameters.getParameter(VGAIN);
76                  HeadwayGtu follower = followers.first();
77                  double rhoFollower = follower.getParameters().getParameter(RHO);
78                  desiredSpeed = Speed.instantiateSI(desiredSpeed.si + rhoFollower * sigma * vGain.si);
79              }
80          }
81          return desiredSpeed;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public void init(final LaneBasedGtu laneBasedGtu)
87      {
88          this.gtu = laneBasedGtu;
89      }
90  
91  }