View Javadoc
1   package org.opentrafficsim.road.network.lane.object.sensor;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.exceptions.Throw;
5   import org.opentrafficsim.core.compatibility.Compatible;
6   import org.opentrafficsim.core.gtu.RelativePosition;
7   import org.opentrafficsim.core.network.NetworkException;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.network.lane.CrossSectionElement;
10  import org.opentrafficsim.road.network.lane.Lane;
11  
12  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
13  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
14  
15  /**
16   * A SinkSensor is a sensor that deletes every GTU that hits it.
17   * <p>
18   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
19   * All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * <p>
22   * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
23   * initial version an 30, 2015 <br>
24   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
26   */
27  public class SinkSensor extends AbstractSensor
28  {
29      /** */
30      private static final long serialVersionUID = 20150130L;
31  
32      /**
33       * @param lane Lane; the lane that triggers the deletion of the GTU.
34       * @param position Length; the position of the sensor
35       * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; the simulator to enable animation.
36       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
37       */
38      public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator)
39              throws NetworkException
40      {
41          super("SINK@" + lane.getFullId(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
42      }
43  
44      /**
45       * @param dummy1 String; dummy
46       * @param lane Lane; the lane that triggers the deletion of the GTU.
47       * @param position Length; the position of the sensor
48       * @param dummy2 RelativePosition.TYPE; dummy
49       * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; the simulator to enable animation.
50       * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
51       */
52      public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
53              final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
54      {
55          super("SINK@" + lane.getFullId(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public final void triggerResponse(final LaneBasedGTU gtu)
61      {
62          gtu.destroy();
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final String toString()
68      {
69          return "SinkSensor [Lane=" + this.getLane() + "]";
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      @SuppressWarnings("checkstyle:designforextension")
75      public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator)
76              throws NetworkException
77      {
78          Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
79          Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
80                  "simulator should be a DEVSSimulator");
81          return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
82      }
83  
84  }