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 OtsSimulator.
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      /** */
21      private static final long serialVersionUID = 1L;
22  
23      /** a very short description of the simulation. */
24      private String shortName;
25  
26      /** a description of the simulation (HTML formatted). */
27      private String description;
28  
29      /**
30       * Instantiate an abstract OtsModel. The name and description will be set as the class name.
31       * @param simulator OtsSimulatorInterface; the simulator to use
32       */
33      public AbstractOtsModel(final OtsSimulatorInterface simulator)
34      {
35          this(simulator, "", "");
36          this.shortName = getClass().getSimpleName();
37          this.description = getClass().getSimpleName();
38      }
39  
40      /**
41       * Instantiate an abstract OtsModel.
42       * @param simulator OtsSimulatorInterface; the simulator to use
43       * @param shortName String; a very short description of the simulation
44       * @param description String; a description of the simulation (HTML formatted)
45       */
46      public AbstractOtsModel(final OtsSimulatorInterface simulator, final String shortName, final String description)
47      {
48          this(simulator, shortName, description, setInitialStreams());
49      }
50  
51      /**
52       * Instantiate an abstract OtsModel with an initial set of streams (e.g., with seed management).
53       * @param simulator OtsSimulatorInterface; the simulator to use
54       * @param shortName String; a very short description of the simulation
55       * @param description String; a description of the simulation (HTML formatted)
56       * @param streamInformation StreamInformation; the initial set of streams (e.g., with seed management)
57       */
58      public AbstractOtsModel(final OtsSimulatorInterface simulator, final String shortName, final String description,
59              final StreamInformation streamInformation)
60      {
61          super(simulator, streamInformation);
62          Throw.whenNull(shortName, "shortname cannot be null");
63          Throw.whenNull(description, "description cannot be null");
64          this.shortName = shortName;
65          this.description = description;
66      }
67  
68      /**
69       * Create the default initial streams.
70       * @return StreamInformation; the default initial streams
71       */
72      public static StreamInformation setInitialStreams()
73      {
74          StreamInformation streamInformation = new StreamInformation();
75          streamInformation.addStream("default", new MersenneTwister(10L));
76          streamInformation.addStream("generation", new MersenneTwister(11L));
77          return streamInformation;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public final String getShortName()
83      {
84          return this.shortName;
85      }
86  
87      /**
88       * @param shortName String; set shortName
89       */
90      public final void setShortName(final String shortName)
91      {
92          this.shortName = shortName;
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public final String getDescription()
98      {
99          return this.description;
100     }
101 
102     /**
103      * @param description String; set description
104      */
105     public final void setDescription(final String description)
106     {
107         this.description = description;
108     }
109 
110 }