1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.tutorial.section45;
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.experiment.Experiment;
17 import nl.tudelft.simulation.dsol.formalisms.devs.SimEvent;
18 import nl.tudelft.simulation.dsol.simulators.DEVSSimulator;
19 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
20 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
21 import nl.tudelft.simulation.language.io.URLResource;
22 import nl.tudelft.simulation.xml.dsol.ExperimentParser;
23
24 /***
25 * A Model <br>
26 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl"> Delft
27 * University of Technology </a>, the Netherlands. <br>
28 * See for project information <a href="http://www.simulation.tudelft.nl">
29 * www.simulation.tudelft.nl </a> <br>
30 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31 * License (GPL) </a>, no warranty <br>
32 *
33 * @version 1.0 Jan 19, 2004 <br>
34 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
35 * Jacobs </a>
36 */
37 public class Model implements ModelInterface
38 {
39 /***
40 * constructs a new Model
41 *
42 */
43 public Model()
44 {
45 super();
46 }
47
48 /***
49 * @see nl.tudelft.simulation.dsol.ModelInterface
50 * #constructModel(nl.tudelft.simulation.dsol.simulators.SimulatorInterface)
51 */
52 public void constructModel(final SimulatorInterface simulator)
53 throws SimRuntimeException, RemoteException
54 {
55 DEVSSimulatorInterface devsSimulator = (DEVSSimulatorInterface) simulator;
56 Port port = new Port(devsSimulator);
57
58
59 this.scheduleBoatArrival(0, devsSimulator, port);
60 this.scheduleBoatArrival(1, devsSimulator, port);
61 this.scheduleBoatArrival(15, devsSimulator, port);
62 }
63
64 /***
65 * schedules the creation of a boat
66 *
67 * @param time the time when the boat should arrive
68 * @param simulator the simulator on which we schedule
69 * @param port the port
70 * @throws RemoteException on network failuer
71 * @throws SimRuntimeException on simulation exception
72 */
73 private void scheduleBoatArrival(final double time,
74 final DEVSSimulatorInterface simulator, final Port port)
75 throws RemoteException, SimRuntimeException
76 {
77 simulator.scheduleEvent(new SimEvent(time, this, Boat.class, "<init>",
78 new Object[]{simulator, port}));
79 }
80
81 /***
82 * commandline executes the model
83 *
84 * @param args the arguments to the commandline
85 */
86 public static void main(final String[] args)
87 {
88 try
89 {
90 Experiment experiment = ExperimentParser
91 .parseExperiment(URLResource
92 .getResource("/nl/tudelft/simulation/examples/dsol/port/experiment.xml"));
93 experiment.setSimulator(new DEVSSimulator());
94 experiment.start();
95 } catch (Exception exception)
96 {
97 exception.printStackTrace();
98 }
99 }
100 }