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