View Javadoc
1   package org.opentrafficsim.core.network.lane;
2   
3   import java.rmi.RemoteException;
4   
5   import org.opentrafficsim.core.gtu.RelativePosition;
6   import org.opentrafficsim.core.gtu.lane.LaneBasedGTU;
7   import org.opentrafficsim.core.network.LongitudinalDirectionality;
8   import org.opentrafficsim.core.network.NetworkException;
9   import org.opentrafficsim.core.unit.FrequencyUnit;
10  import org.opentrafficsim.core.unit.LengthUnit;
11  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
12  
13  /**
14   * Lane that deletes a vehicle and unregisters its animation when the vehicle enters the lanee with its front.
15   * <p>
16   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
17   * reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
19   * <p>
20   * @version Jan 30, 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="http://Hansvanlint.weblog.tudelft.nl">Hans van Lint</a>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
25   * @author <a href="http://www.citg.tudelft.nl">Yufei Yuan</a>
26   */
27  public class SinkLane extends Lane
28  {
29  
30      /**
31       * Construct a SinkLane.
32       * @param parentLink Cross Section Link to which the element belongs.
33       * @param lateralOffsetAtStart DoubleScalar.Rel&lt;LengthUnit&gt;; the lateral offset of the design line of the new
34       *            CrossSectionLink with respect to the design line of the parent Link at the start of the parent Link
35       * @param beginWidth DoubleScalar.Rel&lt;LengthUnit&gt;; start width, positioned <i>symmetrically around</i> the
36       *            design line
37       * @param laneType type of lane to deduce compatibility with GTU types
38       * @param directionality in direction of geometry, reverse, or both
39       * @throws NetworkException when creation of the geometry fails
40       */
41      @SuppressWarnings("checkstyle:parameternumber")
42      public SinkLane(final CrossSectionLink<?, ?> parentLink, final DoubleScalar.Rel<LengthUnit> lateralOffsetAtStart,
43              final DoubleScalar.Rel<LengthUnit> beginWidth, final LaneType<?> laneType,
44              final LongitudinalDirectionality directionality) throws NetworkException
45      {
46          super(parentLink, lateralOffsetAtStart, lateralOffsetAtStart, beginWidth, beginWidth, laneType, directionality,
47                  new DoubleScalar.Abs<FrequencyUnit>(1, FrequencyUnit.SI));
48          getSensors().clear(); // no standard sensors...
49          addSensor(new SinkSensor(this));
50      }
51  
52      /**
53       * sensor that deletes the GTU.
54       * <p>
55       * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
56       * All rights reserved. <br>
57       * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
58       * <p>
59       * @version Jan 30, 2015 <br>
60       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
61       * @author <a href="http://Hansvanlint.weblog.tudelft.nl">Hans van Lint</a>
62       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
63       * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
64       * @author <a href="http://www.citg.tudelft.nl">Yufei Yuan</a>
65       */
66      private static class SinkSensor extends AbstractSensor
67      {
68          /** */
69          private static final long serialVersionUID = 20150130L;
70  
71          /**
72           * @param lane the lane that triggers the deletion of the GTU.
73           */
74          public SinkSensor(final Lane lane)
75          {
76              super(lane, new DoubleScalar.Rel<LengthUnit>(0.0, LengthUnit.METER), RelativePosition.FRONT);
77          }
78  
79          /** {@inheritDoc} */
80          @Override
81          public void trigger(final LaneBasedGTU<?> gtu) throws RemoteException
82          {
83              gtu.destroy();
84          }
85  
86      }
87  
88  }