View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.categories;
2   
3   import java.util.HashSet;
4   import java.util.Map;
5   import java.util.Set;
6   import java.util.SortedSet;
7   import java.util.TreeSet;
8   
9   import org.opentrafficsim.base.TimeStampedObject;
10  import org.opentrafficsim.core.gtu.GTUException;
11  import org.opentrafficsim.core.gtu.RelativePosition;
12  import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
13  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
14  import org.opentrafficsim.road.gtu.lane.perception.LaneStructure.Entry;
15  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
16  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayBusStop;
17  import org.opentrafficsim.road.network.lane.conflict.Conflict;
18  import org.opentrafficsim.road.network.lane.object.BusStop;
19  
20  /**
21   * <p>
22   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
24   * <p>
25   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2017 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
28   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
29   */
30  
31  public class DirectBusStopPerception extends LaneBasedAbstractPerceptionCategory implements BusStopPerception
32  {
33  
34      /** */
35      private static final long serialVersionUID = 20170127;
36  
37      /** Bus stops. */
38      private TimeStampedObject<SortedSet<HeadwayBusStop>> busStops;
39  
40      /**
41       * @param perception perception
42       */
43      public DirectBusStopPerception(final LanePerception perception)
44      {
45          super(perception);
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public final void updateBusStops() throws GTUException, ParameterException
51      {
52          SortedSet<HeadwayBusStop> stops = new TreeSet<>();
53          Map<RelativeLane, SortedSet<Entry<BusStop>>> map = getPerception().getLaneStructure().getDownstreamObjectsOnRoute(
54                  BusStop.class, getGtu(), RelativePosition.FRONT, getGtu().getStrategicalPlanner().getRoute());
55          for (RelativeLane relativeLane : map.keySet())
56          {
57              for (Entry<BusStop> entry : map.get(relativeLane))
58              {
59                  Set<String> conflictIds = new HashSet<>();
60                  for (Conflict conflict : entry.getLaneBasedObject().getConflicts())
61                  {
62                      conflictIds.add(conflict.getId());
63                  }
64                  stops.add(new HeadwayBusStop(entry.getLaneBasedObject(), entry.getDistance(), relativeLane, conflictIds));
65              }
66          }
67          this.busStops = new TimeStampedObject<>(stops, getTimestamp());
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final SortedSet<HeadwayBusStop> getBusStops()
73      {
74          return this.busStops.getObject();
75      }
76  
77      /**
78       * Returns the time stamped bus stops.
79       * @return time stamped bus stops
80       */
81      public final TimeStampedObject<SortedSet<HeadwayBusStop>> getTimeStampedBusStops()
82      {
83          return this.busStops;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public String toString()
89      {
90          return "DirectBusStopPerception";
91      }
92  
93  }