View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.opentrafficsim.base.parameters.Parameters;
5   import org.opentrafficsim.core.gtu.Try;
6   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
7   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
8   import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
9   import org.opentrafficsim.road.gtu.lane.perception.categories.NeighborsPerception;
10  
11  /**
12   * Task demand for car-following.
13   * <p>
14   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 apr. 2018 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public class TaskCarFollowing extends TaskHeadwayBased
23  {
24  
25      /** {@inheritDoc} */
26      @Override
27      protected Duration getHeadway(final LanePerception perception, final LaneBasedGTU gtu, final Parameters parameters)
28      {
29          NeighborsPerception neighbors = Try.assign(() -> perception.getPerceptionCategory(NeighborsPerception.class),
30                  "NeighborsPerception not available.");
31          Try.execute(() -> neighbors.updateLeaders(RelativeLane.CURRENT), "Exception while updating adjacent leaders.");
32          return neighbors.getLeaders(RelativeLane.CURRENT).collect(new TaskHeadwayCollector(getSpeed()));
33      }
34  
35  }