View Javadoc
1   package nl.tudelft.simulation.dsol.tutorial.mm1;
2   
3   import java.rmi.RemoteException;
4   
5   import org.djutils.stats.summarizers.event.StatisticsEvents;
6   import org.pmw.tinylog.Level;
7   
8   import nl.tudelft.simulation.dsol.statistics.SimPersistent;
9   import nl.tudelft.simulation.dsol.statistics.table.PersistentTableModel;
10  import nl.tudelft.simulation.dsol.statistics.table.TallyTableModel;
11  import nl.tudelft.simulation.dsol.swing.charts.boxwhisker.BoxAndWhiskerChart;
12  import nl.tudelft.simulation.dsol.swing.charts.xy.XYChart;
13  import nl.tudelft.simulation.dsol.swing.gui.DsolPanel;
14  import nl.tudelft.simulation.dsol.swing.gui.TablePanel;
15  import nl.tudelft.simulation.dsol.swing.gui.control.DevsControlPanel;
16  import nl.tudelft.simulation.dsol.swing.statistics.StatisticsTable;
17  import nl.tudelft.simulation.language.DsolException;
18  
19  /**
20   * <p>
21   * Copyright (c) 2002-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
22   * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL
23   * project is distributed under a three-clause BSD-style license, which can be found at
24   * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">
25   * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html</a>.
26   * </p>
27   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
28   */
29  public class MM1Panel extends DsolPanel
30  {
31      /** */
32      private static final long serialVersionUID = 1L;
33  
34      /**
35       * @param controlPanel DevsControlPanel; the control panel
36       * @param model MM1Model; the model
37       * @throws DsolException on error
38       * @throws RemoteException on error
39       */
40      public MM1Panel(final DevsControlPanel.TimeDouble controlPanel, final MM1Model model)
41              throws RemoteException, DsolException
42      {
43          super(controlPanel);
44          addTabs(model);
45          enableSimulationControlButtons();
46      }
47  
48      /**
49       * add a number of charts for the demo.
50       * @param model MM1Model; the model from which to take the statistics
51       */
52      public void addTabs(final MM1Model model)
53      {
54          TablePanel charts = new TablePanel(4, 3);
55          getTabbedPane().addTab("statistics", charts);
56          getTabbedPane().setSelectedIndex(0);
57          addConsoleLogger(Level.TRACE);
58          addConsoleOutput();
59  
60          try
61          {
62              // dN
63  
64              XYChart dNVal = new XYChart(getSimulator(), "time in queue (dN)").setLabelXAxis("time (s)").setLabelYAxis("dN");
65              dNVal.add("dN value", model.dN, StatisticsEvents.OBSERVATION_ADDED_EVENT);
66              charts.setCell(dNVal.getSwingPanel(), 0, 0);
67  
68              XYChart dN = new XYChart(getSimulator(), "avg time in queue").setLabelXAxis("time (s)").setLabelYAxis("avg dN");
69              dN.add("dN mean", model.dN, StatisticsEvents.SAMPLE_MEAN_EVENT);
70              charts.setCell(dN.getSwingPanel(), 1, 0);
71  
72              BoxAndWhiskerChart bwdN = new BoxAndWhiskerChart(getSimulator(), "dN boxplot");
73              bwdN.add(model.dN);
74              charts.setCell(bwdN.getSwingPanel(), 2, 0);
75  
76              StatisticsTable dNTable = new StatisticsTable(new TallyTableModel(model.dN));
77              charts.setCell(dNTable.getSwingPanel(), 3, 0);
78  
79              // qN
80  
81              XYChart qNVal = new XYChart(getSimulator(), "queue length (qN)").setLabelXAxis("time (s)").setLabelYAxis("qN");
82              qNVal.add("qN value", model.qN, SimPersistent.TIMED_OBSERVATION_ADDED_EVENT);
83              charts.setCell(qNVal.getSwingPanel(), 0, 1);
84  
85              XYChart qN = new XYChart(getSimulator(), "avg queue length").setLabelXAxis("time (s)").setLabelYAxis("avg qN");
86              qN.add("qN mean", model.qN, StatisticsEvents.TIMED_WEIGHTED_SAMPLE_MEAN_EVENT);
87              charts.setCell(qN.getSwingPanel(), 1, 1);
88  
89              BoxAndWhiskerChart bwqN = new BoxAndWhiskerChart(getSimulator(), "qN boxplot");
90              bwqN.add(model.qN);
91              charts.setCell(bwqN.getSwingPanel(), 2, 1);
92  
93              StatisticsTable qNTable = new StatisticsTable(new PersistentTableModel(model.qN));
94              charts.setCell(qNTable.getSwingPanel(), 3, 1);
95  
96              // uN
97  
98              XYChart utilization = new XYChart(getSimulator(), "utilization").setLabelXAxis("time (s)").setLabelYAxis("uN");
99              utilization.add("utilization", model.uN, SimPersistent.TIMED_OBSERVATION_ADDED_EVENT);
100             charts.setCell(utilization.getSwingPanel(), 0, 2);
101 
102             XYChart meanUtilization =
103                     new XYChart(getSimulator(), "avg utilization (uN)").setLabelXAxis("time (s)").setLabelYAxis("avg uN");
104             meanUtilization.add("mean utilization", model.uN, StatisticsEvents.TIMED_WEIGHTED_SAMPLE_MEAN_EVENT);
105             charts.setCell(meanUtilization.getSwingPanel(), 1, 2);
106 
107             BoxAndWhiskerChart bwuN = new BoxAndWhiskerChart(getSimulator(), "uN boxplot");
108             bwuN.add(model.uN);
109             charts.setCell(bwuN.getSwingPanel(), 2, 2);
110 
111             StatisticsTable uNTable = new StatisticsTable(new PersistentTableModel(model.uN));
112             charts.setCell(uNTable.getSwingPanel(), 3, 2);
113         }
114         catch (RemoteException exception)
115         {
116             model.getSimulator().getLogger().always().error(exception);
117         }
118     }
119 
120 }