Source code: desmoj/DemandProcess.java
1 package desmoj;
2
3 import desmoj.*; // import all the core desmoj stuff
4 import desmoj.dist.*; // import all the stuff for the random number distributions
5
6 /**
7 * DemandProcess is a kind of process representing the demand in a manufacturing
8 * system. It is some kind of drain for the products manufactured in the
9 * production system. So it can be viewed as the border of the simulated system,
10 * where the products disappear. It is meant to model the demand of the market
11 * where the finished products leaving the manufacturing system are sold.
12 * It has three main parameters to be specified (see the Constructor): The
13 * <code>Entrepot</code> where the products to be sold are stored, the random
14 * number distribution to determine the quantity of demanded products, the rate
15 * (frequenzy) also a random number distribution, at which the demand occurs.
16 * Once the DemandProcess has obtained the products, they are consumed and will
17 * leave the simulated system for ever. Actually they will be destroyed as the
18 * the garbage collector will get them.
19 * Internally <code>CustomerProcesss</code>es are set up and initialized, which
20 * are the ones actually fetching the products from the <code>Entrepot</code>.
21 * But this is done automatically, so the user does not have to care about it.
22 *
23 * @author: Soenke Claassen
24 *
25 * @version DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL
26 */
27 public class DemandProcess extends SimProcess {
28
29 /**
30 * The random number distribution determining the quantity of demanded products.
31 */
32 private desmoj.dist.IntDist demandQuantity;
33
34 /**
35 * The random number distribution determining the intervals in which the
36 * demand occurs.
37 */
38 private desmoj.dist.RealDist demandInterval;
39
40 /**
41 * The <code>Entrepot</code> supplying the products this DemandProcess is
42 * demanding.
43 */
44 private Entrepot entrepot;
45 /**
46 * Constructor of a DemandProcess. The DemandProcess is fetching a certain
47 * quantity of products from the given <code>Entrepot</code> in certain
48 * intervals.
49 * @param owner desmoj.Model : The model this DemandProcess is associated to.
50 * @param name java.lang.String : The name of this DemandProcess.
51 * @param supplier desmoj.Entrepot : The <code>Entrepot</code> supplying the
52 * products this DemandProcess is buying.
53 * @param quantity desmoj.dist.IntDist : The random number distribution
54 * determining the demand (quantity) of this DemandProcess.
55 * Use <code>desmoj.dist.IntDistConstant</code> to simulate a constant demand.
56 * @param interval desmoj.dist.RealDist : The random number distribution
57 * determining the intervals in which the demand occurs.
58 * Use <code>desmoj.dist.RealDistConstant</code> to simulate constant intervals.
59 * @param showInTrace boolean : Flag, if this DemandProcess should produce
60 * a trace output or not.
61 */
62 public DemandProcess(Model owner, String name, Entrepot supplier,
63 IntDist quantity, RealDist interval, boolean showInTrace)
64 {
65 super(owner, name, showInTrace); // make a SimProcess
66
67 // save the parameters
68 this.entrepot = supplier;
69 this.demandQuantity = quantity;
70 this.demandInterval = interval;
71 }
72 /**
73 * Returns the random number distribution determining the intervals in which the
74 * demand occurs.
75 * @return desmoj.dist.RealDist : The random number distribution determining the
76 * intervals in which the demand occurs.
77 */
78 public desmoj.dist.RealDist getDemandInterval() {
79
80 return demandInterval;
81 }
82 /**
83 * Returns the random number distribution determining the demand (quantity).
84 * @return desmoj.dist.IntDist : The random number distribution determining
85 * the demand (quantity).
86 */
87 public desmoj.dist.IntDist getDemandQuantity() {
88
89 return demandQuantity;
90 }
91 /**
92 * Returns the <code>Entrepot</code> supplying the products this DemandProcess is
93 * demanding.
94 * @return desmoj.Entrepot : The <code>Entrepot</code> supplying the products
95 * this DemandProcess is demanding.
96 */
97 public Entrepot getEntrepot() {
98
99 return entrepot;
100 }
101 /**
102 * The DemandProcess is fetching in certain intervals a certain quantity of
103 * products from the given <code>Entrepot</code> and destroys them. So it serves
104 * as a drain for the finished products. To prevent this process from being
105 * blocked waiting in the queue of the <code>Entrepot</code>, it will instantiate
106 * <code>CustomerProcess</code>es which will actually fetching the products from
107 * the <code>Entrepot</code>.
108 */
109 public void lifeCycle() {
110
111 while (true) // a never ending hunger for products ;-)
112 {
113 // wait until it is time to fetch the next products
114 hold( new SimTime (demandInterval.sample()) );
115
116 // determine the quantity of demanded products
117 int qty = (int)demandQuantity.sample();
118
119 // create and activate a CustomerProcess to let him fetch the products
120 CustomerProcess cp = new CustomerProcess( getModel(),
121 "anonymous customer",
122 entrepot,
123 qty,
124 traceIsOn() );
125 cp.activate( new SimTime (0.0) );
126
127 // debug out
128 if ( debugIsOn() )
129 {
130 sendDebugNote( "demands " + qty + " products from " +
131 entrepot.getQuotedName() );
132 }
133 } // end while loop
134 }
135 /**
136 * Sets the intervals in which the demand occurs to the new given random number
137 * distribution. Use <code>desmoj.dist.RealDistConstant</code> to simulate
138 * constant intervals.
139 * @param newDemandInterval desmoj.dist.RealDist : The new random number
140 * distribution determining the intervals in which the demand occurs.
141 */
142 public void setDemandInterval(desmoj.dist.RealDist newDemandInterval) {
143
144 this.demandInterval = newDemandInterval;
145 }
146 /**
147 * Sets the demand (quantity) to the new given random number distribution.
148 * Use <code>desmoj.dist.IntDistConstant</code> to simulate a constant demand.
149 * @param newDemandQuantity desmoj.dist.IntDist : The new random number
150 * distribution determining the demand (quantity).
151 */
152 public void setDemandQuantity(desmoj.dist.IntDist newDemandQuantity) {
153
154 this.demandQuantity = newDemandQuantity;
155 }
156 }