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