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