AbstractOtsModel.java

  1. package org.opentrafficsim.core.dsol;

  2. import org.djunits.value.vdouble.scalar.Duration;
  3. import org.djutils.exceptions.Throw;

  4. import nl.tudelft.simulation.dsol.experiment.StreamInformation;
  5. import nl.tudelft.simulation.dsol.model.AbstractDSOLModel;
  6. import nl.tudelft.simulation.jstats.streams.MersenneTwister;

  7. /**
  8.  * AbstractOtsModel is the base class for a model that runs on an OtsSimulator.
  9.  * <p>
  10.  * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  11.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  12.  * </p>
  13.  * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
  14.  */
  15. public abstract class AbstractOtsModel extends AbstractDSOLModel<Duration, OtsSimulatorInterface> implements OtsModelInterface
  16. {
  17.     /** */
  18.     private static final long serialVersionUID = 1L;

  19.     /** a very short description of the simulation. */
  20.     private String shortName;

  21.     /** a description of the simulation (HTML formatted). */
  22.     private String description;

  23.     /**
  24.      * Instantiate an abstract OtsModel. The name and description will be set as the class name.
  25.      * @param simulator OtsSimulatorInterface; the simulator to use
  26.      */
  27.     public AbstractOtsModel(final OtsSimulatorInterface simulator)
  28.     {
  29.         this(simulator, "", "");
  30.         this.shortName = getClass().getSimpleName();
  31.         this.description = getClass().getSimpleName();
  32.     }

  33.     /**
  34.      * Instantiate an abstract OtsModel.
  35.      * @param simulator OtsSimulatorInterface; the simulator to use
  36.      * @param shortName String; a very short description of the simulation
  37.      * @param description String; a description of the simulation (HTML formatted)
  38.      */
  39.     public AbstractOtsModel(final OtsSimulatorInterface simulator, final String shortName, final String description)
  40.     {
  41.         this(simulator, shortName, description, setInitialStreams());
  42.     }

  43.     /**
  44.      * Instantiate an abstract OtsModel with an initial set of streams (e.g., with seed management).
  45.      * @param simulator OtsSimulatorInterface; the simulator to use
  46.      * @param shortName String; a very short description of the simulation
  47.      * @param description String; a description of the simulation (HTML formatted)
  48.      * @param streamInformation StreamInformation; the initial set of streams (e.g., with seed management)
  49.      */
  50.     public AbstractOtsModel(final OtsSimulatorInterface simulator, final String shortName, final String description,
  51.             final StreamInformation streamInformation)
  52.     {
  53.         super(simulator, streamInformation);
  54.         Throw.whenNull(shortName, "shortname cannot be null");
  55.         Throw.whenNull(description, "description cannot be null");
  56.         this.shortName = shortName;
  57.         this.description = description;
  58.     }

  59.     /**
  60.      * Create the default initial streams.
  61.      * @return StreamInformation; the default initial streams
  62.      */
  63.     public static StreamInformation setInitialStreams()
  64.     {
  65.         StreamInformation streamInformation = new StreamInformation();
  66.         streamInformation.addStream("default", new MersenneTwister(10L));
  67.         streamInformation.addStream("generation", new MersenneTwister(11L));
  68.         return streamInformation;
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public final String getShortName()
  73.     {
  74.         return this.shortName;
  75.     }

  76.     /**
  77.      * @param shortName String; set shortName
  78.      */
  79.     public final void setShortName(final String shortName)
  80.     {
  81.         this.shortName = shortName;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public final String getDescription()
  86.     {
  87.         return this.description;
  88.     }

  89.     /**
  90.      * @param description String; set description
  91.      */
  92.     public final void setDescription(final String description)
  93.     {
  94.         this.description = description;
  95.     }

  96. }