View Javadoc
1   package nl.tudelft.simulation.dsol.demo.event.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.ConsoleLogger;
14  import nl.tudelft.simulation.dsol.swing.gui.ConsoleOutput;
15  import nl.tudelft.simulation.dsol.swing.gui.DsolPanel;
16  import nl.tudelft.simulation.dsol.swing.gui.TablePanel;
17  import nl.tudelft.simulation.dsol.swing.gui.control.DevsControlPanel;
18  import nl.tudelft.simulation.dsol.swing.statistics.StatisticsTable;
19  
20  /**
21   * MM1Panel panel for test model.
22   * <p>
23   * Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
24   * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
25   * project is distributed under a three-clause BSD-style license, which can be found at
26   * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
27   * </p>
28   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   */
30  public class MM1Panel extends DsolPanel
31  {
32      /** */
33      private static final long serialVersionUID = 1L;
34  
35      /**
36       * @param controlPanel DevsControlPanel.TimeDouble; the control panel
37       * @throws RemoteException when communications to a remote machine fails
38       */
39      public MM1Panel(final DevsControlPanel.TimeDouble controlPanel) throws RemoteException
40      {
41          super(controlPanel);
42          addTabs();
43          enableSimulationControlButtons();
44      }
45  
46      /**
47       * add a number of charts for the demo.
48       */
49      protected void addTabs()
50      {
51          TablePanel charts = new TablePanel(4, 4);
52          getTabbedPane().addTab("statistics", charts);
53          getTabbedPane().setSelectedIndex(0);
54          MM1Model model = (MM1Model) getModel();
55  
56          try
57          {
58              // time in queue
59  
60              XYChart dNVal = new XYChart(getSimulator(), "time in queue (dN)").setLabelXAxis("time (s)").setLabelYAxis("dN");
61              dNVal.add("dN value", model.tallyTimeInQueue, StatisticsEvents.OBSERVATION_ADDED_EVENT);
62              charts.setCell(dNVal.getSwingPanel(), 0, 0);
63  
64              XYChart dN = new XYChart(getSimulator(), "avg time in queue").setLabelXAxis("time (s)").setLabelYAxis("avg dN");
65              dN.add("dN mean", model.tallyTimeInQueue, StatisticsEvents.SAMPLE_MEAN_EVENT);
66              charts.setCell(dN.getSwingPanel(), 1, 0);
67  
68              BoxAndWhiskerChart bwdN = new BoxAndWhiskerChart(getSimulator(), "dN boxplot");
69              bwdN.add(model.tallyTimeInQueue);
70              charts.setCell(bwdN.getSwingPanel(), 2, 0);
71  
72              StatisticsTable dNTable = new StatisticsTable(new TallyTableModel(model.tallyTimeInQueue));
73              charts.setCell(dNTable.getSwingPanel(), 3, 0);
74  
75              // queue length
76  
77              XYChart qNVal = new XYChart(getSimulator(), "queue length (qN)").setLabelXAxis("time (s)").setLabelYAxis("qN");
78              qNVal.add("qN value", model.persistentQueueLength, SimPersistent.TIMED_OBSERVATION_ADDED_EVENT);
79              charts.setCell(qNVal.getSwingPanel(), 0, 1);
80  
81              XYChart qN = new XYChart(getSimulator(), "avg queue length").setLabelXAxis("time (s)").setLabelYAxis("avg qN");
82              qN.add("qN mean", model.persistentQueueLength, StatisticsEvents.TIMED_WEIGHTED_SAMPLE_MEAN_EVENT);
83              charts.setCell(qN.getSwingPanel(), 1, 1);
84  
85              BoxAndWhiskerChart bwqN = new BoxAndWhiskerChart(getSimulator(), "qN boxplot");
86              bwqN.add(model.persistentQueueLength);
87              charts.setCell(bwqN.getSwingPanel(), 2, 1);
88  
89              StatisticsTable qNTable = new StatisticsTable(new PersistentTableModel(model.persistentQueueLength));
90              charts.setCell(qNTable.getSwingPanel(), 3, 1);
91  
92              // utilization
93  
94              XYChart utilization = new XYChart(getSimulator(), "utilization").setLabelXAxis("time (s)").setLabelYAxis("uN");
95              utilization.add("utilization", model.persistentUtilization, SimPersistent.TIMED_OBSERVATION_ADDED_EVENT);
96              charts.setCell(utilization.getSwingPanel(), 0, 2);
97  
98              XYChart meanUtilization =
99                      new XYChart(getSimulator(), "avg utilization (uN)").setLabelXAxis("time (s)").setLabelYAxis("avg uN");
100             meanUtilization.add("mean utilization", model.persistentUtilization,
101                     StatisticsEvents.TIMED_WEIGHTED_SAMPLE_MEAN_EVENT);
102             charts.setCell(meanUtilization.getSwingPanel(), 1, 2);
103 
104             BoxAndWhiskerChart bwuN = new BoxAndWhiskerChart(getSimulator(), "uN boxplot");
105             bwuN.add(model.persistentUtilization);
106             charts.setCell(bwuN.getSwingPanel(), 2, 2);
107 
108             StatisticsTable uNTable = new StatisticsTable(new PersistentTableModel(model.persistentUtilization));
109             charts.setCell(uNTable.getSwingPanel(), 3, 2);
110 
111             // time in system
112 
113             XYChart tNVal = new XYChart(getSimulator(), "time in system (tN)").setLabelXAxis("time (s)").setLabelYAxis("tN");
114             tNVal.add("tN value", model.tallyTimeInSystem, StatisticsEvents.OBSERVATION_ADDED_EVENT);
115             charts.setCell(tNVal.getSwingPanel(), 0, 3);
116 
117             XYChart tN = new XYChart(getSimulator(), "avg time in system").setLabelXAxis("time (s)").setLabelYAxis("avg tN");
118             tN.add("tN mean", model.tallyTimeInSystem, StatisticsEvents.SAMPLE_MEAN_EVENT);
119             charts.setCell(tN.getSwingPanel(), 1, 3);
120 
121             BoxAndWhiskerChart bwtN = new BoxAndWhiskerChart(getSimulator(), "tN boxplot");
122             bwtN.add(model.tallyTimeInSystem);
123             charts.setCell(bwtN.getSwingPanel(), 2, 3);
124 
125             StatisticsTable tNTable = new StatisticsTable(new TallyTableModel(model.tallyTimeInSystem));
126             charts.setCell(tNTable.getSwingPanel(), 3, 3);
127         }
128         catch (RemoteException exception)
129         {
130             model.getSimulator().getLogger().always().error(exception);
131         }
132 
133         ConsoleLogger logConsole = new ConsoleLogger(Level.INFO);
134         getTabbedPane().addTab("logger", logConsole);
135         getTabbedPane().addTab("console", new ConsoleOutput());
136     }
137 
138 }