1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg.experiment;
14
15 import java.rmi.RemoteException;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.List;
19
20 import nl.tudelft.simulation.actor.ActorInterface;
21 import nl.tudelft.simulation.dsol.experiment.TimeUnit;
22 import nl.tudelft.simulation.dsol.experiment.TimeUnitInterface;
23 import nl.tudelft.simulation.jstats.distributions.DistConstant;
24 import nl.tudelft.simulation.jstats.distributions.DistContinuous;
25 import nl.tudelft.simulation.jstats.distributions.DistExponential;
26 import nl.tudelft.simulation.jstats.distributions.DistNormal;
27 import nl.tudelft.simulation.jstats.distributions.DistTriangular;
28 import nl.tudelft.simulation.jstats.streams.StreamInterface;
29 import nl.tudelft.simulation.logger.Logger;
30 import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
31 import nl.tudelft.simulation.supplychain.actor.Trader;
32 import nl.tudelft.simulation.supplychain.content.Bill;
33 import nl.tudelft.simulation.supplychain.content.InternalDemand;
34 import nl.tudelft.simulation.supplychain.content.Order;
35 import nl.tudelft.simulation.supplychain.content.OrderConfirmation;
36 import nl.tudelft.simulation.supplychain.content.Payment;
37 import nl.tudelft.simulation.supplychain.content.Quote;
38 import nl.tudelft.simulation.supplychain.content.RequestForQuote;
39 import nl.tudelft.simulation.supplychain.content.Shipment;
40 import nl.tudelft.simulation.supplychain.handlers.BillHandler;
41 import nl.tudelft.simulation.supplychain.handlers.BillTimeOutHandler;
42 import nl.tudelft.simulation.supplychain.handlers.InternalDemandHandlerRFQ;
43 import nl.tudelft.simulation.supplychain.handlers.OrderConfirmationFineHandler;
44 import nl.tudelft.simulation.supplychain.handlers.OrderHandlerStock;
45 import nl.tudelft.simulation.supplychain.handlers.PaymentFineHandler;
46 import nl.tudelft.simulation.supplychain.handlers.PaymentHandler;
47 import nl.tudelft.simulation.supplychain.handlers.ProductionOrderHandler;
48 import nl.tudelft.simulation.supplychain.handlers.QuoteHandler;
49 import nl.tudelft.simulation.supplychain.handlers.QuoteHandlerTimeout;
50 import nl.tudelft.simulation.supplychain.handlers.RequestForQuoteHandler;
51 import nl.tudelft.simulation.supplychain.handlers.ShipmentFineHandlerConsume;
52 import nl.tudelft.simulation.supplychain.handlers.ShipmentFineHandlerStock;
53 import nl.tudelft.simulation.supplychain.handlers.ShipmentHandlerConsume;
54 import nl.tudelft.simulation.supplychain.handlers.ShipmentHandlerStock;
55 import nl.tudelft.simulation.supplychain.product.Product;
56 import nl.tudelft.simulation.supplychain.production.Production;
57 import nl.tudelft.simulation.supplychain.stock.policies.RestockingPolicySafety;
58 import nl.tudelft.simulation.supplychain.transport.TransportMode;
59
60 import org.gscg.gameactors.GameDistributor;
61 import org.gscg.singleuser.handlers.InteractiveBillHandler;
62 import org.gscg.singleuser.handlers.InteractiveBillTimeOutHandler;
63 import org.gscg.singleuser.handlers.InteractiveInternalDemandHandler;
64 import org.gscg.singleuser.handlers.InteractiveOrderConfirmationFineHandler;
65 import org.gscg.singleuser.handlers.InteractiveOrderHandlerStock;
66 import org.gscg.singleuser.handlers.InteractiveQuoteHandler;
67 import org.gscg.singleuser.handlers.InteractiveRequestForQuoteHandler;
68 import org.gscg.singleuser.handlers.LatLonOrderHandlerStock;
69 import org.gscg.singleuser.handlers.LatLonRequestForQuoteHandler;
70 import org.gscg.singleuser.handlers.ManufacturerOrderHandlerProduce;
71 import org.gscg.singleuser.handlers.PCShopOrderHandlerMake;
72 import org.gscg.singleuser.handlers.PCShopRequestForQuoteHandler;
73 import org.gscg.singleuser.production.GameDelayProductionService;
74 import org.gscg.singleuser.production.ProductionSchedule;
75 import org.jdom.Element;
76 import org.jdom.Namespace;
77
78 /***
79 * Parses XML Elements into handlers.
80 * <p>
81 * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
82 * University of Technology </a>, the Netherlands. <br>
83 * See for project information <a
84 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
85 *
86 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
87 * Delft, the Netherlands. All rights reserved.
88 *
89 * See for project information <a href="http://www.simulation.tudelft.nl/">
90 * www.simulation.tudelft.nl </a>.
91 *
92 * The source code and binary code of this software are proprietary information
93 * of Delft University of Technology.
94 *
95 * @author <a
96 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
97 * van Houten </a>
98 * @version $Revision: 1.3 $ $Date: 2005/08/10 11:23:30 $
99 * @since 1.1.10
100 */
101 public final class HandlerParser
102 {
103 /*** true for debugging */
104 private static final boolean DEBUG = false;
105
106 /***
107 * constructs a new HandlerParser
108 */
109 protected HandlerParser()
110 {
111
112 super();
113 }
114
115 /***
116 * parses the given handler element to a handler and adds this to the actor
117 *
118 * @param actor the actor
119 * @param rootElement the root element with all the handlers
120 */
121 public static void parseAndAddHandler(final SupplyChainActor actor,
122 final Element rootElement)
123 {
124 for (Iterator i = rootElement.getChildren().iterator(); i.hasNext();)
125 {
126 Element groupElement = (Element) i.next();
127 String groupName = groupElement.getName();
128 if (groupName.equalsIgnoreCase("internaldemandhandlergroup"))
129 {
130 List children = groupElement.getChildren();
131 for (int ii = 0; ii < children.size(); ii++)
132 {
133 Element handlerElement = (Element) children.get(ii);
134 String handlerName = handlerElement.getName();
135
136 if (handlerName
137 .equalsIgnoreCase("InternalDemandHandlerRFQ"))
138 {
139 HandlerParser.parseInternalDemandHandlerRFQ(actor,
140 handlerElement);
141 } else if (handlerName
142 .equalsIgnoreCase("InteractiveInternalDemandHandler"))
143 {
144 HandlerParser
145 .parseInteractiveInternalDemandHandler(actor);
146 } else
147 {
148 Logger.severe(HandlerParser.class,
149 "internaldemandhandlergroup",
150 "Unknown handler: " + handlerName);
151 }
152 }
153 } else if (groupName
154 .equalsIgnoreCase("requestforquotehandlergroup"))
155 {
156 List children = groupElement.getChildren();
157 for (int ii = 0; ii < children.size(); ii++)
158 {
159 Element handlerElement = (Element) children.get(ii);
160 String handlerName = handlerElement.getName();
161
162 if (handlerName.equalsIgnoreCase("RequestForQuoteHandler"))
163 {
164 HandlerParser.parseRequestForQuoteHandler(
165 (Trader) actor, handlerElement);
166 } else if (handlerName
167 .equalsIgnoreCase("PCShopRequestForQuoteHandler"))
168 {
169 HandlerParser.parsePCShopRequestForQuoteHandler(
170 (Trader) actor, handlerElement);
171 } else if (handlerName
172 .equalsIgnoreCase("LatLonRequestForQuoteHandler"))
173 {
174 HandlerParser.parseLatLonRequestForQuoteHandler(
175 (Trader) actor, handlerElement);
176 } else if (handlerName
177 .equalsIgnoreCase("InteractiveRequestForQuoteHandler"))
178 {
179 HandlerParser
180 .parseInteractiveRequestForQuoteHandler(actor);
181 } else
182 {
183 Logger.severe(HandlerParser.class,
184 "requestforquotehandlergroup",
185 "Unknown handler: " + handlerName);
186 }
187 }
188 } else if (groupName.equalsIgnoreCase("quotehandlergroup"))
189 {
190 List children = groupElement.getChildren();
191 for (int ii = 0; ii < children.size(); ii++)
192 {
193 Element handlerElement = (Element) children.get(ii);
194 String handlerName = handlerElement.getName();
195
196 if (handlerName.equalsIgnoreCase("QuoteHandlerTimeout"))
197 {
198 HandlerParser.parseQuoteHandlerTimeOut(actor,
199 handlerElement);
200 } else if (handlerName
201 .equalsIgnoreCase("InteractiveQuoteHandler"))
202 {
203 HandlerParser
204 .parseInteractiveQuoteHandler((GameDistributor) actor);
205 } else
206 {
207 Logger.severe(HandlerParser.class, "quotehandlergroup",
208 "Unknown handler: " + handlerName);
209 }
210 }
211 } else if (groupName.equalsIgnoreCase("orderhandlergroup"))
212 {
213 List children = groupElement.getChildren();
214 for (int ii = 0; ii < children.size(); ii++)
215 {
216 Element handlerElement = (Element) children.get(ii);
217 String handlerName = handlerElement.getName();
218
219 if (handlerName.equalsIgnoreCase("OrderHandlerStock"))
220 {
221 HandlerParser.parseOrderHandlerStock((Trader) actor);
222 } else if (handlerName
223 .equalsIgnoreCase("ManufacturerOrderHandlerProduce"))
224 {
225 HandlerParser.parseManufacturerOrderHandlerProduce(
226 (Trader) actor, handlerElement);
227 } else if (handlerName
228 .equalsIgnoreCase("PCShopOrderHandlerMake"))
229 {
230 HandlerParser.parsePCShopOrderHandlerMake(
231 (Trader) actor, handlerElement);
232 } else if (handlerName
233 .equalsIgnoreCase("LatLonOrderHandlerStock"))
234 {
235 HandlerParser
236 .parseLatLonOrderHandlerStock((Trader) actor);
237 } else if (handlerName
238 .equalsIgnoreCase("InteractiveOrderHandlerStock"))
239 {
240 HandlerParser
241 .parseInteractiveOrderHandlerStock((Trader) actor);
242 } else
243 {
244 Logger.severe(HandlerParser.class, "orderhandlergroup",
245 "Unknown handler: " + handlerName);
246 }
247 }
248 } else if (groupName
249 .equalsIgnoreCase("orderconfirmationhandlergroup"))
250 {
251 List children = groupElement.getChildren();
252 for (int ii = 0; ii < children.size(); ii++)
253 {
254 Element handlerElement = (Element) children.get(ii);
255 String handlerName = handlerElement.getName();
256
257 if (handlerName
258 .equalsIgnoreCase("OrderConfirmationFineHandler"))
259 {
260 HandlerParser.parseOrderConfirmationFineHandler(actor,
261 handlerElement);
262 } else if (handlerName
263 .equalsIgnoreCase("InteractiveOrderConfirmationFineHandler"))
264 {
265 HandlerParser
266 .parseInteractiveOrderConfirmationFineHandler(
267 actor, handlerElement);
268 } else
269 {
270 Logger.severe(HandlerParser.class,
271 "orderconfirmationhandlergroup",
272 "Unknown handler: " + handlerName);
273 }
274 }
275 } else if (groupName.equalsIgnoreCase("shipmenthandlergroup"))
276 {
277 List children = groupElement.getChildren();
278 for (int ii = 0; ii < children.size(); ii++)
279 {
280 Element handlerElement = (Element) children.get(ii);
281 String handlerName = handlerElement.getName();
282
283 if (handlerName.equalsIgnoreCase("ShipmentHandlerStock"))
284 {
285 HandlerParser.parseShipmentHandlerStock((Trader) actor);
286 } else if (handlerName
287 .equalsIgnoreCase("ShipmentFineHandlerStock"))
288 {
289 HandlerParser.parseShipmentFineHandlerStock(
290 (Trader) actor, handlerElement);
291 } else if (handlerName
292 .equalsIgnoreCase("ShipmentHandlerConsume"))
293 {
294 HandlerParser.parseShipmentHandlerConsume(actor);
295 } else if (handlerName
296 .equalsIgnoreCase("ShipmentFineHandlerConsume"))
297 {
298 HandlerParser.parseShipmentFineHandlerConsume(actor,
299 handlerElement);
300 } else
301 {
302 Logger.severe(HandlerParser.class,
303 "shipmenthandlergroup", "Unknown handler: "
304 + handlerName);
305 }
306 }
307 } else if (groupName.equalsIgnoreCase("billhandlergroup"))
308 {
309 List children = groupElement.getChildren();
310 for (int ii = 0; ii < children.size(); ii++)
311 {
312 Element handlerElement = (Element) children.get(ii);
313 String handlerName = handlerElement.getName();
314
315 if (handlerName.equalsIgnoreCase("BillHandler"))
316 {
317 HandlerParser.parseBillHandler(actor, handlerElement);
318 } else if (handlerName
319 .equalsIgnoreCase("BillTimeOutHandler"))
320 {
321 HandlerParser.parseBillTimeOutHandler(actor,
322 handlerElement);
323 } else if (handlerName
324 .equalsIgnoreCase("InteractiveBillHandler"))
325 {
326 HandlerParser.parseInteractiveBillHandler(actor);
327 } else if (handlerName
328 .equalsIgnoreCase("InteractiveBillTimeOutHandler"))
329 {
330 HandlerParser.parseInteractiveBillTimeOutHandler(actor,
331 handlerElement);
332 } else
333 {
334 Logger.severe(HandlerParser.class, "billhandlergroup",
335 "Unknown handler: " + handlerName);
336 }
337 }
338 } else if (groupName.equalsIgnoreCase("paymenthandlergroup"))
339 {
340 List children = groupElement.getChildren();
341 for (int ii = 0; ii < children.size(); ii++)
342 {
343 Element handlerElement = (Element) children.get(ii);
344 String handlerName = handlerElement.getName();
345
346 if (handlerName.equalsIgnoreCase("PaymentHandler"))
347 {
348 HandlerParser
349 .parsePaymentHandler(actor, handlerElement);
350 } else if (handlerName
351 .equalsIgnoreCase("PaymentFineHandler"))
352 {
353 HandlerParser.parsePaymentFineHandler(actor,
354 handlerElement);
355 } else
356 {
357 Logger.severe(HandlerParser.class,
358 "paymenthandlergroup", "Unknown handler: "
359 + handlerName);
360 }
361 }
362 } else if (groupName.equalsIgnoreCase("stockpolicygroup"))
363 {
364 List children = groupElement.getChildren();
365 for (int ii = 0; ii < children.size(); ii++)
366 {
367 Element handlerElement = (Element) children.get(ii);
368 String handlerName = handlerElement.getName();
369
370 if (handlerName.equalsIgnoreCase("RestockingPolicySafety"))
371 {
372 HandlerParser.parseRestockingPolicySafety(
373 (Trader) actor, handlerElement);
374 } else
375 {
376 Logger.severe(HandlerParser.class, "stockpolicygroup",
377 "Unknown handler: " + handlerName);
378 }
379 }
380 } else
381 {
382 System.err.println("Found unknown handler group name: "
383 + groupName);
384 }
385 }
386 }
387
388 /***
389 * parses the element and adds a request for quote handler to the trader
390 *
391 * @param trader the trader to add the handler to
392 * @param content the element containing the data for the handler
393 */
394 private static void parseRequestForQuoteHandler(final Trader trader,
395 final Element content)
396 {
397 double profit = 0.0;
398 TransportMode mode = null;
399 double handlingTime = 0.0;
400
401 profit = new Double(content.getAttributeValue("profit")).doubleValue();
402 try
403 {
404 mode = HandlerParser.parseTransportMode(content
405 .getAttributeValue("transportMode"));
406 } catch (Exception exception)
407 {
408 Logger.severe(HandlerParser.class, "parseRequestForQuoteHandler",
409 exception);
410 }
411
412 Element handlingTimeElement = content.getChild("handlingTime");
413 handlingTime = HandlerParser.parseHandlingTime(handlingTimeElement,
414 trader);
415
416 RequestForQuoteHandler handler = new RequestForQuoteHandler(trader,
417 trader.getStock(), profit, handlingTime, mode);
418 trader.addContentHandler(RequestForQuote.class, handler);
419 Logger.info(HandlerParser.class, "parseRequestForQuoteHandler",
420 "RequestForQuoteHandler added to: " + trader.getName());
421 }
422
423 /***
424 * parses the element and adds a lat lon request for quote handler to the
425 * trader
426 *
427 * @param trader the trader to add the handler to
428 * @param content the element containing the data for the handler
429 */
430 private static void parseLatLonRequestForQuoteHandler(final Trader trader,
431 final Element content)
432 {
433 double profit = 0.0;
434 TransportMode mode = null;
435 double handlingTime = 0.0;
436
437 profit = new Double(content.getAttributeValue("profit")).doubleValue();
438 try
439 {
440 mode = HandlerParser.parseTransportMode(content
441 .getAttributeValue("transportMode"));
442 } catch (Exception exception)
443 {
444 Logger.severe(HandlerParser.class,
445 "parseLatLonRequestForQuoteHandler", exception);
446 }
447
448 Element handlingTimeElement = content.getChild("handlingTime");
449 handlingTime = HandlerParser.parseHandlingTime(handlingTimeElement,
450 trader);
451
452 LatLonRequestForQuoteHandler handler = new LatLonRequestForQuoteHandler(
453 trader, trader.getStock(), profit, handlingTime, mode);
454 trader.addContentHandler(RequestForQuote.class, handler);
455 Logger.info(HandlerParser.class, "parseLatLonRequestForQuoteHandler",
456 "LatLonRequestForQuoteHandler added to: " + trader.getName());
457 }
458
459 /***
460 * parses the element and adds an order handler stock to the trader
461 *
462 * @param trader the trader to add the handler to
463 */
464 private static void parseOrderHandlerStock(final Trader trader)
465 {
466 OrderHandlerStock handler = new OrderHandlerStock(trader, trader
467 .getStock());
468 trader.addContentHandler(Order.class, handler);
469 Logger.info(HandlerParser.class, "parseOrderHandlerStock",
470 "OrderHandlerStock added to: " + trader.getName());
471 }
472
473 /***
474 * parses the element and adds an manufacturer order handler Produce handler
475 * stock to the trader
476 *
477 * @param trader the trader to add the handler to
478 * @param content the element containing the content
479 */
480 private static void parseManufacturerOrderHandlerProduce(
481 final Trader trader, final Element content)
482 {
483 try
484 {
485 Production production = new Production(trader);
486 List productionServices = content.getChildren("productionservice");
487 for (Iterator it = productionServices.iterator(); it.hasNext();)
488 {
489 Element productionService = (Element) it.next();
490 production.addProductionService(HandlerParser
491 .getProductionService((Element) productionService
492 .getChildren().get(0), trader));
493 }
494 ManufacturerOrderHandlerProduce handler = new ManufacturerOrderHandlerProduce(
495 trader, new ProductionOrderHandler(trader, production));
496 trader.addContentHandler(Order.class, handler);
497 Logger.info(HandlerParser.class,
498 "parseManufacturerOrderHandlerProduce",
499 "ManufacturerOrderHandlerProduce added to: "
500 + trader.getName());
501 } catch (Exception exception)
502 {
503 exception.printStackTrace();
504 }
505 }
506
507 /***
508 * parses the element and adds a pc shop order handler male to the trader
509 *
510 * @param trader the trader to add the handler to
511 * @param content the element containing the content
512 */
513 private static void parsePCShopOrderHandlerMake(final Trader trader,
514 final Element content)
515 {
516 List productSchedulesElements = content
517 .getChildren("productionSchedule");
518 List productSchedules = new ArrayList();
519
520 for (Iterator it = productSchedulesElements.iterator(); it.hasNext();)
521 {
522 Element productScheduleElement = (Element) it.next();
523
524 String productName = productScheduleElement
525 .getAttributeValue("productName");
526 Iterator stockIterator = trader.getStock().iterator();
527 Product product = null;
528 while (stockIterator.hasNext())
529 {
530 product = (Product) stockIterator.next();
531 if (product.getName().equalsIgnoreCase(productName))
532 {
533 break;
534 }
535 }
536 double amount = new Double(productScheduleElement
537 .getAttributeValue("amount")).doubleValue();
538
539 Element productionElement = productScheduleElement
540 .getChild("productionTime");
541 double productionTime = HandlerParser.parseHandlingTime(
542 productionElement, trader);
543
544 ProductionSchedule schedule = new ProductionSchedule(product,
545 amount, productionTime, trader.getStock(), trader
546 .getSimulator());
547 if (HandlerParser.DEBUG)
548 {
549 System.out
550 .println("DEBUG -- HandlerParser:parsePCShopOrderHandlerMake: schedule created for: "
551 + product.getName()
552 + " amount: "
553 + amount
554 + " productionTime: " + productionTime);
555 }
556 productSchedules.add(schedule);
557 }
558
559 PCShopOrderHandlerMake handler = new PCShopOrderHandlerMake(
560 trader,
561 (ProductionSchedule[]) productSchedules
562 .toArray(new ProductionSchedule[productSchedules.size()]));
563 trader.addContentHandler(Order.class, handler);
564 Logger.info(HandlerParser.class, "parsePCShopOrderHandlerMake",
565 "PCShopOrderHandlerMake added to: " + trader.getName());
566 }
567
568 /***
569 * parses the element and adds an lat lon order handler stock to the trader
570 *
571 * @param trader the trader to add the handler to
572 */
573 private static void parseLatLonOrderHandlerStock(final Trader trader)
574 {
575 LatLonOrderHandlerStock handler = new LatLonOrderHandlerStock(trader,
576 trader.getStock());
577 trader.addContentHandler(Order.class, handler);
578 Logger.info(HandlerParser.class, "parseLatLonOrderHandlerStock",
579 "LatLonOrderHandlerStock added to: " + trader.getName());
580 }
581
582 /***
583 * parses the element and adds a payment handler to the actor
584 *
585 * @param actor the actor to add the handler to
586 * @param element the element containing the data for the handler
587 */
588 private static void parsePaymentHandler(final SupplyChainActor actor,
589 final Element element)
590 {
591 PaymentHandler handler = new PaymentHandler(actor, actor
592 .getBankAccount());
593 actor.addContentHandler(Payment.class, handler);
594 Logger.info(HandlerParser.class, "parsePaymentHandler",
595 "PaymentHandler added to: " + actor.getName());
596 }
597
598 /***
599 * parses the element and adds a payment fine handler to the actor
600 *
601 * @param actor the actor to add the handler to
602 * @param content the element containing the data for the handler
603 */
604 private static void parsePaymentFineHandler(final SupplyChainActor actor,
605 final Element content)
606 {
607 double fineMarginPerDay = new Double(content
608 .getAttributeValue("fineMarginPerDay")).doubleValue();
609 double fixedFinePerDay = new Double(content
610 .getAttributeValue("fixedFinePerDay")).doubleValue();
611
612 PaymentFineHandler handler = new PaymentFineHandler(actor, actor
613 .getBankAccount(), fineMarginPerDay, fixedFinePerDay);
614 actor.addContentHandler(Payment.class, handler);
615 Logger.info(HandlerParser.class, "parsePaymentFineHandler",
616 "PaymentFineHandler added to: " + actor.getName());
617 }
618
619
620 /***
621 * parses the element and adds a restocking policy safety to the trader
622 *
623 * @param trader the trader to add the restocking policy to
624 * @param content the element containing the data for the policy
625 */
626 private static void parseRestockingPolicySafety(final Trader trader,
627 final Element content)
628 {
629 List products = content.getChildren("product");
630 for (Iterator it = products.iterator(); it.hasNext();)
631 {
632 Element productElement = (Element) it.next();
633
634 String productName = productElement
635 .getAttributeValue("productName");
636 Iterator stockIterator = trader.getStock().iterator();
637 Product product = null;
638 while (stockIterator.hasNext())
639 {
640 product = (Product) stockIterator.next();
641 if (product.getName().equalsIgnoreCase(productName))
642 {
643 break;
644 }
645 }
646 Element checkIntervalElement = productElement
647 .getChild("checkInterval");
648
649 double checkInterval = HandlerParser.parseHandlingTime(
650 checkIntervalElement, trader);
651 double amount = new Double(productElement
652 .getAttributeValue("amount")).doubleValue();
653 double safetyAmount = new Double(productElement
654 .getAttributeValue("ceiling")).doubleValue();
655
656 Element maxDeliveryTimeElement = productElement
657 .getChild("maxDeliveryTime");
658 double maxDeliveryTime = HandlerParser.parseHandlingTime(
659 maxDeliveryTimeElement, trader);
660
661 new RestockingPolicySafety(trader.getStock(), product,
662 checkInterval, false, amount, true, safetyAmount,
663 maxDeliveryTime);
664 Logger.info(HandlerParser.class, "parseRestockingPolicySafety",
665 "RestockingPolicySafety added to: " + trader.getName());
666 }
667 }
668
669 /***
670 * parses the element and adds an internal demand handler rfq to the trader
671 *
672 * @param actor the actor to add the internal demand handler rfq to
673 * @param content the element containing the data for the handler
674 */
675 private static void parseInternalDemandHandlerRFQ(
676 final SupplyChainActor actor, final Element content)
677 {
678 Element handlingTimeElement = content.getChild("handlingTime");
679
680 double handlingTime = HandlerParser.parseHandlingTime(
681 handlingTimeElement, actor);
682
683 InternalDemandHandlerRFQ handler = null;
684 if (actor instanceof Trader)
685 {
686 handler = new InternalDemandHandlerRFQ(actor, handlingTime,
687 ((Trader) actor).getStock());
688 } else
689 {
690 handler = new InternalDemandHandlerRFQ(actor, handlingTime, null);
691 }
692 actor.addContentHandler(InternalDemand.class, handler);
693 Logger.info(HandlerParser.class, "parseInternalDemandHandlerRFQ",
694 "InternalDemand added to: " + actor.getName());
695 }
696
697 /***
698 * parses the element and adds a quote handler timeout to the actor
699 *
700 * @param actor the actor to add the restocking policy to
701 * @param content the element containing the data for the handler
702 */
703 private static void parseQuoteHandlerTimeOut(final SupplyChainActor actor,
704 final Element content)
705 {
706 int comparator = 0;
707 try
708 {
709 comparator = HandlerParser.parseQuoteHandlerComparator(content
710 .getAttributeValue("comparator"));
711 } catch (Exception exception)
712 {
713 Logger.severe(HandlerParser.class, "parseQuoteHandlerTimeOut",
714 exception);
715 }
716
717 Element handlingTimeElement = content.getChild("handlingTime");
718
719 double handlingTime = HandlerParser.parseHandlingTime(
720 handlingTimeElement, actor);
721 double maximumPriceMargin = new Double(content
722 .getAttributeValue("maximumpricemargin")).doubleValue();
723
724 QuoteHandlerTimeout handler = new QuoteHandlerTimeout(actor,
725 comparator, handlingTime, maximumPriceMargin);
726 actor.addContentHandler(Quote.class, handler);
727 Logger.info(HandlerParser.class, "parseQuoteHandlerTimeOut",
728 "QuoteHandlerTimeout added to: " + actor.getName());
729 }
730
731 /***
732 * parses the element and adds an order confirmation fine handler to the
733 * actor
734 *
735 * @param actor the actor to add the order confirmation fine handler to
736 * @param content the element containing the data for the handler
737 */
738 private static void parseOrderConfirmationFineHandler(
739 final SupplyChainActor actor, final Element content)
740 {
741 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
742 double maximumTimeOut = HandlerParser.parseHandlingTime(
743 maximumTimeOutElement, actor);
744
745 double fineMargin = new Double(content.getAttributeValue("fineMargin"))
746 .doubleValue();
747 double fixedFine = new Double(content.getAttributeValue("fixedFine"))
748 .doubleValue();
749
750 OrderConfirmationFineHandler handler = new OrderConfirmationFineHandler(
751 actor, maximumTimeOut, fineMargin, fixedFine);
752 actor.addContentHandler(OrderConfirmation.class, handler);
753 Logger.info(HandlerParser.class, "parseOrderConfirmationFineHandler",
754 "OrderConfirmationFineHandler added to: " + actor.getName());
755 }
756
757 /***
758 * parses the element and adds a bill handler to the actor
759 *
760 * @param actor the actor to add the bill handler to
761 * @param content the element containing the data for the handler
762 */
763 private static void parseBillHandler(final SupplyChainActor actor,
764 final Element content)
765 {
766 int billHandlerPolicy = 0;
767 try
768 {
769 billHandlerPolicy = HandlerParser.parseBillHandlerPolicy(content
770 .getAttributeValue("policy"));
771 } catch (Exception exception)
772 {
773 {
774 Logger.severe(HandlerParser.class, "parseBillHandler",
775 exception);
776 }
777 }
778
779 Element paymentDelayElement = content.getChild("paymentDelay");
780 double paymentDelay = HandlerParser.parseHandlingTime(
781 paymentDelayElement, actor);
782 try
783 {
784 BillHandler handler = new BillHandler(actor,
785 actor.getBankAccount(), billHandlerPolicy,
786 new DistConstant(actor.getSimulator().getReplication()
787 .getStream("default"), paymentDelay));
788 actor.addContentHandler(Bill.class, handler);
789 Logger.info(HandlerParser.class, "parseBillHandler",
790 "BillHandler added to: " + actor.getName());
791 } catch (RemoteException remoteException)
792 {
793 Logger.severe(HandlerParser.class, "parseBillHandler",
794 remoteException);
795 }
796 }
797
798 /***
799 * parses the element and adds a bill handler to the actor
800 *
801 * @param actor the actor to add the bill handler to
802 * @param content the element containing the data for the handler
803 */
804 private static void parseBillTimeOutHandler(final SupplyChainActor actor,
805 final Element content)
806 {
807 int billHandlerPolicy = 0;
808 try
809 {
810 billHandlerPolicy = HandlerParser.parseBillHandlerPolicy(content
811 .getAttributeValue("policy"));
812 } catch (Exception exception)
813 {
814 {
815 Logger.severe(HandlerParser.class, "parseBillHandler",
816 exception);
817 }
818 }
819
820 Element paymentDelayElement = content.getChild("paymentDelay");
821 double paymentDelay = HandlerParser.parseHandlingTime(
822 paymentDelayElement, actor);
823
824 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
825 double maximumTimeOut = HandlerParser.parseHandlingTime(
826 maximumTimeOutElement, actor);
827
828 try
829 {
830 BillTimeOutHandler handler = new BillTimeOutHandler(actor, actor
831 .getBankAccount(), billHandlerPolicy, new DistConstant(
832 actor.getSimulator().getReplication().getStream("default"),
833 paymentDelay), maximumTimeOut);
834 actor.addContentHandler(Bill.class, handler);
835 Logger.info(HandlerParser.class, "parseBillTimeOutHandler",
836 "BillTimeOutHandler added to: " + actor.getName());
837 } catch (RemoteException remoteException)
838 {
839 Logger.severe(HandlerParser.class, "parseBillHandler",
840 remoteException);
841 }
842 }
843
844 /***
845 * parses the element and adds an interactive bill handler
846 *
847 * @param actor the actor to add an interactive bill handler to
848 */
849 private static void parseInteractiveBillHandler(final SupplyChainActor actor)
850 {
851 InteractiveBillHandler handler = new InteractiveBillHandler(actor);
852 actor.addContentHandler(Bill.class, handler);
853 Logger.info(HandlerParser.class, "parseInteractiveBillHandler",
854 "InteractiveBillHandler added to: " + actor.getName());
855 }
856
857 /***
858 * parses the element and adds an interactive bill time out handler
859 *
860 * @param actor the actor to add an interactive bill time out handler to
861 * @param content the element containing the data for the handler
862 */
863 private static void parseInteractiveBillTimeOutHandler(
864 final SupplyChainActor actor, final Element content)
865 {
866 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
867 double maximumTimeOut = HandlerParser.parseHandlingTime(
868 maximumTimeOutElement, actor);
869
870 InteractiveBillTimeOutHandler handler = new InteractiveBillTimeOutHandler(
871 actor, maximumTimeOut);
872 actor.addContentHandler(Bill.class, handler);
873 Logger.info(HandlerParser.class, "parseInteractiveBillTimeOutHandler",
874 "InteractiveBillTimeOutHandler added to: " + actor.getName());
875 }
876
877 /***
878 * parses the element and adds a shipment handler stock to the trader
879 *
880 * @param trader the trader to add the shipment handler to
881 */
882 private static void parseShipmentHandlerStock(final Trader trader)
883 {
884 ShipmentHandlerStock handler = new ShipmentHandlerStock(trader, trader
885 .getStock());
886 trader.addContentHandler(Shipment.class, handler);
887 Logger.info(HandlerParser.class, "parseShipmentHandlerStock",
888 "ShipmentHandlerStock added to: " + trader.getName());
889 }
890
891 /***
892 * parses the element and adds a shipment fine handler stock to the trader
893 *
894 * @param trader the trader to add the shipment fine handler to
895 * @param content the element containing the data for the handler
896 */
897 private static void parseShipmentFineHandlerStock(final Trader trader,
898 final Element content)
899 {
900 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
901 double maximumTimeOut = HandlerParser.parseHandlingTime(
902 maximumTimeOutElement, trader);
903
904 double fineMarginPerDay = new Double(content
905 .getAttributeValue("fineMarginPerDay")).doubleValue();
906 double fixedFinePerDay = new Double(content
907 .getAttributeValue("fixedFinePerDay")).doubleValue();
908
909 ShipmentFineHandlerStock handler = new ShipmentFineHandlerStock(trader,
910 trader.getStock(), maximumTimeOut, fineMarginPerDay,
911 fixedFinePerDay);
912 trader.addContentHandler(Shipment.class, handler);
913 Logger.info(HandlerParser.class, "parseShipmentFineHandlerStock",
914 "ShipmentFineHandlerStock added to: " + trader.getName());
915 }
916
917 /***
918 * parses the element and adds a shipment handler consume to the trader
919 *
920 * @param actor the trader to add the shipment handler to
921 */
922 private static void parseShipmentHandlerConsume(final SupplyChainActor actor)
923 {
924 ShipmentHandlerConsume handler = new ShipmentHandlerConsume(actor);
925 actor.addContentHandler(Shipment.class, handler);
926 Logger.info(HandlerParser.class, "parseShipmentHandlerConsume",
927 "ShipmentHandlerConsume added to: " + actor.getName());
928 }
929
930 /***
931 * parses the element and adds a shipment fine handler consume to the trader
932 *
933 * @param actor the actor to add the shipment fine handler consume to
934 * @param content the element containing the data for the handler
935 */
936 private static void parseShipmentFineHandlerConsume(
937 final SupplyChainActor actor, final Element content)
938 {
939 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
940 double maximumTimeOut = HandlerParser.parseHandlingTime(
941 maximumTimeOutElement, actor);
942
943 double fineMarginPerDay = new Double(content
944 .getAttributeValue("fineMarginPerDay")).doubleValue();
945 double fixedFinePerDay = new Double(content
946 .getAttributeValue("fixedFinePerDay")).doubleValue();
947
948 ShipmentFineHandlerConsume handler = new ShipmentFineHandlerConsume(
949 actor, maximumTimeOut, fineMarginPerDay, fixedFinePerDay);
950 actor.addContentHandler(Shipment.class, handler);
951 Logger.info(HandlerParser.class, "parseShipmentFineHandlerConsume",
952 "ShipmentFineHandlerConsume added to: " + actor.getName());
953 }
954
955 /***
956 * parses the element and adds an PCShop request for quote handler to the
957 * actor
958 *
959 * @param trader the trader to add the PCShop request for quote handler to
960 * @param content the element containing the data for the handler
961 */
962 private static void parsePCShopRequestForQuoteHandler(final Trader trader,
963 final Element content)
964 {
965 Product[] products = null;
966 DistTriangularGetters[] priceDistributions = null;
967 DistContinuous handlingTimeDistribution = null;
968 DistContinuous delayTimeDistribution = null;
969
970 if (content.getChild("products") != null)
971 {
972 try
973 {
974 products = HandlerParser.parseProduct(content
975 .getChild("products"));
976 priceDistributions = HandlerParser.parsePriceDistribution(
977 content.getChild("products"), trader);
978 } catch (Exception exception)
979 {
980 Logger.severe(HandlerParser.class,
981 "parsePCShopRequestForQuoteHandler", exception);
982 }
983 }
984 if (content.getChild("handling_time_in_days") != null)
985 {
986 handlingTimeDistribution = HandlerParser.getDistContinuous(
987 ((Element) content.getChild("handling_time_in_days")
988 .getChildren().get(0)), true, trader);
989 }
990 if (content.getChild("delay_time_in_days") != null)
991 {
992 delayTimeDistribution = HandlerParser.getDistContinuous(
993 ((Element) content.getChild("delay_time_in_days")
994 .getChildren().get(0)), true, trader);
995 }
996
997 PCShopRequestForQuoteHandler handler = new PCShopRequestForQuoteHandler(
998 trader, handlingTimeDistribution, products, priceDistributions,
999 delayTimeDistribution);
1000 trader.addContentHandler(RequestForQuote.class, handler);
1001 Logger.info(HandlerParser.class, "parsePCShopRequestForQuoteHandler",
1002 "PCShopRequestForQuoteHandler added to: " + trader.getName());
1003 }
1004
1005 /***
1006 * parses the element and adds an interactive request for quote handler
1007 *
1008 * @param actor the actor to add the interactive request for quote handler
1009 * to
1010 */
1011 private static void parseInteractiveRequestForQuoteHandler(
1012 final SupplyChainActor actor)
1013 {
1014 InteractiveRequestForQuoteHandler handler = new InteractiveRequestForQuoteHandler(
1015 actor);
1016 actor.addContentHandler(RequestForQuote.class, handler);
1017 Logger.info(HandlerParser.class,
1018 "parseInteractiveRequestForQuoteHandler",
1019 "InteractiveRequestForQuoteHandler added to: "
1020 + actor.getName());
1021 }
1022
1023 /***
1024 * parses the element and adds an interactive quote handler
1025 *
1026 * @param pcShop the pcshop to add the handler to
1027 */
1028 private static void parseInteractiveQuoteHandler(
1029 final GameDistributor pcShop)
1030 {
1031
1032 InteractiveQuoteHandler handler = new InteractiveQuoteHandler(pcShop);
1033 pcShop.setInteractiveQuoteHandler(handler);
1034 Logger.info(HandlerParser.class, "parseInteractiveQuoteHandler",
1035 "InteractiveQuoteHandler added to: " + pcShop.getName());
1036 }
1037
1038 /***
1039 * parses the element and adds an interactive order handler stock
1040 *
1041 * @param trader the trader to add an interactive order handler stock to
1042 */
1043 private static void parseInteractiveOrderHandlerStock(final Trader trader)
1044 {
1045 InteractiveOrderHandlerStock handler = new InteractiveOrderHandlerStock(
1046 trader, trader.getStock());
1047 trader.addContentHandler(Order.class, handler);
1048 Logger.info(HandlerParser.class, "parseInteractiveOrderHandlerStock",
1049 "InteractiveOrderHandlerStock added to: " + trader.getName());
1050 }
1051
1052 /***
1053 * parses the element and adds an interactive order confirmation fine
1054 * handler
1055 *
1056 * @param actor the actor to add an interactive order confirmation fine
1057 * handler to
1058 * @param content the element containing the data for the handler
1059 */
1060 private static void parseInteractiveOrderConfirmationFineHandler(
1061 final SupplyChainActor actor, final Element content)
1062 {
1063 Element maximumTimeOutElement = content.getChild("maximumTimeOut");
1064 double maximumTimeOut = HandlerParser.parseHandlingTime(
1065 maximumTimeOutElement, actor);
1066
1067 double fineMargin = new Double(content.getAttributeValue("fineMargin"))
1068 .doubleValue();
1069 double fixedFine = new Double(content.getAttributeValue("fixedFine"))
1070 .doubleValue();
1071
1072 InteractiveOrderConfirmationFineHandler handler = new InteractiveOrderConfirmationFineHandler(
1073 actor, maximumTimeOut, fineMargin, fixedFine);
1074 actor.addContentHandler(OrderConfirmation.class, handler);
1075 Logger.info(HandlerParser.class,
1076 "parseInteractiveOrderConfirmationFineHandler",
1077 "InteractiveOrderConfirmationFineHandler added to: "
1078 + actor.getName());
1079 }
1080
1081 /***
1082 * parses the element and adds an interactive order confirmation fine
1083 * handler
1084 *
1085 * @param actor the actor to add an interactive order confirmation fine
1086 * handler to
1087 */
1088 private static void parseInteractiveInternalDemandHandler(
1089 final SupplyChainActor actor)
1090 {
1091 InteractiveInternalDemandHandler handler = new InteractiveInternalDemandHandler(
1092 actor);
1093 actor.addContentHandler(InternalDemand.class, handler);
1094 Logger
1095 .info(HandlerParser.class,
1096 "parseInteractiveInternalDemandHandler",
1097 "InteractiveInternalDemandHandler added to: "
1098 + actor.getName());
1099 }
1100
1101 /***
1102 * parses a transport mode
1103 *
1104 * @param name the name
1105 * @return TransportMode result
1106 * @throws Exception on failure
1107 */
1108 private static TransportMode parseTransportMode(final String name)
1109 throws Exception
1110 {
1111 if (name.equals("PLANE"))
1112 {
1113 return TransportMode.PLANE;
1114 }
1115 throw new Exception("parseTransportMode.. unknown argument: " + name);
1116 }
1117
1118 /***
1119 * parses a handling time element
1120 *
1121 * @param element the element to get the handling time from
1122 * @param actor the actor
1123 * @return returns the handling time as a double
1124 */
1125 private static double parseHandlingTime(final Element element,
1126 final ActorInterface actor)
1127 {
1128 Namespace space = element.getNamespace();
1129
1130 double value = new Double(element.getAttributeValue("value", space))
1131 .doubleValue();
1132 String timeUnit = element.getAttributeValue("timeUnit");
1133 try
1134 {
1135 return value * HandlerParser.parseTimeUnit(timeUnit, actor);
1136 } catch (Exception exception)
1137 {
1138 Logger.severe(HandlerParser.class, "parseHandlingTime", exception);
1139 }
1140 return Double.NaN;
1141 }
1142
1143 /***
1144 * parses a time unit
1145 *
1146 * @param name the name of the unit
1147 * @param actor the actor to get the simulator from
1148 * @return returns a double representing the time unit in simulator time
1149 * units
1150 * @throws Exception thrown in case of an unknown time unit name
1151 */
1152 private static double parseTimeUnit(final String name,
1153 final ActorInterface actor) throws Exception
1154 {
1155 if (name.equals("MILLISECOND"))
1156 {
1157 return TimeUnit.convert(1, TimeUnitInterface.MILLISECOND, actor
1158 .getSimulator());
1159 }
1160 if (name.equals("SECOND"))
1161 {
1162 return TimeUnit.convert(1, TimeUnitInterface.SECOND, actor
1163 .getSimulator());
1164 }
1165 if (name.equals("MINUTE"))
1166 {
1167 return TimeUnit.convert(1, TimeUnitInterface.MINUTE, actor
1168 .getSimulator());
1169 }
1170 if (name.equals("HOUR"))
1171 {
1172 return TimeUnit.convert(1, TimeUnitInterface.HOUR, actor
1173 .getSimulator());
1174 }
1175 if (name.equals("DAY"))
1176 {
1177 return TimeUnit.convert(1, TimeUnitInterface.DAY, actor
1178 .getSimulator());
1179 }
1180 if (name.equals("WEEK"))
1181 {
1182 return TimeUnit.convert(1, TimeUnitInterface.WEEK, actor
1183 .getSimulator());
1184 }
1185 throw new Exception("parseTimeUnit.. unknown argument: " + name);
1186 }
1187
1188 /***
1189 * parses a quote handler comparator
1190 *
1191 * @param name the name of the comparator
1192 * @return returns a quote handler comparator
1193 * @throws Exception thrown in case of an unknown comparator name
1194 */
1195 private static int parseQuoteHandlerComparator(final String name)
1196 throws Exception
1197 {
1198 if (name.equals("SORT_DATE_DISTANCE_PRICE"))
1199 {
1200 return QuoteHandler.SORT_DATE_DISTANCE_PRICE;
1201 }
1202 if (name.equals("SORT_DATE_PRICE_DISTANCE"))
1203 {
1204 return QuoteHandler.SORT_DATE_PRICE_DISTANCE;
1205 }
1206 if (name.equals("SORT_DISTANCE_DATE_PRICE"))
1207 {
1208 return QuoteHandler.SORT_DISTANCE_DATE_PRICE;
1209 }
1210 if (name.equals("SORT_DISTANCE_PRICE_DATE"))
1211 {
1212 return QuoteHandler.SORT_DISTANCE_PRICE_DATE;
1213 }
1214 if (name.equals("SORT_PRICE_DATE_DISTANCE"))
1215 {
1216 return QuoteHandler.SORT_PRICE_DATE_DISTANCE;
1217 }
1218 if (name.equals("SORT_PRICE_DISTANCE_DATE"))
1219 {
1220 return QuoteHandler.SORT_PRICE_DISTANCE_DATE;
1221 }
1222 throw new Exception("parseQuoteHandlerComparator.. unknown argument: "
1223 + name);
1224 }
1225
1226 /***
1227 * parses a bill handler policy
1228 *
1229 * @param name the name of the policy
1230 * @return returns a bill handler policy
1231 * @throws Exception thrown in case of an unknown policy name
1232 */
1233 private static int parseBillHandlerPolicy(final String name)
1234 throws Exception
1235 {
1236 if (name.equals("PAYMENT_EARLY"))
1237 {
1238 return BillHandler.PAYMENT_EARLY;
1239 }
1240 if (name.equals("PAYMENT_IMMEDIATE"))
1241 {
1242 return BillHandler.PAYMENT_IMMEDIATE;
1243 }
1244 if (name.equals("PAYMENT_LATE"))
1245 {
1246 return BillHandler.PAYMENT_LATE;
1247 }
1248 if (name.equals("PAYMENT_ON_TIME"))
1249 {
1250 return BillHandler.PAYMENT_ON_TIME;
1251 }
1252 throw new Exception("parseBillHandlerPolicy.. unknown argument: "
1253 + name);
1254 }
1255
1256 /***
1257 * Parses an element representing a list of products
1258 *
1259 * @param element the element to parse
1260 * @return returns an array with products
1261 * @throws Exception thrown in case of an unknown name
1262 */
1263 private static Product[] parseProduct(final Element element)
1264 throws Exception
1265 {
1266 List products = element.getChildren();
1267 List result = new ArrayList();
1268 for (int i = 0; i < products.size(); i++)
1269 {
1270 Element product = (Element) products.get(i);
1271 Namespace space = element.getNamespace();
1272 String name = (product.getAttributeValue("name", space));
1273 result.add(Products.getProduct(name));
1274 }
1275 return (Product[]) result.toArray(new Product[result.size()]);
1276 }
1277
1278 /***
1279 * Parses an element representing a list of products
1280 *
1281 * @param element the element to parse
1282 * @param actor the actor
1283 * @return returns an array with products
1284 * @throws Exception thrown in case of an unknown name
1285 */
1286 private static DistTriangularGetters[] parsePriceDistribution(
1287 final Element element, final ActorInterface actor) throws Exception
1288 {
1289 StreamInterface stream = actor.getSimulator().getReplication()
1290 .getStream("default");
1291
1292 List products = element.getChildren();
1293 List result = new ArrayList();
1294 for (int i = 0; i < products.size(); i++)
1295 {
1296 Element product = (Element) products.get(i);
1297 Namespace space = element.getNamespace();
1298 if (product.getChild("price_function", space) != null)
1299 {
1300
1301 Element distributionElement = product.getChild(
1302 "price_function", space);
1303 if (distributionElement.getChild("triangular", space) != null)
1304 {
1305 Element triangularElement = distributionElement.getChild(
1306 "triangular", space);
1307
1308 double a = new Double(triangularElement.getAttributeValue(
1309 "a", space)).doubleValue();
1310 double b = new Double(triangularElement.getAttributeValue(
1311 "b", space)).doubleValue();
1312 double c = new Double(triangularElement.getAttributeValue(
1313 "c", space)).doubleValue();
1314
1315 if (!(a < b && b < c))
1316 {
1317 System.err
1318 .println("HandlerParser: parsePriceDistribution: trader:"
1319 + actor.getName()
1320 + " a: "
1321 + a
1322 + " b: "
1323 + b + " c: " + c);
1324 }
1325
1326 result.add(new DistTriangularGetters(stream, a, b, c));
1327 }
1328 }
1329 }
1330 return (DistTriangularGetters[]) result
1331 .toArray(new DistTriangularGetters[result.size()]);
1332 }
1333
1334 /***
1335 * Method getDistContinuous returns an initialiazed dist continuous function
1336 *
1337 * @param element the element
1338 * @param time the time
1339 * @param actor the actor
1340 * @return Returns a dist continuous function
1341 */
1342 private static DistContinuous getDistContinuous(final Element element,
1343 final boolean time, final ActorInterface actor)
1344 {
1345 try
1346 {
1347 Namespace space = element.getNamespace();
1348 StreamInterface stream = actor.getSimulator().getReplication()
1349 .getStream("default");
1350 double day = TimeUnit.convert(1.0, TimeUnitInterface.DAY, actor
1351 .getSimulator());
1352 if (element.getName().equalsIgnoreCase("triangular"))
1353 {
1354 double a = new Double(element.getAttributeValue("a", space))
1355 .doubleValue();
1356 double b = new Double(element.getAttributeValue("b", space))
1357 .doubleValue();
1358 double c = new Double(element.getAttributeValue("c", space))
1359 .doubleValue();
1360 if (!(a < b && b < c))
1361 {
1362 System.err.println("Parsing Manufacturer: a: " + a + " b: "
1363 + b + " c: " + c);
1364 }
1365
1366 if (time)
1367 {
1368 return new DistTriangular(stream, a * day, b * day, c * day);
1369 }
1370 return new DistTriangular(stream, a, b, c);
1371 }
1372 if (element.getName().equalsIgnoreCase("normal"))
1373 {
1374 double mean = new Double(element.getAttributeValue("mean",
1375 space)).doubleValue();
1376 double stdev = new Double(element.getAttributeValue("stdev",
1377 space)).doubleValue();
1378 if (time)
1379 {
1380 return new DistNormal(stream, mean * day, stdev * day);
1381 }
1382 return new DistNormal(stream, mean, stdev);
1383 }
1384 if (element.getName().equalsIgnoreCase("exponential"))
1385 {
1386 double lambda = new Double(element.getAttributeValue("lambda",
1387 space)).doubleValue();
1388 if (time)
1389 {
1390 return new DistExponential(stream, lambda * day);
1391 }
1392 return new DistExponential(stream, lambda);
1393 }
1394 if (element.getName().equalsIgnoreCase("constant"))
1395 {
1396 double c = new Double(element.getAttributeValue("c", space))
1397 .doubleValue();
1398 if (time)
1399 {
1400 return new DistConstant(stream, c * day);
1401 }
1402 return new DistConstant(stream, c);
1403 }
1404 throw new IllegalArgumentException(
1405 "getDistContinuous.. unknown argument: "
1406 + element.getName());
1407 } catch (Exception exception)
1408 {
1409 Logger.severe(HandlerParser.class, "getDistConstant", exception);
1410 return null;
1411 }
1412 }
1413
1414 /***
1415 * Method getProductionService returns an initialiazed production service
1416 *
1417 * @param element the element
1418 * @param trader the trader
1419 * @return Returns a production service
1420 */
1421 private static nl.tudelft.simulation.supplychain.production.ProductionService getProductionService(
1422 final Element element, final Trader trader)
1423 {
1424 try
1425 {
1426 Namespace space = element.getNamespace();
1427 Product product = null;
1428 StreamInterface stream = trader.getSimulator().getReplication()
1429 .getStream("default");
1430 if (element.getName().equalsIgnoreCase("delayproduction"))
1431 {
1432 product = Products.getProduct(element.getAttributeValue(
1433 "productName", space));
1434 DistContinuous distContinuous = new DistConstant(stream,
1435 HandlerParser.parseHandlingTime(element
1436 .getChild("productionTime"), trader));
1437 boolean fixedTime = new Boolean(element.getAttributeValue(
1438 "fixedTime", space)).booleanValue();
1439 boolean greedy = new Boolean(element.getAttributeValue(
1440 "greedy", space)).booleanValue();
1441 double profitMargin = new Double(element.getAttributeValue(
1442 "profitMargin", space)).doubleValue();
1443 if (HandlerParser.DEBUG)
1444 {
1445 System.out
1446 .println("DEBUG -- HandlerParser: getProductionService: created delayproduction service: "
1447 + "\nwith product: "
1448 + product
1449 + "\nDistConstant: "
1450 + distContinuous
1451 + "\nfixedTime: "
1452 + fixedTime
1453 + "\ngreedy: "
1454 + greedy
1455 + "\nprofitMargin: " + profitMargin);
1456
1457 }
1458
1459 return new GameDelayProductionService(trader, trader.getStock(),
1460 product, distContinuous, fixedTime, greedy,
1461 profitMargin);
1462 }
1463 throw new IllegalArgumentException(
1464 "getProductionService.. unknown argument: "
1465 + element.getName());
1466 } catch (Exception exception)
1467 {
1468 Logger.severe(HandlerParser.class, "getDistConstant", exception);
1469 exception.printStackTrace();
1470 return null;
1471 }
1472 }
1473 }