Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: desmoj/SimpleTransporter.java


1   package desmoj;
2   
3   import desmoj.dist.*;    // import the random number streams (for the return time)
4   
5   /**
6    * A SimpleTransporter is a simple transporter (vehicle) associated to a 
7    * <code>TransportJunction</code>. There it waits for goods to transport them.
8    * The goods are transported for a certain time and than released.
9    * The SimpleTransporter returns to his <code>TranspsortJunction</code> where
10   * it waits again for some other goods to transport. The time it takes the 
11   * transporter to return to its <code>TransportJunction</code> must be specified
12   * in the parameter <code>returnTime</code>. It must be some kind of
13   * <code>desmoj.dist.RealDist* </code> random number stream.
14   * The SimpleTransporter has a certain capacity (maximum number of goods which
15   * can be carried around at once) and a minimum load (minimum number of goods 
16   * which will be carried). The minimum load is one (1) unless something different
17   * is specified.
18   * The SimpleTransporters lifeCycle is kept simple, as it only waits in a 
19   * <code>TransportJunction</code> for goods to be transported. Than, after having
20   * transported the goods it returns to its <code>TransportJunction</code>.
21   * The user can overwrite the method <code>lifeCycle()</code> in a subclass in
22   * order to implement a different behavior.
23   *
24   * @see Transporter
25   *  
26   * @author: Soenke Claassen
27   * 
28   * @version DESMO-J,  Ver. 1.5 copyright (c) 2001 licensed under GNU GPL
29   */
30  public class SimpleTransporter extends Transporter {
31  
32   /**
33    *  The random number stream determining the time it takes this SimpleTransporter
34    * to return to its <code>TransportJunction</code>.
35    */
36    private desmoj.dist.RealDist returnTimeStream;
37  
38   /**
39    *  The <code>TransportJunction</code> this SimpleTransporter is associated to.
40    * From there it starts and to that <code>TransportJunction</code> it returns.
41    */
42    private TransportJunction homeBase;
43  
44   /**
45    *  The <code>Transportation</code> this SimpleTransporter is performing. That
46    * is the joint cooperation of this SimpleTransporter and the goods 
47    * (<code>SimProcess</code>es).
48    */
49    private Transportation transportation;
50  /**
51   * Constructs a SimpleTransporter which will carry around goods in a 
52   * manufacturing system, from and to a certain <code>TransportJunction</code>.
53   * A SimpleTransporter is associated to a certain <code>TransportJunction</code>
54   * as his home base. He will perform the transportation of the goods as 
55   * described in the Transportation object. He needs a certain time to return 
56   * to his home base and has a capacity (maximum number of goods which can be 
57   * transported) and a mimimum load (a minimum number of goods it will carry). 
58   * Use this constructor to construct a Transporter with a certain minimum load, 
59   * a specified capacity, a given transportation order, a certain home base 
60   * (<code>TransportJunction</code>) and a given return time it takes him to 
61   * return to his base.
62   * The minimum load and the capacity must not be zero or negative.
63   * @param owner desmoj.Model : The model this SimpleTransporter is associated to.
64   * @param name java.lang.String : The name of this SimpleTransporter.
65   * @param minLoad int : The minimum number of goods this SimpleTransporter will 
66   * carry around.
67   * @param capac int : The maximum number of goods this SimpleTransporter can 
68   * carry around.
69   * @param transport Transportation : The transportation to be carried out by 
70   * this SimpleTransporter.
71   * @param homeBase TransportJunction : The home base of this SimpleTransporter;
72   * where he comes from and where he returns to.
73   * @param returnTime RealDist : The time it takes the SimpleTransporter to return
74   * to his home base after transporting the goods to a certain place. 
75   * @param showInTrace boolean : Flag, if this SimpleTransporter should produce
76   * a trace output or not.
77   */
78  public SimpleTransporter(Model owner, String name, int minLoad, int capac, 
79                            Transportation transport, TransportJunction homeBase, 
80                            RealDist returnTime, boolean showInTrace) 
81  {
82    super(owner, name, minLoad, capac, showInTrace);  // make a Transporter
83    // the minLoad and the capacity parameter will be checked there
84  
85    // check the transport parameter
86    if ( transport == null )
87    {
88      sendWarning ( "The given Transportation this SimpleTransporter should carry "+
89                    "out is only a null pointer. The SimpleTransporter can not " +
90                    "be constructed!",
91                    getClass().getName() + ": " + getQuotedName() +
92                    ", Constructor: SimpleTransporter(Model owner, String name, " +
93                    "int minLoad, int capac, Transportation transport, " +
94                    "TransportJunction homeBase, RealDist returnTime, " +
95                    "boolean showInTrace) ",
96                    "A SimpleTransporter needs a reference to a Transportation " +
97                    "he is supposed to carry out.",
98                    "Make sure to provide a valid Transportation object for the "+
99                    "SimpleTransporter to carry out.");
100     
101     return;    // ignore that rubbish and just return
102   }
103   else
104   {
105     this.transportation = transport;
106   }
107   
108   // check the home base parameter
109   if ( homeBase == null )
110   {
111     sendWarning ( "The given TransportJunction homeBase for a SimpleTransporter"+
112                   " is only a null pointer. The SimpleTransporter can not be " +
113                   "constructed!",
114                   getClass().getName() + ": " + getQuotedName() +
115                   ", Constructor: SimpleTransporter(Model owner, String name, " +
116                   "int minLoad, int capac, Transportation transport, " +
117                   "TransportJunction homeBase, RealDist returnTime, " +
118                   "boolean showInTrace) ",
119                   "A SimpleTransporter needs a certain TransportJunction as " +
120                   "its home base.",
121                   "Make sure to provide a valid TransportJunction as a home "+
122                   "base for the SimpleTransporter to be constructed.");
123     
124     return;    // ignore that rubbish and just return
125   }
126   else
127   {
128     this.homeBase = homeBase;
129   }
130 
131   // check the return time stream parameter
132   if ( returnTime == null )
133   {
134     sendWarning ( "The given return time for a SimpleTransporter is only a "+
135                   "null pointer. The return time will be set to zero!",
136                   getClass().getName() + ": " + getQuotedName() +
137                   ", Constructor: SimpleTransporter(Model owner, String name, " +
138                   "int minLoad, int capac, Transportation transport, " +
139                   "TransportJunction homeBase, RealDist returnTime, " +
140                   "boolean showInTrace) ",
141                   "A SimpleTransporter needs a certain time to return to his " +
142                   "home TransportJunction." ,
143                   "Make sure to provide a valid desmoj.dist.RealDist* random "+
144                   "number stream as the return time for the SimpleTransporter " +
145                   "to be constructed.");
146     // set the return time to zero
147     this.returnTimeStream = new RealDistConstant(owner, "simpleTransReturnTime",
148                                                   0.0, true, false);
149   }
150   else
151   {
152     this.returnTimeStream = returnTime;
153   }
154 }
155 /**
156  * Constructs a SimpleTransporter which will carry around goods in a 
157  * manufacturing system, from and to a certain <code>TransportJunction</code>.
158  * A SimpleTransporter is associated to a certain <code>TransportJunction</code>
159  * as his home base. He will perform the transportation of the goods as 
160  * described in the Transportation object. He needs a certain time to return 
161  * to his home base and has a capacity (maximum number of goods which can be 
162  * transported). The mimimum load (a minimum number of goods it will carry) is
163  * one. 
164  * Use this constructor to construct a Transporter with a specified capacity, a
165  * given transportation order, a certain home base 
166  * (<code>TransportJunction</code>), a given return time it takes him to return
167  * to his base and a minimum load of one.
168  * @param owner desmoj.Model : The model this SimpleTransporter is associated to.
169  * @param name java.lang.String : The name of this SimpleTransporter.
170  * @param capac int : The maximum number of goods this SimpleTransporter can 
171  * carry around.
172  * @param transport Transportation : The transportation to be carried out by 
173  * this SimpleTransporter.
174  * @param homeBase TransportJunction : The home base of this SimpleTransporter;
175  * where he comes from and where he returns to.
176  * @param returnTime RealDist : The time it takes the SimpleTransporter to return
177  * to his home base after transporting the goods to a certain place. 
178  * @param showInTrace boolean : Flag, if this SimpleTransporter should produce
179  * a trace output or not.
180  */
181 public SimpleTransporter(Model owner, String name, int capac, 
182                           Transportation transport, TransportJunction homeBase, 
183                           RealDist returnTime, boolean showInTrace) 
184 {
185   // construct a SimpleTransporter with a minimum load of one
186   this (owner, name, 1, capac, transport, homeBase, returnTime, showInTrace);
187 }
188 /**
189  * Returns the home base <code>TransportJunction</code> this SimpleTransporter
190  * is associated to.
191  * @return desmoj.TransportJunction : The home base <code>TransportJunction</code>
192  * this SimpleTransporter is associated to.
193  */
194 public TransportJunction getHomeBase() {
195   
196   return this.homeBase;
197 }
198 /**
199  * Returns a <code>SimTime</code> object representing the time it takes the 
200  * SimpleTransporter to return to his home base (<code>TransportJunction</code>) 
201  * after having transported the goods to some place. The time is taken from the 
202  * given random number stream returnTimeStream.
203  * @return desmoj.SimTime : The time it takes the SimpleTransporter to return 
204  * to his home base (<code>TransportJunction</code>) after having transported 
205  * the goods to some place.
206  */
207 public SimTime getReturnTimeSample() {
208 
209   return new SimTime( returnTimeStream.sample() );
210 }
211 /**
212  * Returns the <code>Transportation</code> order this SimpleTransporter is 
213  * supposed to execute.
214  * @return desmoj.Transportation : The <code>Transportation</code> order
215  * this SimpleTransporter is supposed to execute.
216  */
217 public Transportation getTransportation() {
218   
219   return this.transportation;
220 }
221 /**
222  * This SimpleTransporter has a very simple lifeCycle. He waits in his home base
223  * (<code>TransportJunction</code>) for goods to transport. As soon as goods 
224  * arrive at the <code>TransportJunction</code> they will be transported to their
225  * destination and the SimpleTransporter returns to his home base. 
226  */
227 public void lifeCycle() 
228 {
229   // neverending cycle of transportation work
230   while ( true )
231   {
232     // wait in home base for goods to transport
233     homeBase.transport(transportation);
234 
235     // transportation will be carried out as described in transportation
236 
237     // return to home base
238     hold( getReturnTimeSample() );
239   }  
240   
241 }
242 /**
243  * Sets a new <code>TransportJunction</code> as the home base this 
244  * SimpleTransporter is associated to. Must not be <code>null</code>!
245  * @param newHomeBase desmoj.TransportJunction : The new 
246  * <code>TransportJunction</code> as the home base of this SimpleTransporter.
247  */
248 public void setHomeBase(TransportJunction newHomeBase) {
249 
250   // check the home base parameter
251   if ( newHomeBase == null )
252   {
253     sendWarning ( "The given TransportJunction homeBase for a SimpleTransporter"+
254                   " is only a null pointer. The attempted action is ignored!",
255                   getClass().getName() + ": " + getQuotedName() +
256                   ", Mehtod: void setHomeBase(TransportJunction newHomeBase)",
257                   "A SimpleTransporter needs a certain TransportJunction as " +
258                   "its home base.",
259                   "Make sure to provide a valid TransportJunction as a home "+
260                   "base for this SimpleTransporter.");
261     
262     return;    // ignore that rubbish and just return
263   }
264   else
265   {
266     this.homeBase = newHomeBase;
267   }
268 
269 }
270 /**
271  * Sets a new <code>Transportation</code> order this SimpleTransporter is 
272  * supposed to carry out. Must not be <code>null</code>!
273  * @param newTransportation desmoj.Transportation : The new 
274  * <code>Transportation</code> order this SimpleTransporter is supposed 
275  * to carry out.
276  */
277 public void setTransportation(Transportation newTransportation) {
278 
279   // check the home base parameter
280   if ( newTransportation == null )
281   {
282     sendWarning ( "The given Transportation this SimpleTransporter should carry "+
283                   "out is only a null pointer. The attempted action is ignored!",
284                   getClass().getName() + ": " + getQuotedName() +
285                   ", Mehtod: void setTransportation(Transportation " +
286                   "newTransportation)",
287                   "A SimpleTransporter needs a reference to a Transportation " +
288                   "he is supposed to carry out.",
289                   "Make sure to provide a valid Transportation object for the "+
290                   "SimpleTransporter to carry out.");
291     
292     return;    // ignore that rubbish and just return
293   }
294   else
295   {
296     this.transportation = newTransportation;
297   }
298 
299 }
300 }