package nl.tudelft.simulation.dsol.tutorial.section41; import java.rmi.RemoteException; import javax.naming.NamingException; import org.djutils.logger.CategoryLogger; import org.pmw.tinylog.Level; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.experiment.ReplicationInterface; import nl.tudelft.simulation.dsol.experiment.SingleReplication; import nl.tudelft.simulation.dsol.simulators.DEVSSimulator; import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication; import nl.tudelft.simulation.dsol.swing.gui.control.DEVSControlPanel; import nl.tudelft.simulation.language.DSOLException; /** * M/M/1 queuing model with animation and graphs. *

* Copyright (c) 2002-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @author Alexander Verbraeck */ public class MM1Queue41SwingApplication extends DSOLApplication { /** the model. */ private MM1Queue41Model model; /** * @param panel DSOLPanel; the panel * @param model MM1Queue41Model; the model * @param simulator DEVSSimulatorInterface.TimeDouble; the simulator */ public MM1Queue41SwingApplication(final MM1Queue41Panel panel, final MM1Queue41Model model, final DEVSSimulator.TimeDouble simulator) { super(panel, "MM1Queue41SwingApplication"); this.model = model; try { simulator.scheduleEventAbs(1000.0, this, this, "terminate", null); } catch (SimRuntimeException exception) { simulator.getLogger().always().error(exception, ""); } } /** */ private static final long serialVersionUID = 1L; /** * @param args String[]; arguments, expected to be empty * @throws SimRuntimeException on error * @throws RemoteException on error * @throws NamingException on error * @throws DSOLException on error */ public static void main(final String[] args) throws SimRuntimeException, RemoteException, NamingException, DSOLException { CategoryLogger.setAllLogLevel(Level.TRACE); DEVSSimulator.TimeDouble simulator = new DEVSSimulator.TimeDouble("MM1Queue41SwingApplication"); MM1Queue41Model model = new MM1Queue41Model(simulator); ReplicationInterface.TimeDouble replication = new SingleReplication.TimeDouble("rep1", 0.0, 0.0, 1000.0); simulator.initialize(model, replication); DEVSControlPanel.TimeDouble controlPanel = new DEVSControlPanel.TimeDouble(model, simulator); new MM1Queue41SwingApplication(new MM1Queue41Panel(controlPanel, model), model, simulator); } /** stop the simulation. */ public void terminate() { System.out.println("average queue length = " + this.model.qN.getWeightedSampleMean()); System.out.println("average queue wait = " + this.model.dN.getSampleMean()); System.out.println("average utilization = " + this.model.uN.getWeightedSampleMean()); } }