1 package nl.tudelft.simulation.dsol.demo.flow.mm1;
2
3 import java.rmi.RemoteException;
4 import java.util.SortedMap;
5
6 import javax.naming.NamingException;
7
8 import org.djutils.event.Event;
9 import org.djutils.event.EventListener;
10 import org.djutils.logger.CategoryLogger;
11 import org.djutils.stats.summarizers.Tally;
12 import org.djutils.stats.summarizers.TimestampWeightedTally;
13 import org.pmw.tinylog.Level;
14
15 import nl.tudelft.simulation.dsol.SimRuntimeException;
16 import nl.tudelft.simulation.dsol.experiment.Experiment;
17 import nl.tudelft.simulation.dsol.experiment.Replication;
18 import nl.tudelft.simulation.dsol.simulators.DevsSimulator;
19 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20 import nl.tudelft.simulation.dsol.swing.gui.inputparameters.TabbedParameterDialog;
21
22
23
24
25
26
27
28
29
30
31
32 public class MM1ExperimentApplication implements EventListener
33 {
34
35 private static final long serialVersionUID = 20230114L;
36
37
38 private DevsSimulator<Double> simulator;
39
40
41 private MM1Model model;
42
43
44 private Experiment<Double, SimulatorInterface<Double>> experiment;
45
46
47
48
49
50
51
52 protected MM1ExperimentApplication() throws SimRuntimeException, RemoteException, NamingException
53 {
54 this.simulator = new DevsSimulator<Double>("MM1ExperimentApplication");
55 this.model = new MM1Model(this.simulator);
56 new TabbedParameterDialog(this.model.getInputParameterMap());
57 this.experiment = new Experiment<>("mm1", this.simulator, this.model, 0.0, 0.0, 1000.0, 10);
58 this.experiment.addListener(this, Experiment.END_EXPERIMENT_EVENT);
59 this.experiment.addListener(this, Replication.END_REPLICATION_EVENT);
60 this.experiment.start();
61 }
62
63
64 @Override
65 public void notify(final Event event) throws RemoteException
66 {
67 if (event.getType().equals(Replication.END_REPLICATION_EVENT))
68 {
69 reportReplicationStatistics();
70 }
71 if (event.getType().equals(Experiment.END_EXPERIMENT_EVENT))
72 {
73 reportFinalStatistics();
74 }
75 }
76
77
78
79
80 protected void reportReplicationStatistics()
81 {
82 System.out.println("Statistics replication:");
83 System.out.println(Tally.reportHeader());
84 System.out.println(this.model.dN.reportLine());
85 System.out.println(Tally.reportFooter());
86 System.out.println();
87 System.out.println(TimestampWeightedTally.reportHeader());
88 System.out.println(this.model.qN.reportLine());
89 System.out.println(this.model.uN.reportLine());
90 System.out.println(TimestampWeightedTally.reportFooter());
91 System.out.println();
92 }
93
94
95
96
97 protected void reportFinalStatistics()
98 {
99 System.out.println("Final statistics:");
100 SortedMap<String, SortedMap<String, Tally>> stats = this.experiment.getSummaryStatistics();
101 for (String statMapKey : stats.keySet())
102 {
103 System.out.println("\nSummary statistic for: " + statMapKey);
104 System.out.println(Tally.reportHeader());
105 SortedMap<String, Tally> statMap = stats.get(statMapKey);
106 for (String statKey : statMap.keySet())
107 {
108 Tally stat = statMap.get(statKey);
109 System.out.println(stat.reportLine());
110 }
111 System.out.println(Tally.reportFooter());
112 }
113
114 System.exit(0);
115 }
116
117
118
119
120
121
122
123 public static void main(final String[] args) throws SimRuntimeException, RemoteException, NamingException
124 {
125 CategoryLogger.setAllLogLevel(Level.WARNING);
126 new MM1ExperimentApplication();
127 }
128
129 }