View Javadoc

1   /*
2    * @(#) MM1Queue.java Sep 21, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.tutorial.section41;
11  
12  import java.rmi.RemoteException;
13  
14  import nl.tudelft.simulation.dsol.ModelInterface;
15  import nl.tudelft.simulation.dsol.SimRuntimeException;
16  import nl.tudelft.simulation.dsol.formalisms.Resource;
17  import nl.tudelft.simulation.dsol.formalisms.flow.Delay;
18  import nl.tudelft.simulation.dsol.formalisms.flow.Generator;
19  import nl.tudelft.simulation.dsol.formalisms.flow.Release;
20  import nl.tudelft.simulation.dsol.formalisms.flow.Seize;
21  import nl.tudelft.simulation.dsol.formalisms.flow.StationInterface;
22  import nl.tudelft.simulation.dsol.formalisms.flow.statistics.Utilization;
23  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
24  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
25  import nl.tudelft.simulation.dsol.statistics.Tally;
26  import nl.tudelft.simulation.dsol.statistics.charts.BoxAndWhiskerChart;
27  import nl.tudelft.simulation.jstats.distributions.DistConstant;
28  import nl.tudelft.simulation.jstats.distributions.DistContinuous;
29  import nl.tudelft.simulation.jstats.distributions.DistDiscreteConstant;
30  import nl.tudelft.simulation.jstats.distributions.DistExponential;
31  import nl.tudelft.simulation.jstats.streams.StreamInterface;
32  
33  /***
34   * The M/M/1 example as published in Simulation Modeling and Analysis by A.M.
35   * Law & W.D. Kelton section 1.4 and 2.4.
36   * <p>
37   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
38   * University of Technology </a>, the Netherlands. <br>
39   * See for project information <a
40   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
41   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
42   * License (GPL) </a>, no warranty <br>
43   * 
44   * @version 2.0 21.09.2003 <br>
45   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
46   *         Jacobs </a>
47   */
48  public class MM1Queue implements ModelInterface
49  {
50  	/***
51  	 * constructor for the MM1Queue
52  	 */
53  	public MM1Queue()
54  	{
55  		super();
56  	}
57  
58  	/***
59  	 * @see nl.tudelft.simulation.dsol.ModelInterface#
60  	 *      constructModel(SimulatorInterface)
61  	 */
62  	public void constructModel(final SimulatorInterface simulator)
63  			throws SimRuntimeException, RemoteException
64  	{
65  		DEVSSimulatorInterface devsSimulator = (DEVSSimulatorInterface) simulator;
66  
67  		StreamInterface defaultStream = devsSimulator.getReplication()
68  				.getStream("default");
69  
70  		//The Generator
71  		Generator generator = new Generator(devsSimulator, Object.class, null);
72  		generator.setInterval(new DistExponential(defaultStream, 1.0));
73  		generator.setStartTime(new DistConstant(defaultStream, 0.0));
74  		generator.setBatchSize(new DistDiscreteConstant(defaultStream, 1));
75  		generator.setMaxNumber(1000);
76  
77  		//The queue, the resource and the release
78  		Resource resource = new Resource(devsSimulator, 1.0);
79  
80  		// created a resource
81  		StationInterface queue = new Seize(devsSimulator, resource);
82  		StationInterface release = new Release(devsSimulator, resource, 1.0);
83  
84  		//The server
85  		DistContinuous serviceTime = new DistExponential(defaultStream, 0.5);
86  		StationInterface server = new Delay(devsSimulator, serviceTime);
87  
88  		//The flow
89  		generator.setDestination(queue);
90  		queue.setDestination(server);
91  		server.setDestination(release);
92  
93  		//Statistics
94  		Tally dN = new Tally("d(n)", devsSimulator, queue, Seize.DELAY_TIME);
95  		Tally qN = new Tally("q(n)", devsSimulator, queue,
96  				Seize.QUEUE_LENGTH_EVENT);
97  		Utilization uN = new Utilization("u(n)", devsSimulator, server);
98  
99  		//Charts
100 		new BoxAndWhiskerChart(devsSimulator, "d(n) chart").add(dN);
101 		new BoxAndWhiskerChart(devsSimulator, "q(n) chart").add(qN);
102 		new BoxAndWhiskerChart(devsSimulator, "u(n) chart").add(uN);
103 	}
104 }