View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.categories;
2   
3   import java.io.Serializable;
4   import java.util.HashMap;
5   import java.util.Map;
6   import java.util.Set;
7   import java.util.SortedSet;
8   
9   import org.opentrafficsim.base.TimeStampedObject;
10  import org.opentrafficsim.base.parameters.ParameterException;
11  import org.opentrafficsim.core.gtu.GTUException;
12  import org.opentrafficsim.core.gtu.Try;
13  import org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory;
14  import org.opentrafficsim.core.network.LateralDirectionality;
15  import org.opentrafficsim.core.network.NetworkException;
16  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
17  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
18  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
19  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
20  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
21  
22  /**
23   * <p>
24   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
26   * <p>
27   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 31 jan. 2018 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
31   */
32  public class HistoricalNeighborsPerception extends AbstractPerceptionCategory<LaneBasedGTU, LanePerception>
33          implements NeighborsPerception, Serializable
34  {
35  
36      /** */
37      private static final long serialVersionUID = 20180131L;
38  
39      /** Number of followers. */
40      private final int nFollowers;
41  
42      /** Number of leaders. */
43      private final int nLeaders;
44  
45      /** Set of followers per relative lane. */
46      private final Map<RelativeLane, TimeStampedObject<SortedSet<HeadwayGTU>>> followers = new HashMap<>();
47  
48      /** Set of leaders per relative lane. */
49      private final Map<RelativeLane, TimeStampedObject<SortedSet<HeadwayGTU>>> leaders = new HashMap<>();
50  
51      /** Set of first followers per lane upstream of merge per lateral direction, i.e. in the left or right lane. */
52      private final Map<LateralDirectionality, TimeStampedObject<SortedSet<HeadwayGTU>>> firstFollowers = new HashMap<>();
53  
54      /** Set of first leaders per lane downstream of split per lateral direction, i.e. in the left or right lane. */
55      private final Map<LateralDirectionality, TimeStampedObject<SortedSet<HeadwayGTU>>> firstLeaders = new HashMap<>();
56  
57      /** Whether a GTU is alongside per lateral direction, i.e. in the left or right lane. */
58      private final Map<LateralDirectionality, TimeStampedObject<Boolean>> gtuAlongside = new HashMap<>();
59  
60      /** Headway GTU type that should be used. */
61      private final HeadwayGtuType headwayGtuType;
62  
63      public HistoricalNeighborsPerception(final LanePerception perception, final HeadwayGtuType headwayGtuType)
64      {
65          this(perception, Integer.MAX_VALUE, Integer.MAX_VALUE, headwayGtuType);
66      }
67  
68      public HistoricalNeighborsPerception(final LanePerception perception, final int nFollowers, final int nLeaders,
69              final HeadwayGtuType headwayGtuType)
70      {
71          super(perception);
72          this.nFollowers = nFollowers;
73          this.nLeaders = nLeaders;
74          this.headwayGtuType = headwayGtuType;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public void updateAll() throws GTUException, NetworkException, ParameterException
80      {
81          this.followers.clear();
82          this.leaders.clear();
83          this.firstFollowers.clear();
84          this.firstLeaders.clear();
85          this.gtuAlongside.clear();
86          // TODO how to get a specific String to getCrossSection???
87          Set<RelativeLane> crossSection =
88                  Try.assign(() -> getPerception().getPerceptionCategory(InfrastructurePerception.class).getCrossSection(),
89                          GTUException.class, "HistoricalNeighborsPerception requires InfrastructurePerception");
90          for (RelativeLane lane : crossSection)
91          {
92  
93          }
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public void updateFirstLeaders(final LateralDirectionality lat) throws ParameterException, GTUException, NetworkException
99      {
100         updateAll();
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public void updateFirstFollowers(final LateralDirectionality lat) throws GTUException, ParameterException, NetworkException
106     {
107         updateAll();
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public void updateGtuAlongside(final LateralDirectionality lat) throws GTUException, ParameterException, NetworkException
113     {
114         updateAll();
115     }
116 
117     /** {@inheritDoc} */
118     @Override
119     public void updateLeaders(final RelativeLane lane) throws ParameterException, GTUException, NetworkException
120     {
121         updateAll();
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public void updateFollowers(final RelativeLane lane) throws GTUException, NetworkException, ParameterException
127     {
128         updateAll();
129     }
130 
131     /** {@inheritDoc} */
132     @Override
133     public SortedSet<HeadwayGTU> getFirstLeaders(LateralDirectionality lat)
134             throws ParameterException, NullPointerException, IllegalArgumentException
135     {
136         return null;
137     }
138 
139     /** {@inheritDoc} */
140     @Override
141     public SortedSet<HeadwayGTU> getFirstFollowers(LateralDirectionality lat)
142             throws ParameterException, NullPointerException, IllegalArgumentException
143     {
144         return null;
145     }
146 
147     /** {@inheritDoc} */
148     @Override
149     public boolean isGtuAlongside(LateralDirectionality lat)
150             throws ParameterException, NullPointerException, IllegalArgumentException
151     {
152         return false;
153     }
154 
155     /** {@inheritDoc} */
156     @Override
157     public PerceptionCollectable<HeadwayGTU, LaneBasedGTU> getLeaders(RelativeLane lane)
158     {
159         return null;
160     }
161 
162     /** {@inheritDoc} */
163     @Override
164     public PerceptionCollectable<HeadwayGTU, LaneBasedGTU> getFollowers(RelativeLane lane)
165     {
166         return null;
167     }
168 
169 }