Advanced Modelling FeaturesRes
The Ship Process |
||
Ships are modelled as simulation processes. The Ship class carries a single attribute size, the ship's size in number of berths needed. Let's have a look at the lifeCycle() of this process: /** * Describes this ship's life cycle: * * On arrival, the ship will request a number of berths according to its size. * This will result in having the ship wait until enough space is available. * It will then proceed to the quay for unloading. * After service it leaves the system. */ public void lifeCycle() throws SuspendExecution { // get a reference to the model ResExample model = (ResExample)getModel(); // arrive at the harbour // trace note just for information sendTraceNote("available berths: " + model.berths.getAvail()); // try to acquire the needed berths // --> the process may be passivated and placed on an internal queue // by the res if there are not enough berths available model.berths.provide(size); // now the ship got its resources and can proceed with the unloading hold(new TimeSpan(model.getServiceTime() * this.size, TimeUnit.MINUTES)); // the time needed depends on the size of ship // ship has been serviced // --> releases its resources (leaves the quay) model.berths.takeBack(size); // trace note for information sendTraceNote("available berths: " + model.berths.getAvail()); // leaves the system } We start with sending some information to the trace output when the ship arrives. Thus we'll see in the trace report how many resources are available in the Res object before the ship requests any. Using the provide() method the ship then tries to acquire the amount of berths corresponding to its size. This may result in the ship process to be automatically passivated by the Res object, if there are not enough resources available. The ship process may be inserted into the internal waiting queue of the Res object then. Otherwise it receives its resources immediately and proceeds. Docking and unloading is modelled as a hold(). The duration for that hold() depends on the ship's size. Finally, the ship hands its occupied resources back to the Res and leaves the system. |
||
http://desmoj.sourceforge.net/tutorial/advanced/res3.html |