View Javadoc

1   /*
2    * @(#)TestModel.java Mar 4, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  
14  package nl.tudelft.simulation.supplychain.test;
15  
16  import java.awt.Dimension;
17  import java.rmi.RemoteException;
18  import java.util.logging.Level;
19  
20  import javax.vecmath.Point3d;
21  
22  import nl.tudelft.simulation.dsol.ModelInterface;
23  import nl.tudelft.simulation.dsol.animation.D2.SingleImageRenderable;
24  import nl.tudelft.simulation.dsol.experiment.Experiment;
25  import nl.tudelft.simulation.dsol.simulators.AnimatorInterface;
26  import nl.tudelft.simulation.dsol.simulators.DEVSSimulator;
27  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
28  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
29  import nl.tudelft.simulation.language.d3.DirectedPoint;
30  import nl.tudelft.simulation.logger.Logger;
31  import nl.tudelft.simulation.supplychain.banking.Bank;
32  import nl.tudelft.simulation.supplychain.content.LeanContentStore;
33  import nl.tudelft.simulation.supplychain.product.Product;
34  import nl.tudelft.simulation.supplychain.product.Unit;
35  import nl.tudelft.simulation.supplychain.roles.Role;
36  import nl.tudelft.simulation.xml.dsol.ExperimentParser;
37  
38  /***
39   * The TestModel for the supplychain package.
40   * <p>
41   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
42   * Delft, the Netherlands. All rights reserved.
43   * 
44   * See for project information <a href="http://www.simulation.tudelft.nl/">
45   * www.simulation.tudelft.nl </a>.
46   * 
47   * The source code and binary code of this software is proprietary information
48   * of Delft University of Technology.
49   * 
50   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
51   *         Jacobs </a>, <a
52   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
53   *         Verbraeck </a>
54   * @version $$Revision: 1.4 $$ $$Date: 2005/05/18 00:27:27 $$
55   */
56  public class TestModel implements ModelInterface
57  {
58  	/*** the serial version uid */
59  	private static final long serialVersionUID = 12L;
60  
61  	/***
62  	 * constructs a new TestModel
63  	 */
64  	public TestModel()
65  	{
66  		super();
67  		// We don't do anything to prevent state-based replications.
68  	}
69  
70  	/***
71  	 * @see nl.tudelft.simulation.dsol.ModelInterface
72  	 *      #constructModel(SimulatorInterface)
73  	 */
74  	public void constructModel(final SimulatorInterface simulator)
75  			throws RemoteException
76  	{
77  		DEVSSimulatorInterface devsSimulator = (DEVSSimulatorInterface) simulator;
78  		if (devsSimulator instanceof AnimatorInterface)
79  		{
80  			// First we create some background. We set the zValue to
81  			// -Double.Min
82  			// value to ensure that it is actually drawn "below" our actors and
83  			// messages.
84  			new SingleImageRenderable(
85  					new DirectedPoint(0.0, 0.0, -Double.MIN_VALUE),
86  					new Dimension(1618, 716),
87  					devsSimulator,
88  					TestModel.class
89  							.getResource("/nl/tudelft/simulation/supplychain/images/worldmap.gif"));
90  		}
91  		// create the bank
92  		Bank ing = new Bank("ING", devsSimulator, new Point3d(0, 0, 0));
93  		ing.setAnnualInterestRateNeg(0.080);
94  		ing.setAnnualInterestRatePos(0.025);
95  		// create a product
96  		Product laptop = new Product("Laptop", Unit.PIECE, 1400.0, 6.5, 0.0);
97  		// create a manufacturer
98  		Dell dell = new Dell("Dell", devsSimulator, new Point3d(200, 200, 0),
99  				new Role[]{}, ing, 50000.0, laptop, 1000);
100 		dell.setContentStore(new LeanContentStore(dell, devsSimulator));
101 		// create a retailer
102 		PCShop pcShop = new PCShop("PCshop", devsSimulator, new Point3d(20,
103 				200, 0), new Role[]{}, ing, 50000.0, laptop, 10, dell);
104 		pcShop.setContentStore(new LeanContentStore(pcShop, devsSimulator));
105 		// create a customer
106 		Shell shell = new Shell("Shell", devsSimulator,
107 				new Point3d(100, 100, 0), ing, 1500000.0, laptop, pcShop);
108 		shell.setContentStore(new LeanContentStore(shell, devsSimulator));
109 	}
110 
111 	/***
112 	 * executes TestModel
113 	 * 
114 	 * @param args the commandline arguments
115 	 */
116 	public static void main(final String[] args)
117 	{
118 		Logger.setLogLevel(Level.WARNING);
119 		if (args.length != 0)
120 		{
121 			System.out
122 					.println("Usage: java nl.tudelft.simulation.supplychain.test.TestModel");
123 			System.exit(0);
124 		}
125 		try
126 		{
127 			// We parse the experiment
128 			Experiment experiment = ExperimentParser
129 					.parseExperiment(TestModel.class
130 							.getResource("/testmodel.xml"));
131 			// We make sure the experiment is reset
132 			DEVSSimulatorInterface simulator = new DEVSSimulator();
133 			experiment.setSimulator(simulator);
134 			experiment.setModel(new TestModel());
135 			experiment.start();
136 		} catch (Exception exception)
137 		{
138 			exception.printStackTrace();
139 		}
140 	}
141 
142 }