1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg.singleuser.production;
14
15 import java.io.Serializable;
16 import java.rmi.RemoteException;
17
18 import nl.tudelft.simulation.dsol.experiment.TimeUnit;
19 import nl.tudelft.simulation.dsol.experiment.TimeUnitInterface;
20 import nl.tudelft.simulation.dsol.formalisms.devs.SimEvent;
21 import nl.tudelft.simulation.dsol.formalisms.devs.SimEventInterface;
22 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
23 import nl.tudelft.simulation.logger.Logger;
24 import nl.tudelft.simulation.supplychain.product.Product;
25 import nl.tudelft.simulation.supplychain.stock.StockInterface;
26
27 /***
28 * The ProductionSchedule is used to produce a product according to a predefined
29 * schedule. In this case it simply takes a number of time specified in days to
30 * produce a certain amount of products. After production, the products are
31 * added to the stock.
32 * <p>
33 * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
34 * University of Technology </a>, the Netherlands. <br>
35 * See for project information <a
36 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
37 *
38 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
39 * Delft, the Netherlands. All rights reserved.
40 *
41 * See for project information <a href="http://www.simulation.tudelft.nl/">
42 * www.simulation.tudelft.nl </a>.
43 *
44 * The source code and binary code of this software are proprietary information
45 * of Delft University of Technology.
46 *
47 * @author <a
48 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
49 * van Houten </a>
50 * @version $Revision: 1.1 $ $Date: 2005/08/09 15:43:41 $
51 * @since 1.1.10
52 */
53 public class ProductionSchedule implements Serializable
54 {
55 /*** true for debugging */
56 private static final boolean DEBUG = true;
57
58 /*** the serial version uid */
59 private static final long serialVersionUID = 10L;
60
61 /*** the product */
62 private Product product = null;
63
64 /*** the amount */
65 private double amount = Double.NaN;
66
67 /*** the time */
68 private double time = Double.NaN;
69
70 /*** the stock */
71 private StockInterface stock = null;
72
73 /*** the simulator */
74 private DEVSSimulatorInterface simulator = null;
75
76 /***
77 * constructs a new ProductionSchedule
78 *
79 * @param product the product
80 * @param amount the amount to produce per time the schedule is executed
81 * @param time the time necessary to execute one schedule
82 * @param stock the stock to add the produced products to
83 * @param simulator the simulator
84 */
85 public ProductionSchedule(final Product product, final double amount,
86 final double time, final StockInterface stock,
87 final DEVSSimulatorInterface simulator)
88 {
89 super();
90 this.product = product;
91 this.amount = amount;
92 this.stock = stock;
93 this.simulator = simulator;
94
95 try
96 {
97 this.time = TimeUnit.convert(time, TimeUnitInterface.DAY,
98 this.simulator);
99 } catch (RemoteException remoteException)
100 {
101 Logger.severe(this, "<init>", remoteException);
102 }
103 }
104
105 /***
106 * @return returns the product
107 */
108 public Product getProduct()
109 {
110 return this.product;
111 }
112
113 /***
114 * @return returns the time expressed in simulator time units
115 */
116 public double getTime()
117 {
118 return this.time;
119 }
120
121 /***
122 * produces the product and adds the produced product to the stock
123 */
124 public void produce()
125 {
126 try
127 {
128 Object[] args = new Object[]{};
129 SimEventInterface simEvent = new SimEvent(this.simulator
130 .getSimulatorTime()
131 + this.time, this, this, "addToStock", args);
132 this.simulator.scheduleEvent(simEvent);
133 } catch (Exception exception)
134 {
135 Logger.severe(this, "produce", exception);
136 }
137 }
138
139 /***
140 * changes the amount of the schedule
141 *
142 * @param percentage the percentage to change the amount with
143 * @param increase true for increase, false for decrease
144 */
145 public void changeAmount(double percentage, boolean increase)
146 {
147 if (increase)
148 {
149 this.amount = Math.ceil((this.amount * (1 + percentage / 100)));
150 System.out
151 .println("DEBUG -- ProductionSchedule: amount increased with: "
152 + percentage
153 + " percent of schedule for product: "
154 + this.product
155 + " for actor: "
156 + this.stock.getOwner().getName()
157 + ". New amount = " + this.amount);
158 } else
159 {
160 this.amount = Math.ceil((this.amount * (1 - percentage / 100)));
161 System.out
162 .println("DEBUG -- ProductionSchedule: amount decreased with: "
163 + percentage
164 + " percent of schedule for product: "
165 + this.product
166 + " for actor: "
167 + this.stock.getOwner().getName()
168 + ". New amount = " + this.amount);
169 }
170 }
171
172 /***
173 * changes the production time of the schedule
174 *
175 * @param percentage the percentage to change the production time with
176 * @param increase true for increase, false for decrease
177 */
178 public void changeProductionTime(double percentage, boolean increase)
179 {
180 if (increase)
181 {
182 this.time = Math.ceil((this.amount * (1 + percentage / 100)));
183 if (ProductionSchedule.DEBUG)
184 {
185 System.out
186 .println("DEBUG -- ProductionSchedule: production time increased with: "
187 + percentage
188 + " percent of schedule for product: "
189 + this.product
190 + " for actor: "
191 + this.stock.getOwner().getName()
192 + ". New time = " + this.time);
193 }
194 } else
195 {
196 this.time = Math.ceil((this.amount * (1 - percentage / 100)));
197 if (ProductionSchedule.DEBUG)
198 {
199 System.out
200 .println("DEBUG -- ProductionSchedule: production time decreased with: "
201 + percentage
202 + " percent of schedule for product: "
203 + this.product
204 + " for actor: "
205 + this.stock.getOwner().getName()
206 + ". New time = " + this.time);
207 }
208 }
209 }
210
211 /***
212 * adds the products to the stock
213 */
214 protected void addToStock()
215 {
216 this.stock.addStock(this.product, this.amount, this.product
217 .getUnitMarketPrice()
218 * this.amount);
219 if (ProductionSchedule.DEBUG)
220 {
221 System.out.println("DEBUG -- ProductionSchedule: amount: "
222 + this.amount + " of product: " + this.product.getName()
223 + " added to stock of actor: "
224 + this.stock.getOwner().getName());
225 }
226 }
227 }