Source code: desmoj/Transportation.java
1 package desmoj;
2
3 import desmoj.dist.*; // import the random number distributions
4
5 /**
6 * Transportation is the object representing the process cooperation between a
7 * <code>Transporter</code> process and the goods (products represented by
8 * SimProcesses) he is transporting.
9 * It is intended that that this Transportation is used with the
10 * <code>TransportJunction</code> construct, where a <code>Transporter</code>
11 * ( as a master process) is waiting for goods (slave processes) to carry them
12 * around in the manufacturing system. During the Transportation the master is
13 * active and the slaves are passive. The transportation carried out together
14 * is described in the method <code>cooperation</code>, which can be overwritten
15 * by the user to build more complex models. Until now this method only models
16 * the time it takes to transport the goods.
17 * Note: when using the <code>TransportJunction</code> construct the master
18 * (Transporter) will be activated after the transportation is done and
19 * the slaves will be activated after the master (if they have not been
20 * activated during the transportation already).
21 *
22 * @author: Soenke Claassen
23 *
24 * @see desmoj.TransportJunction
25 *
26 * @version DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL
27 */
28 public class Transportation extends ProcessCoop {
29
30 /**
31 * The random number stream determining the time it takes to transport the goods.
32 */
33 private desmoj.dist.RealDist transportTimeStream;
34 /**
35 * Constructs a Transportation process where a master (<code>Transporter</code>)
36 * is transporting slaves (<code>SimPorcess</code>es) in a cooperate process.
37 * The time it takes to transport the goods is determined by the specified
38 * transportTimeStream.
39 * @param owner desmoj.Model : The model this Transportation is associated to.
40 * @param name java.lang.String : the name of this Transportation.
41 * @param transportTimeStream desmoj.dist.RealDist : The random number stream
42 * determining the time it takes to transport the goods.
43 * @param showInTrace boolean : Flag, if this Transportation should produce
44 * a trace output or not.
45 */
46 public Transportation(Model owner, String name, RealDist transportTimeStream,
47 boolean showInTrace)
48 {
49 super(owner, name, showInTrace); // make a ProcessCoop
50
51 this.transportTimeStream = transportTimeStream;
52 }
53 /**
54 * The <code>cooperation()</code> method with only one master and one slave
55 * is not needed here. So we pass it to the more general method with an array
56 * of slaves as parameter.
57 */
58 protected void cooperation(SimProcess master, SimProcess slave)
59 {
60 // make an array for the slave to be wrapped up
61 SimProcess[] wrapArray = new SimProcess[1];
62
63 wrapArray[0] = slave;
64
65 // hand it over to the more general cooperation method
66 transport (master, wrapArray);
67 }
68 /**
69 * Returns a <code>SimTime</code> object representing the time it takes to
70 * transport the goods with the transporter. The time is taken from the given
71 * random number stream transportTimeStream.
72 * @return desmoj.SimTime : The time it takes to transport the goods with
73 * the transporter.
74 */
75 protected SimTime getTransportTimeSample() {
76
77 return new SimTime( transportTimeStream.sample() );
78 }
79 /**
80 * Sets the transportTimeStream to a new <code>RealDist</code> random number
81 * stream.
82 * @param newTransportTimeStream desmoj.dist.RealDist : The new
83 * <code>RealDist</code> random number stream determining the time it takes to
84 * transport the goods.
85 */
86 public void setTransportTimeStream(RealDist newTransportTimeStream) {
87
88 this.transportTimeStream = newTransportTimeStream;
89 }
90 /**
91 * This method describes the transportation process carried out by the master
92 * process (some kind of <code>Transporter</code>). In this simple case only
93 * the time it takes to transport the goods is taken into consideration.
94 * If the user building the model has to implement a more complex behavior,
95 * he has to overwrite this method in a subclass.
96 * The time it takes to transport the goods is obtained from the method
97 * <code>getTransportTimeSample()</code>.
98 * @param master SimProcess : The master process which really carries out
99 * the cooperation. Should be a subclass of <code>Transporter</code>.
100 * @param slaves SimProcess[] : The slave processes which are lead through the
101 * cooperation by the master.
102 */
103 protected void transport(SimProcess master, SimProcess[] slaves)
104 {
105 // check if the master is a Transporter
106 if ( ! (master instanceof desmoj.Transporter) )
107 {
108 sendWarning ( "The given master process for a transportation is "+
109 "not a Transporter. The transport will be carried out anyway!",
110 "Transportation : "+getName()+" Method: void "+
111 "cooperation (SimProcess master, SimProcess[] slave)",
112 "The given master process is not a Transporter.",
113 "It is recommended to use a Transporter process as a master "+
114 "to carry out a transportation");
115 }
116
117 // hold for the time the goods are transported
118 hold ( getTransportTimeSample() );
119
120 }
121 /**
122 * The <code>transport()</code> method with only one master and one slave
123 * is not needed here. So we pass it to the more general method with an array
124 * of slaves as parameter.
125 */
126 protected void transport(SimProcess master, SimProcess slave)
127 {
128 // make an array for the slave to be wrapped up
129 SimProcess[] wrapArray = new SimProcess[1];
130
131 wrapArray[0] = slave;
132
133 // hand it over to the more general cooperation method
134 transport (master, wrapArray);
135 }
136 }