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
22
23
24
25
26
27
28
29
30 public class SocioDesiredSpeed implements DesiredSpeedModel, Initialisable
31 {
32
33
34 protected static final ParameterTypeDouble RHO = Tailgating.RHO;
35
36
37 protected static final ParameterTypeDouble SOCIO = LmrsParameters.SOCIO;
38
39
40 protected static final ParameterTypeSpeed VGAIN = LmrsParameters.VGAIN;
41
42
43 private LaneBasedGtu gtu;
44
45
46 private final DesiredSpeedModel baseModel;
47
48
49
50
51
52 public SocioDesiredSpeed(final DesiredSpeedModel baseModel)
53 {
54 this.baseModel = baseModel;
55 }
56
57
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
85 @Override
86 public void init(final LaneBasedGtu laneBasedGtu)
87 {
88 this.gtu = laneBasedGtu;
89 }
90
91 }