1 package nl.tudelft.simulation.dsol.experiment;
2
3 import java.util.function.Predicate;
4
5 import org.djutils.event.EventType;
6 import org.djutils.exceptions.Throw;
7 import org.djutils.metadata.MetaData;
8
9 import nl.tudelft.simulation.dsol.model.DsolModel;
10 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
11 import nl.tudelft.simulation.naming.context.ContextInterface;
12 import nl.tudelft.simulation.naming.context.Contextualized;
13
14
15
16
17
18
19
20
21
22
23
24
25 public abstract class Replication<T extends Number & Comparable<T>> implements Contextualized, Treatment<T>
26 {
27
28 public static final EventType START_REPLICATION_EVENT =
29 new EventType(new MetaData("START_REPLICATION_EVENT", "Replication started"));
30
31
32 public static final EventType END_REPLICATION_EVENT =
33 new EventType(new MetaData("END_REPLICATION_EVENT", "Replication ended"));
34
35
36 public static final EventType WARMUP_EVENT = new EventType(new MetaData("WARMUP_EVENT", "warmup time"));
37
38
39 private RunControl<T> runControl;
40
41
42 private ContextInterface context;
43
44
45
46
47
48
49
50
51
52
53
54 public Replication(final String id, final T startTime, final T warmupPeriod, final T runLength)
55 {
56 this(new RunControl<T>(id, startTime, warmupPeriod, runLength));
57 }
58
59
60
61
62
63
64 public Replication(final RunControl<T> runControl)
65 {
66 Throw.whenNull(runControl, "runControl should not be null");
67 this.runControl = runControl;
68 }
69
70
71
72
73
74 public RunControl<T> getRunControl()
75 {
76 return this.runControl;
77 }
78
79
80
81
82
83 protected void setContext(final ContextInterface context)
84 {
85 this.context = context;
86 }
87
88 @Override
89 public ContextInterface getContext()
90 {
91 return this.context;
92 }
93
94 @Override
95 public String getId()
96 {
97 return getRunControl().getId();
98 }
99
100 @Override
101 public void setDescription(final String description)
102 {
103 getRunControl().setDescription(description);
104 }
105
106 @Override
107 public String getDescription()
108 {
109 return getRunControl().getDescription();
110 }
111
112 @Override
113 public T getStartTime()
114 {
115 return getRunControl().getStartTime();
116 }
117
118 @Override
119 public T getEndTime()
120 {
121 return getRunControl().getEndTime();
122 }
123
124 @Override
125 public T getWarmupTime()
126 {
127 return getRunControl().getWarmupTime();
128 }
129
130 @Override
131 public <M extends DsolModel<T, ? extends SimulatorInterface<T>>> Predicate<? super M> getStoppingCondition()
132 {
133 return getRunControl().getStoppingCondition();
134 }
135
136 @Override
137 public <M extends DsolModel<T, ? extends SimulatorInterface<T>>> void setStoppingCondition(
138 final Predicate<? super M> stoppingCondition)
139 {
140 getRunControl().setStoppingCondition(stoppingCondition);
141 }
142
143 }