View Javadoc

1   /*
2    * @(#) C1.java Apr 20, 2004
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.sne.c1;
11  
12  import java.rmi.RemoteException;
13  
14  import nl.tudelft.simulation.dsol.ModelInterface;
15  import nl.tudelft.simulation.dsol.SimRuntimeException;
16  import nl.tudelft.simulation.dsol.formalisms.dess.DifferentialEquationInterface;
17  import nl.tudelft.simulation.dsol.simulators.DEVDESSSimulatorInterface;
18  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
19  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20  import nl.tudelft.simulation.dsol.statistics.Persistent;
21  import nl.tudelft.simulation.dsol.statistics.charts.XYChart;
22  import nl.tudelft.simulation.event.EventInterface;
23  import nl.tudelft.simulation.jstats.ode.integrators.NumericalIntegrator;
24  
25  /***
26   * The C1 Test Model. see for detailed specification <a
27   * href="http://www.argesim.org/comparisons/c1/definition/c1def.html">
28   * http://www.argesim.org/comparisons/c1/definition/c1def.html </a>
29   * <p>
30   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
31   * University of Technology </a>, the Netherlands. <br>
32   * See for project information <a
33   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
34   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
35   * License (GPL) </a>, no warranty <br>
36   * 
37   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
38   *         Jacobs </a>
39   * @version 1.2 Apr 20, 2004
40   * @since 1.4
41   */
42  public class C1TaskC implements ModelInterface
43  {
44  	/*** the chart */
45  	private XYChart[] chart = null;
46  
47  	/***
48  	 * @see nl.tudelft.simulation.dsol.ModelInterface
49  	 *      #constructModel(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
50  	 */
51  	public void constructModel(SimulatorInterface simulator)
52  			throws RemoteException, SimRuntimeException
53  	{
54  		if (this.chart == null)
55  		{
56  			this.chart = new XYChart[3];
57  			this.chart[0] = new XYChart(
58  					simulator,
59  					"F-center value",
60  					nl.tudelft.simulation.jstats.charts.xy.XYChart.XLOGARITHMIC_YLOGARITHMIC);
61  			this.chart[1] = new XYChart(
62  					simulator,
63  					"R-center value",
64  					nl.tudelft.simulation.jstats.charts.xy.XYChart.XLOGARITHMIC_YLOGARITHMIC);
65  			this.chart[2] = new XYChart(
66  					simulator,
67  					"M-center value",
68  					nl.tudelft.simulation.jstats.charts.xy.XYChart.XLOGARITHMIC_YLOGARITHMIC);
69  		}
70  		DEVDESSSimulatorInterface dessSimulator = (DEVDESSSimulatorInterface) simulator;
71  		dessSimulator.setTimeStep(0.00001);
72  		FCenter fCenter = new FCenter(dessSimulator, 0.001,
73  				NumericalIntegrator.ADAMS);
74  		this.createChart(dessSimulator, fCenter, 0, "R");
75  		this.createChart(dessSimulator, fCenter, 1, "M");
76  		this.createChart(dessSimulator, fCenter, 2, "F");
77  	}
78  
79  	/***
80  	 * creates a chart
81  	 * 
82  	 * @param simulator the simulator to use.
83  	 * @param fCenter the fCenter to be used
84  	 * @param index the index
85  	 * @param name the name
86  	 * @throws SimRuntimeException on failure
87  	 * @throws RemoteException on failure
88  	 */
89  	private void createChart(DEVSSimulatorInterface simulator, FCenter fCenter,
90  			int index, String name) throws SimRuntimeException, RemoteException
91  	{
92  		AggregatingPersistent persistent = new AggregatingPersistent(name
93  				+ "Value (pt=" + fCenter.getP() + ")", simulator);
94  		fCenter.addListener(persistent,
95  				DifferentialEquationInterface.VALUE_CHANGED_EVENT[index]);
96  		simulator.scheduleEvent(simulator.getReplication().getRunControl()
97  				.getRunLength(), this, fCenter, "removeListener", new Object[]{
98  				persistent,
99  				DifferentialEquationInterface.VALUE_CHANGED_EVENT[index]});
100 		this.chart[index].add(persistent);
101 	}
102 
103 	/***
104 	 * an aggregated persistent.
105 	 */
106 	private class AggregatingPersistent extends Persistent
107 	{
108 		/*** the number */
109 		private int number = 0;
110 
111 		/***
112 		 * constructs a new AggregatingPersistent
113 		 * 
114 		 * @param description
115 		 * @param simulator
116 		 * @throws RemoteException
117 		 */
118 		public AggregatingPersistent(String description,
119 				SimulatorInterface simulator) throws RemoteException
120 		{
121 			super(description, simulator);
122 		}
123 
124 		/***
125 		 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
126 		 */
127 		public void notify(EventInterface event)
128 		{
129 			this.number++;
130 			if (event.getSource() instanceof SimulatorInterface
131 					|| this.number % 1000 == 0)
132 			{
133 				super.notify(event);
134 			}
135 		}
136 	}
137 }