package nl.tudelft.simulation.dsol.tutorial.section45; import java.io.Serializable; import javax.naming.NamingException; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.experiment.ReplicationInterface; import nl.tudelft.simulation.dsol.experiment.SingleReplication; import nl.tudelft.simulation.dsol.model.AbstractDSOLModel; import nl.tudelft.simulation.dsol.model.DSOLModel; import nl.tudelft.simulation.dsol.simulators.DEVSSimulator; /** * A BoatModel. *

* Copyright (c) 2002-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @author Peter Jacobs */ public class BoatModel extends AbstractDSOLModel.TimeDouble { /** The default serial version UID for serializable classes. */ private static final long serialVersionUID = 1L; /** * constructs a new BoatModel. * @param simulator DEVSSimulator.TimeDouble; the simulator */ public BoatModel(final DEVSSimulator.TimeDouble simulator) { super(simulator); } /** {@inheritDoc} */ @Override public void constructModel() throws SimRuntimeException { Port port = new Port(this.simulator); // We schedule boat creation this.scheduleBoatArrival(0, port); this.scheduleBoatArrival(1, port); this.scheduleBoatArrival(15, port); } /** * schedules the creation of a boat. * @param time double; the time when the boat should arrive * @param port Port; the port * @throws SimRuntimeException on simulation exception */ private void scheduleBoatArrival(final double time, final Port port) throws SimRuntimeException { this.simulator.scheduleEventAbs(time, this, Boat.class, "", new Object[] {this.simulator, port}); } /** * command line executes the model. * @param args String[]; the arguments to the command line * @throws NamingException on Context error * @throws SimRuntimeException on simulation model construction error */ public static void main(final String[] args) throws NamingException, SimRuntimeException { DEVSSimulator.TimeDouble simulator = new DEVSSimulator.TimeDouble("BoatModel"); DSOLModel.TimeDouble model = new BoatModel(simulator); ReplicationInterface.TimeDouble replication = new SingleReplication.TimeDouble("rep1", 0.0, 0.0, 100.0); simulator.initialize(model, replication); simulator.start(); } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "BoatModel"; } }