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.SimulatorInterface;
19  import nl.tudelft.simulation.dsol.statistics.Persistent;
20  import nl.tudelft.simulation.dsol.statistics.charts.XYChart;
21  import nl.tudelft.simulation.event.EventInterface;
22  import nl.tudelft.simulation.jstats.ode.integrators.NumericalIntegrator;
23  
24  /***
25   * The C1 Test Model. see for detailed specification <a
26   * href="http://www.argesim.org/comparisons/c1/definition/c1def.html">
27   * http://www.argesim.org/comparisons/c1/definition/c1def.html </a>
28   * <p>
29   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
30   * University of Technology </a>, the Netherlands. <br>
31   * See for project information <a
32   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
33   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
34   * License (GPL) </a>, no warranty <br>
35   * 
36   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
37   *         Jacobs </a>
38   * @version 1.2 Apr 20, 2004
39   * @since 1.4
40   */
41  public class C1TaskB implements ModelInterface
42  {
43  	/*** the chart */
44  	private XYChart chart = null;
45  
46  	/***
47  	 * @see nl.tudelft.simulation.dsol.ModelInterface
48  	 *      #constructModel(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
49  	 */
50  	public void constructModel(SimulatorInterface simulator)
51  			throws RemoteException, SimRuntimeException
52  	{
53  		if (this.chart == null)
54  		{
55  			this.chart = new XYChart(
56  					simulator,
57  					"F-center value",
58  					nl.tudelft.simulation.jstats.charts.xy.XYChart.XLOGARITHMIC_YLOGARITHMIC);
59  		}
60  		DEVDESSSimulatorInterface dessSimulator = (DEVDESSSimulatorInterface) simulator;
61  		dessSimulator.setTimeStep(0.00001);
62  		FCenter fCenter = new FCenter(dessSimulator, 0.00001,
63  				NumericalIntegrator.ADAMS);
64  		AggregatingPersistent persistent = new AggregatingPersistent(
65  				"FValue (lf=" + fCenter.getLf() + ")", simulator);
66  		fCenter.addListener(persistent,
67  				DifferentialEquationInterface.VALUE_CHANGED_EVENT[2]);
68  		dessSimulator.scheduleEvent(simulator.getReplication().getRunControl()
69  				.getRunLength(), this, fCenter, "removeListener", new Object[]{
70  				persistent,
71  				DifferentialEquationInterface.VALUE_CHANGED_EVENT[2]});
72  		this.chart.add(persistent);
73  	}
74  
75  	/***
76  	 * an aggregated persistent.
77  	 */
78  	private class AggregatingPersistent extends Persistent
79  	{
80  		/*** the number */
81  		private int number = 0;
82  
83  		/***
84  		 * constructs a new AggregatingPersistent
85  		 * 
86  		 * @param description
87  		 * @param simulator
88  		 * @throws RemoteException
89  		 */
90  		public AggregatingPersistent(String description,
91  				SimulatorInterface simulator) throws RemoteException
92  		{
93  			super(description, simulator);
94  		}
95  
96  		/***
97  		 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
98  		 */
99  		public void notify(EventInterface event)
100 		{
101 			this.number++;
102 			if (event.getSource() instanceof SimulatorInterface
103 					|| this.number % 1000 == 0)
104 			{
105 				super.notify(event);
106 			}
107 		}
108 	}
109 }