1 package org.opentrafficsim.road.gtu.lane.perception;
2
3 import org.opentrafficsim.base.parameters.ParameterException;
4 import org.opentrafficsim.base.parameters.ParameterTypeLength;
5 import org.opentrafficsim.base.parameters.ParameterTypes;
6 import org.opentrafficsim.core.gtu.GtuException;
7 import org.opentrafficsim.core.gtu.perception.AbstractPerception;
8 import org.opentrafficsim.core.network.NetworkException;
9 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
10 import org.opentrafficsim.road.gtu.lane.perception.mental.Mental;
11 import org.opentrafficsim.road.gtu.lane.perception.structure.LaneStructure;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class CategoricalLanePerception extends AbstractPerception<LaneBasedGtu> implements LanePerception
35 {
36
37
38 private static final long serialVersionUID = 20151128L;
39
40
41 protected static final ParameterTypeLength LOOKAHEAD = ParameterTypes.LOOKAHEAD;
42
43
44 protected static final ParameterTypeLength LOOKBACK = ParameterTypes.LOOKBACK;
45
46
47 private LaneStructure laneStructure = null;
48
49
50 private Mental mental;
51
52
53
54
55
56 public CategoricalLanePerception(final LaneBasedGtu gtu)
57 {
58 super(gtu);
59 this.mental = null;
60 }
61
62
63
64
65
66
67 public CategoricalLanePerception(final LaneBasedGtu gtu, final Mental mental)
68 {
69 super(gtu);
70 this.mental = mental;
71 }
72
73 @Override
74 public final LaneStructure getLaneStructure() throws ParameterException
75 {
76 if (this.laneStructure == null)
77 {
78 this.laneStructure = new LaneStructure(getGtu(), getGtu().getParameters().getParameter(LOOKBACK),
79 getGtu().getParameters().getParameter(LOOKAHEAD));
80 }
81 return this.laneStructure;
82 }
83
84 @Override
85 public Mental getMental()
86 {
87 return this.mental;
88 }
89
90 @Override
91 public void perceive() throws GtuException, NetworkException, ParameterException
92 {
93 if (this.mental != null)
94 {
95 this.mental.apply(this);
96 }
97 }
98
99 }