1   /*
2    * @(#) TestExperiment.java Sep 4, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.simulators;
11  
12  import java.util.HashMap;
13  import java.util.Map;
14  
15  import nl.tudelft.simulation.dsol.experiment.Experiment;
16  import nl.tudelft.simulation.dsol.experiment.Replication;
17  import nl.tudelft.simulation.dsol.experiment.RunControl;
18  import nl.tudelft.simulation.dsol.experiment.TimeUnitInterface;
19  import nl.tudelft.simulation.dsol.experiment.Treatment;
20  import nl.tudelft.simulation.jstats.streams.Java2Random;
21  
22  /***
23   * A TestExperiment <br>
24   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25   * University of Technology </a>, the Netherlands. <br>
26   * See for project information <a
27   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29   * License (GPL) </a>, no warranty <br>
30   * 
31   * @version 2.0 21.09.2003 <br>
32   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33   *         Jacobs </a>, <a
34   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
35   *         Verbraeck </a>
36   */
37  public final class TestExperiment extends Experiment
38  {
39  	/***
40  	 * STARTTIME defines the starting time for the experiment in millisec since
41  	 * 1970
42  	 */
43  	public static final long STARTTIME = 0;
44  
45  	/*** TIMEUNIT refers to the time units of the experiment */
46  	public static final TimeUnitInterface TIMEUNIT = TimeUnitInterface.UNIT;
47  
48  	/*** RUNLENGTH is the runLength for this experiment */
49  	public static final double RUNLENGTH = 100;
50  
51  	/*** WARMUP period defines the warmup period for the experiment */
52  	public static final double WARMUP = 10;
53  
54  	/*** SEED is the seed value for the DEFAULT stream */
55  	public static final long SEED = 42;
56  
57  	/*** TIMESTEP is the timeStep to be used for the DESS formalism */
58  	public static final double TIMESTEP = 0.01;
59  
60  	/***
61  	 * constructs a new TestExperiment
62  	 */
63  	private TestExperiment()
64  	{
65  		super();
66  		//unreachable code
67  	}
68  
69  	/***
70  	 * creates a new TestExperiment
71  	 * 
72  	 * @return Experiment
73  	 */
74  	public static Experiment createExperiment()
75  	{
76  		Experiment experiment = new Experiment();
77  		experiment.setTreatments(TestExperiment.createTreatments(experiment));
78  		experiment.setProperty("TIMESTEP", new Double(TIMESTEP).toString());
79  		return experiment;
80  	}
81  
82  	/***
83  	 * creates the Treatments for this experiment
84  	 * 
85  	 * @param experiment the parent
86  	 * @return Treatment[] the result
87  	 */
88  	public static Treatment[] createTreatments(final Experiment experiment)
89  	{
90  		Treatment[] result = new Treatment[1];
91  		result[0] = new Treatment(experiment, 0);
92  
93  		result[0].setStartTime(STARTTIME);
94  		result[0].setTimeUnit(TIMEUNIT);
95  		result[0].setRunControl(TestExperiment.createRunControl(result[0]));
96  		return result;
97  	}
98  
99  	/***
100 	 * creates a RunControl for the test Excperiment
101 	 * 
102 	 * @param treatment the treatment
103 	 * @return RunControl the runControl of the TestExperiment
104 	 */
105 	public static RunControl createRunControl(final Treatment treatment)
106 	{
107 		RunControl result = new RunControl(treatment);
108 		result.setRunLength(RUNLENGTH);
109 		result.setWarmupPeriod(WARMUP);
110 		result.setReplications(TestExperiment.createReplications(result));
111 		return result;
112 	}
113 
114 	/***
115 	 * creates the replications for the test experiment
116 	 * 
117 	 * @param runControl the parent
118 	 * @return Replication[] result
119 	 */
120 	public static Replication[] createReplications(final RunControl runControl)
121 	{
122 		Replication[] result = new Replication[1];
123 		result[0] = new Replication(runControl, 0);
124 
125 		Map streams = new HashMap();
126 		streams.put("DEFAULT", new Java2Random(SEED));
127 		result[0].setStreams(streams);
128 		return result;
129 	}
130 }