1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg.singleuser.handlers;
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.jstats.distributions.DistContinuous;
21 import nl.tudelft.simulation.logger.Logger;
22 import nl.tudelft.simulation.supplychain.actor.Trader;
23 import nl.tudelft.simulation.supplychain.content.Quote;
24 import nl.tudelft.simulation.supplychain.content.RequestForQuote;
25 import nl.tudelft.simulation.supplychain.handlers.RequestForQuoteHandler;
26 import nl.tudelft.simulation.supplychain.product.Product;
27 import nl.tudelft.simulation.supplychain.stock.StockInterface;
28 import nl.tudelft.simulation.supplychain.transport.TransportMode;
29
30 import org.gscg.common.geo.CalculateLatLonDistance;
31
32 /***
33 * <p>
34 * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
35 * University of Technology </a>, the Netherlands. <br>
36 * See for project information <a
37 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
38 *
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 are proprietary information
46 * of Delft University of Technology.
47 *
48 * @author <a
49 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
50 * van Houten </a>
51 * @version $Revision: 1.1 $ $Date: 2005/08/03 08:52:50 $
52 * @since 1.1.10
53 */
54 public class LatLonRequestForQuoteHandler extends RequestForQuoteHandler
55 {
56 /*** the lat lon distance calculator to use */
57 private CalculateLatLonDistance latLonDistanceCalculator = null;
58
59 /***
60 * constructs a new LatLonRequestForQuoteHandler
61 *
62 * @param owner a trader in this case as only traders handle RFQs
63 * @param stock the stock to check for products when quoting
64 * @param profitMargin the profit margin to use; 1.0 is no profit
65 * @param handlingTime the distribution of the time to react on the RFQ
66 * @param transportMode the default transport mode
67 */
68 public LatLonRequestForQuoteHandler(Trader owner, StockInterface stock,
69 double profitMargin, DistContinuous handlingTime,
70 TransportMode transportMode)
71 {
72 super(owner, stock, profitMargin, handlingTime, transportMode);
73 this.latLonDistanceCalculator = new CalculateLatLonDistance();
74 }
75
76 /***
77 * constructs a new LatLonRequestForQuoteHandler
78 *
79 * @param owner a trader in this case as only traders handle RFQs
80 * @param stock the stock to check for products when quoting
81 * @param profitMargin the profit margin to use; 1.0 is no profit
82 * @param handlingTime the constant time to react on the RFQ
83 * @param transportMode the default transport mode
84 */
85 public LatLonRequestForQuoteHandler(Trader owner, StockInterface stock,
86 double profitMargin, double handlingTime,
87 TransportMode transportMode)
88 {
89 super(owner, stock, profitMargin, handlingTime, transportMode);
90 this.latLonDistanceCalculator = new CalculateLatLonDistance();
91 }
92
93 /***
94 * @see nl.tudelft.simulation.content.HandlerInterface#handleContent(java.io.Serializable)
95 */
96 public boolean handleContent(Serializable content)
97 {
98 RequestForQuote rfq = (RequestForQuote) checkContent(content);
99 if (!isValidContent(rfq))
100 {
101 return false;
102 }
103 Product product = rfq.getProduct();
104
105
106
107 double shippingTimeHours = this.transportMode
108 .transportTime(this.latLonDistanceCalculator.getDistance(rfq
109 .getSender(), rfq.getReceiver())) + 24.0;
110
111 double shippingTime = 0.0;
112 try
113 {
114 shippingTime = TimeUnit.convert(shippingTimeHours,
115 TimeUnitInterface.HOUR, this.owner.getSimulator());
116 } catch (RemoteException exception)
117 {
118 Logger.severe(this, "handleContent", exception);
119 }
120 double weight = rfq.getAmount()
121 * rfq.getProduct().getAverageUnitWeight();
122
123
124 double transportCosts = this.transportMode.transportCosts(
125 this.latLonDistanceCalculator.getDistance(rfq.getSender(), rfq
126 .getReceiver()), weight);
127
128
129
130
131
132
133
134
135
136
137
138 double price = (rfq.getAmount() * product.getUnitMarketPrice() * this.profitMargin)
139 + transportCosts;
140
141
142
143
144
145
146
147 double proposedShippingDate = Math.max(
148 (this.owner.getSimulatorTime() + shippingTime), rfq
149 .getEarliestDeliveryDate());
150
151 Quote quote = new Quote(this.owner, rfq.getSender(), rfq
152 .getInternalDemandID(), rfq, product, rfq.getAmount(), price,
153 proposedShippingDate, this.transportMode);
154 super.owner.sendContent(quote, this.handlingTime.draw());
155 return true;
156 }
157 }