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