View Javadoc
1   package org.sim0mq.demo.mm1;
2   
3   import java.rmi.RemoteException;
4   
5   import nl.tudelft.simulation.dsol.SimRuntimeException;
6   import nl.tudelft.simulation.dsol.formalisms.Resource;
7   import nl.tudelft.simulation.dsol.formalisms.flow.Delay;
8   import nl.tudelft.simulation.dsol.formalisms.flow.Generator;
9   import nl.tudelft.simulation.dsol.formalisms.flow.Release;
10  import nl.tudelft.simulation.dsol.formalisms.flow.Seize;
11  import nl.tudelft.simulation.dsol.formalisms.flow.StationInterface;
12  import nl.tudelft.simulation.dsol.formalisms.flow.statistics.Utilization;
13  import nl.tudelft.simulation.dsol.model.AbstractDSOLModel;
14  import nl.tudelft.simulation.dsol.simtime.SimTimeDouble;
15  import nl.tudelft.simulation.dsol.simtime.dist.DistContinuousSimTime;
16  import nl.tudelft.simulation.dsol.simtime.dist.DistContinuousSimulationTime;
17  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
18  import nl.tudelft.simulation.dsol.statistics.SimTally;
19  import nl.tudelft.simulation.jstats.distributions.DistConstant;
20  import nl.tudelft.simulation.jstats.distributions.DistDiscreteConstant;
21  import nl.tudelft.simulation.jstats.distributions.DistExponential;
22  import nl.tudelft.simulation.jstats.streams.MersenneTwister;
23  import nl.tudelft.simulation.jstats.streams.StreamInterface;
24  
25  /**
26   * The M/M/1 example as published in Simulation Modeling and Analysis by A.M. Law & W.D. Kelton section 1.4 and 2.4.
27   * <p>
28   * (c) copyright 2015-2019 <a href="http://www.simulation.tudelft.nl">Delft University of Technology </a>, the Netherlands. <br>
29   * See for project information <a href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
30   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser General Public License (LGPL) </a>, no warranty.
31   * @version 2.0 21.09.2003 <br>
32   * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
33   */
34  public class MM1Queue41Model extends AbstractDSOLModel.TimeDouble<DEVSSimulatorInterface.TimeDouble>
35  {
36      /** The default serial version UID for serializable classes. */
37      private static final long serialVersionUID = 1L;
38  
39      /** tally dN. */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      SimTally.TimeDouble dN;
42  
43      /** tally qN. */
44      @SuppressWarnings("checkstyle:visibilitymodifier")
45      SimTally.TimeDouble qN;
46  
47      /** utilization uN. */
48      @SuppressWarnings("checkstyle:visibilitymodifier")
49      Utilization<Double, Double, SimTimeDouble> uN;
50  
51      /** PARAMETER iat. */
52      @SuppressWarnings("checkstyle:visibilitymodifier")
53      public double iat = Double.NaN;
54  
55      /** PARAMETER serviceTime. */
56      @SuppressWarnings("checkstyle:visibilitymodifier")
57      public double serviceTime = Double.NaN;
58  
59      /** PARAMETER seed. */
60      @SuppressWarnings("checkstyle:visibilitymodifier")
61      public long seed = 1;
62  
63      /**
64       * Construct the model.
65       * @param simulator the simulator
66       */
67      public MM1Queue41Model(final DEVSSimulatorInterface.TimeDouble simulator)
68      {
69          super(simulator);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public final void constructModel() throws SimRuntimeException
75      {
76          if (Double.isNaN(this.iat))
77          {
78              throw new SimRuntimeException("Parameter iat not defined for model");
79          }
80          if (Double.isNaN(this.serviceTime))
81          {
82              throw new SimRuntimeException("Parameter servicetime not defined for model");
83          }
84  
85          StreamInterface defaultStream = new MersenneTwister(this.seed);
86  
87          // The Generator
88          Generator.TimeDouble generator = new Generator.TimeDouble(getSimulator(), Object.class, null);
89          generator.setInterval(new DistContinuousSimulationTime.TimeDouble(new DistExponential(defaultStream, this.iat)));
90          generator.setStartTime(new DistContinuousSimTime.TimeDouble(new DistConstant(defaultStream, 0.0)));
91          generator.setBatchSize(new DistDiscreteConstant(defaultStream, 1));
92          generator.setMaxNumber(1000);
93  
94          // The queue, the resource and the release
95          Resource<Double, Double, SimTimeDouble> resource = new Resource<>(getSimulator(), 1.0);
96  
97          // created a resource
98          StationInterface.TimeDouble queue = new Seize.TimeDouble(getSimulator(), resource);
99          StationInterface.TimeDouble release = new Release.TimeDouble(getSimulator(), resource, 1.0);
100 
101         // The server
102         DistContinuousSimulationTime.TimeDouble serviceTimeDistribution =
103                 new DistContinuousSimulationTime.TimeDouble(new DistExponential(defaultStream, this.serviceTime));
104         StationInterface.TimeDouble server = new Delay.TimeDouble(getSimulator(), serviceTimeDistribution);
105 
106         // The flow
107         generator.setDestination(queue);
108         queue.setDestination(server);
109         server.setDestination(release);
110 
111         // Statistics
112         try
113         {
114             this.dN = new SimTally.TimeDouble("d(n)", getSimulator(), queue, Seize.DELAY_TIME);
115             this.qN = new SimTally.TimeDouble("q(n)", getSimulator(), queue, Seize.QUEUE_LENGTH_EVENT);
116             this.uN = new Utilization<Double, Double, SimTimeDouble>("u(n)", getSimulator(), server);
117         }
118         catch (RemoteException exception)
119         {
120             exception.printStackTrace();
121         }
122     }
123 
124 }