View Javadoc
1   package org.opentrafficsim.core.dsol;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djutils.exceptions.Throw;
5   
6   import nl.tudelft.simulation.dsol.experiment.StreamInformation;
7   import nl.tudelft.simulation.dsol.model.AbstractDsolModel;
8   import nl.tudelft.simulation.jstats.streams.MersenneTwister;
9   
10  /**
11   * AbstractOtsModel is the base class for a model that runs on an OtsSimulatorInterface.
12   * <p>
13   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
17   */
18  public abstract class AbstractOtsModel extends AbstractDsolModel<Duration, OtsSimulatorInterface> implements OtsModelInterface
19  {
20      /** A very short description of the simulation. */
21      private String shortName;
22  
23      /** A description of the simulation (HTML formatted). */
24      private String description;
25  
26      /**
27       * Instantiate an abstract OtsModel. The name and description will be set as the class name. Streams will be default.
28       * @param simulator the simulator to use
29       */
30      public AbstractOtsModel(final OtsSimulatorInterface simulator)
31      {
32          this(simulator, "", "", defaultInitialStreams());
33          this.shortName = getClass().getSimpleName();
34          this.description = getClass().getSimpleName();
35      }
36  
37      /**
38       * Instantiate an abstract OtsModel with an initial set of streams (e.g., with seed management).
39       * @param simulator the simulator to use
40       * @param shortName a very short description of the simulation
41       * @param description a description of the simulation (HTML formatted)
42       * @param streamInformation the initial set of streams (e.g., with seed management)
43       */
44      public AbstractOtsModel(final OtsSimulatorInterface simulator, final String shortName, final String description,
45              final StreamInformation streamInformation)
46      {
47          super(simulator, streamInformation);
48          Throw.whenNull(shortName, "shortname cannot be null");
49          Throw.whenNull(description, "description cannot be null");
50          this.shortName = shortName;
51          this.description = description;
52      }
53  
54      /**
55       * Create the default initial streams.
56       * @return the default initial streams
57       */
58      public static StreamInformation defaultInitialStreams()
59      {
60          StreamInformation streamInformation = new StreamInformation();
61          streamInformation.addStream("default", new MersenneTwister(10L));
62          streamInformation.addStream("generation", new MersenneTwister(11L));
63          return streamInformation;
64      }
65  
66      @Override
67      public final String getShortName()
68      {
69          return this.shortName;
70      }
71  
72      /**
73       * Set short name.
74       * @param shortName set shortName
75       */
76      public final void setShortName(final String shortName)
77      {
78          this.shortName = shortName;
79      }
80  
81      @Override
82      public final String getDescription()
83      {
84          return this.description;
85      }
86  
87      /**
88       * Set description.
89       * @param description set description
90       */
91      public final void setDescription(final String description)
92      {
93          this.description = description;
94      }
95  
96  }