View Javadoc
1   package nl.tudelft.simulation.dsol.experiment;
2   
3   import java.util.Objects;
4   
5   import org.djutils.exceptions.Throw;
6   
7   import nl.tudelft.simulation.dsol.simtime.SimTime;
8   
9   /**
10   * RunControl is a data object that contains off-line run control information. It can be fed to an Experiment or a Replication
11   * to set the run control parameters for a simulation run.
12   * <p>
13   * Copyright (c) 2021-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
14   * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
15   * project is distributed under a three-clause BSD-style license, which can be found at
16   * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
17   * </p>
18   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a> relative types are the same.
19   * @param <T> the simulation time type to be able to implement a comparator on the simulation time.
20   */
21  public class RunControl<T extends Number & Comparable<T>> implements Treatment<T>
22  {
23      /** */
24      private static final long serialVersionUID = 20210409L;
25  
26      /** the id of the replication. */
27      private final String id;
28  
29      /** the description of the replication (if not set, the id will be used). */
30      private String description;
31  
32      /** the start time of the simulation. */
33      private final T startTime;
34  
35      /** the end time of the simulation. */
36      private final T endTime;
37  
38      /** the warmup time of the simulation (included in the total run length). */
39      private final T warmupTime;
40  
41      /**
42       * Construct an object with off-line run control information.
43       * @param id String; the id of the run control that will be used as the id for the replication; should be unique within the
44       *            experiment.
45       * @param startTime T; the start time of the simulation
46       * @param warmupPeriod T; the warmup period, included in the runlength (!)
47       * @param runLength T; the total length of the run, including the warm-up period
48       * @throws NullPointerException when id, startTime, warmupPeriod or runLength is null
49       * @throws IllegalArgumentException when warmup period is negative, or run length is zero or negative, or when the warmup
50       *             time is longer than or equal to the runlength
51       */
52      public RunControl(final String id, final T startTime, final T warmupPeriod, final T runLength)
53      {
54          Throw.whenNull(id, "id should not be null");
55          Throw.whenNull(startTime, "startTime should not be null");
56          Throw.whenNull(warmupPeriod, "warmupPeriod should not be null");
57          Throw.whenNull(runLength, "runLength should not be null");
58          Throw.when(warmupPeriod.doubleValue() < 0.0, IllegalArgumentException.class, "warmup period should not be negative");
59          Throw.when(runLength.doubleValue() <= 0.0, IllegalArgumentException.class, "run length should not be zero or negative");
60          Throw.when(warmupPeriod.compareTo(runLength) >= 0, IllegalArgumentException.class,
61                  "the warmup time is longer than or equal to the runlength");
62  
63          this.id = id;
64          this.description = id;
65          this.startTime = startTime;
66          this.endTime = SimTime.plus(startTime, runLength);
67          this.warmupTime = SimTime.plus(startTime, warmupPeriod);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public RunControl<T> getRunControl()
73      {
74          return this;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public String getId()
80      {
81          return this.id;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public void setDescription(final String description)
87      {
88          this.description = description;
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public String getDescription()
94      {
95          return this.description;
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     public T getStartTime()
101     {
102         return this.startTime;
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public T getEndTime()
108     {
109         return this.endTime;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public T getWarmupTime()
115     {
116         return this.warmupTime;
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public int hashCode()
122     {
123         return Objects.hash(this.endTime, this.id, this.startTime, this.warmupTime);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     public boolean equals(final Object obj)
129     {
130         if (this == obj)
131             return true;
132         if (obj == null)
133             return false;
134         if (getClass() != obj.getClass())
135             return false;
136         RunControl<?> other = (RunControl<?>) obj;
137         return Objects.equals(this.endTime, other.endTime) && Objects.equals(this.id, other.id)
138                 && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.warmupTime, other.warmupTime);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public String toString()
144     {
145         return "RunControl [id=" + this.id + ", startTime=" + this.startTime + ", warmupTime=" + this.warmupTime + ", endTime="
146                 + this.endTime + "]";
147     }
148 
149 }