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.SingleReplication;
11  
12  /**
13   * <p>
14   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$,
18   *          initial version Aug 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class OTSReplication extends SingleReplication<Duration>
22  {
23      /** History manager. */
24      private HistoryManager historyManager;
25      
26      /** the (absolute) start time of the replication. */
27      private final Time startTimeAbs;
28  
29      /**
30       * Create a new OTSReplication.
31       * @param id String; id of the new OTSReplication
32       * @param startTime Time; the start time of the new OTSReplication
33       * @param warmupPeriod Duration; the warmup period of the new OTSReplication
34       * @param runLength Duration; the run length of the new OTSReplication
35       * @throws NamingException when the context for the replication cannot be created
36       */
37      public OTSReplication(final String id, final Time startTime, final Duration warmupPeriod, final Duration runLength)
38              throws NamingException
39      {
40          super(id, Duration.ZERO, warmupPeriod, runLength);
41          this.startTimeAbs = startTime;
42      }
43  
44      /**
45       * Returns the history manager. If none was set, one is created coupled to the simulator using 0s of history and 10s
46       * clean-up time.
47       * @param simulator OTSSimulatorInterface; simulator
48       * @return HistoryManager; history manager
49       */
50      public HistoryManager getHistoryManager(final OTSSimulatorInterface simulator)
51      {
52          if (this.historyManager == null)
53          {
54              this.historyManager = new HistoryManagerDEVS(simulator, Duration.ZERO, Duration.instantiateSI(10.0));
55          }
56          return this.historyManager;
57      }
58  
59      /**
60       * Set history manager.
61       * @param historyManager HistoryManager; history manager to set
62       */
63      public void setHistoryManager(final HistoryManager historyManager)
64      {
65          this.historyManager = historyManager;
66      }
67  
68      /**
69       * Return the absolute start time of the simulation.
70       * @return Time; the absolute start time of the simulation
71       */
72      public Time getStartTimeAbs()
73      {
74          return this.startTimeAbs;
75      }
76  
77      /** */
78      private static final long serialVersionUID = 20140815L;
79  
80      /** {@inheritDoc} */
81      @Override
82      public final String toString()
83      {
84          return "OTSReplication []";
85      }
86  }