SinkSensor.java

  1. package org.opentrafficsim.road.network.lane.object.sensor;

  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.djutils.exceptions.Throw;
  4. import org.opentrafficsim.core.compatibility.Compatible;
  5. import org.opentrafficsim.core.gtu.RelativePosition;
  6. import org.opentrafficsim.core.network.NetworkException;
  7. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  8. import org.opentrafficsim.road.network.lane.CrossSectionElement;
  9. import org.opentrafficsim.road.network.lane.Lane;

  10. import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
  11. import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;

  12. /**
  13.  * A SinkSensor is a sensor that deletes every GTU that hits it.
  14.  * <p>
  15.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
  16.  * All rights reserved. <br>
  17.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  18.  * <p>
  19.  * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
  20.  * initial version an 30, 2015 <br>
  21.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  22.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  23.  */
  24. public class SinkSensor extends AbstractSensor
  25. {
  26.     /** */
  27.     private static final long serialVersionUID = 20150130L;

  28.     /**
  29.      * @param lane Lane; the lane that triggers the deletion of the GTU.
  30.      * @param position Length; the position of the sensor
  31.      * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; the simulator to enable animation.
  32.      * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
  33.      */
  34.     public SinkSensor(final Lane lane, final Length position, final DEVSSimulatorInterface.TimeDoubleUnit simulator)
  35.             throws NetworkException
  36.     {
  37.         super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
  38.     }

  39.     /**
  40.      * @param dummy1 String; dummy
  41.      * @param lane Lane; the lane that triggers the deletion of the GTU.
  42.      * @param position Length; the position of the sensor
  43.      * @param dummy2 RelativePosition.TYPE; dummy
  44.      * @param simulator DEVSSimulatorInterface.TimeDoubleUnit; the simulator to enable animation.
  45.      * @throws NetworkException when the position on the lane is out of bounds w.r.t. the center line of the lane
  46.      */
  47.     public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
  48.             final DEVSSimulatorInterface.TimeDoubleUnit simulator) throws NetworkException
  49.     {
  50.         super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator, Compatible.EVERYTHING);
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public final void triggerResponse(final LaneBasedGTU gtu)
  55.     {
  56.         gtu.destroy();
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public final String toString()
  61.     {
  62.         return "SinkSensor [Lane=" + this.getLane() + "]";
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     @SuppressWarnings("checkstyle:designforextension")
  67.     public SinkSensor clone(final CrossSectionElement newCSE, final SimulatorInterface.TimeDoubleUnit newSimulator)
  68.             throws NetworkException
  69.     {
  70.         Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
  71.         Throw.when(!(newSimulator instanceof DEVSSimulatorInterface.TimeDoubleUnit), NetworkException.class,
  72.                 "simulator should be a DEVSSimulator");
  73.         return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (DEVSSimulatorInterface.TimeDoubleUnit) newSimulator);
  74.     }

  75. }