1
2
3
4
5
6
7
8
9
10
11
12
13
14 package nl.tudelft.simulation.supplychain.handlers;
15
16 import java.io.Serializable;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.Map;
21
22 import nl.tudelft.simulation.jstats.distributions.DistConstant;
23 import nl.tudelft.simulation.jstats.distributions.DistContinuous;
24 import nl.tudelft.simulation.jstats.streams.Java2Random;
25 import nl.tudelft.simulation.logger.Logger;
26 import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
27 import nl.tudelft.simulation.supplychain.content.InternalDemand;
28 import nl.tudelft.simulation.supplychain.content.RequestForQuote;
29 import nl.tudelft.simulation.supplychain.product.Product;
30 import nl.tudelft.simulation.supplychain.stock.StockInterface;
31
32 /***
33 * The InternalDemandHandlerRFQ is a simple implementation of the business logic
34 * to handle a request for new products through sending out a number of RFQs to
35 * a list of preselected suppliers. When receiving the internal demand, it just
36 * creates a number of RFQs based on a table that maps Products onto a list of
37 * Actors, and sends them out, all at the same time, after a given time delay.
38 * <br>
39 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
40 * Delft, the Netherlands. All rights reserved.
41 *
42 * See for project information <a href="http://www.simulation.tudelft.nl/">
43 * www.simulation.tudelft.nl </a>.
44 *
45 * The source code and binary code of this software is proprietary information
46 * of Delft University of Technology.
47 *
48 * @author <a
49 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
50 * Verbraeck </a>
51 * @version $$Revision: 1.3 $$ $$Date: 2005/04/08 12:00:56 $$
52 */
53 public class InternalDemandHandlerRFQ extends InternalDemandHandler
54 {
55 /*** the serial version uid */
56 private static final long serialVersionUID = 12L;
57
58 /*** a table to map the products onto a list of possible suppliers */
59 private Map suppliers = new HashMap();
60
61 /***
62 * Constructs a new InternalDemandHandlerRFQ
63 *
64 * @param owner the owner of the internal demand
65 * @param handlingTime the handling time distribution delay to use
66 * @param stock the stock for being able to change the ordered amount
67 */
68 public InternalDemandHandlerRFQ(final SupplyChainActor owner,
69 final DistContinuous handlingTime, final StockInterface stock)
70 {
71 super(owner, handlingTime, stock);
72 }
73
74 /***
75 * Constructs a new InternalDemandHandlerRFQ
76 *
77 * @param owner the owner of the internal demand
78 * @param handlingTime the constant handling time delay to use
79 * @param stock the stock for being able to change the ordered amount
80 */
81 public InternalDemandHandlerRFQ(final SupplyChainActor owner,
82 final double handlingTime, final StockInterface stock)
83 {
84 this(owner, new DistConstant(new Java2Random(), handlingTime), stock);
85 }
86
87 /***
88 * Add a supplier to send an RFQ to for a certain product
89 *
90 * @param product the product with a set of suppliers.
91 * @param supplier a supplier for that product.
92 */
93 public void addSupplier(final Product product,
94 final SupplyChainActor supplier)
95 {
96 HashSet supplierSet = (HashSet) this.suppliers.get(product);
97 if (supplierSet == null)
98 {
99 supplierSet = new HashSet();
100 this.suppliers.put(product, supplierSet);
101 }
102 supplierSet.add(supplier);
103 }
104
105 /***
106 * Remove a supplier to send an RFQ to for a certain product
107 *
108 * @param product the product.
109 * @param supplier the supplier for that product to be removed.
110 */
111 public void removeSupplier(final Product product,
112 final SupplyChainActor supplier)
113 {
114 HashSet supplierSet = (HashSet) this.suppliers.get(product);
115 if (supplierSet != null)
116 {
117 supplierSet.remove(supplier);
118 }
119 }
120
121 /***
122 * @see nl.tudelft.simulation.content.HandlerInterface
123 * #handleContent(java.io.Serializable)
124 */
125 public boolean handleContent(final Serializable content)
126 {
127 InternalDemand internalDemand = (InternalDemand) checkContent(content);
128 if (!isValidContent(internalDemand))
129 {
130 Logger.warning(this, "handleContent", "InternalDemand for actor "
131 + super.owner + " contains product "
132 + internalDemand.getProduct().toString()
133 + ", but handler not considered valid.");
134 return false;
135 }
136
137 HashSet supplierSet = (HashSet) this.suppliers.get(internalDemand
138 .getProduct());
139 if (supplierSet == null)
140 {
141 Logger.warning(this, "handleContent", "InternalDemand for actor "
142 + super.owner + " contains product "
143 + internalDemand.getProduct().toString()
144 + " without any suppliers.");
145 return false;
146 }
147
148 if (super.stock != null)
149 {
150 super.stock.changeOrderedAmount(internalDemand.getProduct(),
151 internalDemand.getAmount());
152 }
153 double delay = this.handlingTime.draw();
154 Iterator supplierIterator = supplierSet.iterator();
155 while (supplierIterator.hasNext())
156 {
157 SupplyChainActor supplier = (SupplyChainActor) supplierIterator
158 .next();
159 RequestForQuote rfq = new RequestForQuote(super.owner, supplier,
160 internalDemand, internalDemand.getProduct(), internalDemand
161 .getAmount(), internalDemand
162 .getEarliestDeliveryDate(), internalDemand
163 .getLatestDeliveryDate());
164
165 super.owner.sendContent(rfq, delay);
166 }
167 return true;
168 }
169 }