1 package nl.tudelft.simulation.dsol.model;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.djutils.event.LocalEventProducer;
7 import org.djutils.exceptions.Throw;
8
9 import nl.tudelft.simulation.dsol.experiment.StreamInformation;
10 import nl.tudelft.simulation.dsol.model.inputparameters.AbstractInputParameter;
11 import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterException;
12 import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterMap;
13 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
14 import nl.tudelft.simulation.dsol.statistics.SimulationStatistic;
15 import nl.tudelft.simulation.jstats.streams.MersenneTwister;
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class AbstractDsolModel<T extends Number & Comparable<T>, S extends SimulatorInterface<T>> extends LocalEventProducer
29 implements DsolModel<T, S>
30 {
31
32 private static final long serialVersionUID = 20181117L;
33
34
35 @SuppressWarnings("checkstyle:visibilitymodifier")
36 protected S simulator;
37
38
39 @SuppressWarnings("checkstyle:visibilitymodifier")
40 protected InputParameterMap inputParameterMap = new InputParameterMap("model", "Model parameters", "Model parameters", 1.0);
41
42
43 @SuppressWarnings("checkstyle:visibilitymodifier")
44 protected List<SimulationStatistic<T>> outputStatistics = new ArrayList<>();
45
46
47 @SuppressWarnings("checkstyle:visibilitymodifier")
48 protected StreamInformation streamInformation;
49
50
51
52
53
54
55 public AbstractDsolModel(final S simulator)
56 {
57 this(simulator, new StreamInformation(new MersenneTwister(10L)));
58 }
59
60
61
62
63
64
65
66
67 public AbstractDsolModel(final S simulator, final StreamInformation streamInformation)
68 {
69 Throw.whenNull(simulator, "simulator cannot be null");
70 this.simulator = simulator;
71 setStreamInformation(streamInformation);
72 }
73
74
75 @Override
76 public void setStreamInformation(final StreamInformation streamInformation)
77 {
78 Throw.whenNull(streamInformation, "streamInformation cannot be null");
79 this.streamInformation = streamInformation;
80 }
81
82
83 @Override
84 public StreamInformation getStreamInformation()
85 {
86 return this.streamInformation;
87 }
88
89
90 @Override
91 public S getSimulator()
92 {
93 return this.simulator;
94 }
95
96
97 @Override
98 public InputParameterMap getInputParameterMap()
99 {
100 return this.inputParameterMap;
101 }
102
103
104
105
106
107
108 public void addInputParameter(final AbstractInputParameter<?, ?> inputParameter) throws InputParameterException
109 {
110 this.inputParameterMap.add(inputParameter);
111 }
112
113
114
115
116
117
118
119
120 public Object getInputParameter(final String key) throws InputParameterException
121 {
122 return this.inputParameterMap.get(key).getCalculatedValue();
123 }
124
125
126 @Override
127 public List<SimulationStatistic<T>> getOutputStatistics()
128 {
129 return this.outputStatistics;
130 }
131
132 }