View Javadoc
1   package org.opentrafficsim.core.dsol;
2   
3   import javax.naming.NamingException;
4   
5   import org.djunits.value.vdouble.scalar.Duration;
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.core.perception.HistoryManager;
8   import org.opentrafficsim.core.perception.HistoryManagerDEVS;
9   
10  import nl.tudelft.simulation.dsol.experiment.Experiment;
11  import nl.tudelft.simulation.dsol.experiment.Replication;
12  import nl.tudelft.simulation.dsol.experiment.Treatment;
13  
14  /**
15   * <p>
16   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * <p>
19   * @version $Revision: 4886 $, $LastChangedDate: 2019-01-18 22:40:31 +0100 (Fri, 18 Jan 2019) $, by $Author: averbraeck $,
20   *          initial version Aug 15, 2014 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   */
23  public class OTSReplication extends Replication.TimeDoubleUnit<OTSSimulatorInterface>
24  {
25  
26      /** History manager. */
27      private HistoryManager historyManager;
28  
29      /**
30       * @param id String; the id of the Replication.
31       * @param experiment Experiment.TimeDoubleUnit&lt;OTSSimulatorInterface&gt;; Experiment
32       * @throws NamingException when the context for the replication cannot be created
33       */
34      public OTSReplication(final String id, final Experiment.TimeDoubleUnit<OTSSimulatorInterface> experiment)
35              throws NamingException
36      {
37          super(id, experiment);
38      }
39  
40      /**
41       * Create a new OTSReplication.
42       * @param id String; id of the new OTSReplication
43       * @param startTime Time; the start time of the new OTSReplication
44       * @param warmupPeriod Duration; the warmup period of the new OTSReplication
45       * @param runLength Duration; the run length of the new OTSReplication
46       * @param model OTSModelInterface; the model
47       * @return the created replication
48       * @throws NamingException when the context for the replication cannot be created
49       */
50      public static OTSReplication create(final String id, final Time startTime, final Duration warmupPeriod,
51              final Duration runLength, final OTSModelInterface model) throws NamingException
52      {
53          Experiment.TimeDoubleUnit<OTSSimulatorInterface> experiment = new Experiment.TimeDoubleUnit<>();
54          experiment.setModel(model);
55          Treatment.TimeDoubleUnit treatment =
56                  new Treatment.TimeDoubleUnit(experiment, "Treatment for " + id, startTime, warmupPeriod, runLength);
57          experiment.setTreatment(treatment);
58          return new OTSReplication(id, experiment);
59  
60      }
61  
62      /**
63       * Returns the history manager. If none was set, one is created coupled to the simulator using 0s of history and 10s
64       * clean-up time.
65       * @param simulator OTSSimulatorInterface; simulator
66       * @return HistoryManager; history manager
67       */
68      public HistoryManager getHistoryManager(final OTSSimulatorInterface simulator)
69      {
70          if (this.historyManager == null)
71          {
72              this.historyManager = new HistoryManagerDEVS(simulator, Duration.ZERO, Duration.createSI(10.0));
73          }
74          return this.historyManager;
75      }
76  
77      /**
78       * Set history manager.
79       * @param historyManager HistoryManager; history manager to set
80       */
81      public void setHistoryManager(final HistoryManager historyManager)
82      {
83          this.historyManager = historyManager;
84      }
85  
86      /** */
87      private static final long serialVersionUID = 20140815L;
88  
89      /** {@inheritDoc} */
90      @Override
91      public final String toString()
92      {
93          return "OTSReplication []";
94      }
95  }