Package org.opentrafficsim.swing.script
Class AbstractSimulationScript
java.lang.Object
org.opentrafficsim.swing.script.AbstractSimulationScript
- All Implemented Interfaces:
Serializable,Remote,EventListener,org.djutils.cli.Checkable,org.djutils.event.EventListener
public abstract class AbstractSimulationScript
extends Object
implements org.djutils.event.EventListener, org.djutils.cli.Checkable
Template for simulation script. This class allows the user to run a single visualized simulation, or to batch-run the same
model. Parameters can be given through the command-line using djutils-ext. Fields can be added to sub-classes using the
@Options and similar annotations. Default values of the properties in this abstract class can be overwritten by the
sub-class using CliUtil.changeDefaultValue().
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSimulationScript(String name, String description) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTabs(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim, OtsSimulationApplication<?> animation) Adds tabs to the animation.protected voidanimateNetwork(org.opentrafficsim.core.network.Network net) Creates animations for nodes, links and lanes.voidcheck()final GtuColorerReturns the GTU colorer.final RoadNetworkReturns the network.longgetSeed()Returns the seed.org.djunits.value.vdouble.scalar.DurationReturns the simulation time.final org.opentrafficsim.core.dsol.OtsSimulatorInterfaceReturns the simulator.org.djunits.value.vdouble.scalar.TimeReturns the start time.org.djunits.value.vdouble.scalar.DurationReturns the warm-up time.booleanReturns whether to autorun.voidnotify(org.djutils.event.Event event) protected voidMethod that is called when the simulation has ended.protected voidsetAnimationToggles(OtsAnimationPanel animation) Sets the animation toggles.final voidsetGtuColorer(GtuColorer colorer) Set GTU colorer.protected voidsetupDemo(OtsAnimationPanel animationPanel, RoadNetwork net) Method that is called when the animation has been created, to add components for a demo.protected abstract RoadNetworksetupSimulation(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim) Sets up the simulation based on provided properties.final voidstart()Starts the simulation.
-
Constructor Details
-
AbstractSimulationScript
Constructor.- Parameters:
name- String; namedescription- String; description
-
-
Method Details
-
getSeed
public long getSeed()Returns the seed.- Returns:
- long; seed
-
getStartTime
public org.djunits.value.vdouble.scalar.Time getStartTime()Returns the start time.- Returns:
- Time; start time
-
getWarmupTime
public org.djunits.value.vdouble.scalar.Duration getWarmupTime()Returns the warm-up time.- Returns:
- Duration; warm-up time
-
getSimulationTime
public org.djunits.value.vdouble.scalar.Duration getSimulationTime()Returns the simulation time.- Returns:
- Duration; simulation time
-
isAutorun
public boolean isAutorun()Returns whether to autorun.- Returns:
- boolean; whether to autorun
-
setGtuColorer
Set GTU colorer.- Parameters:
colorer- GtuColorer; GTU colorer
-
getGtuColorer
Returns the GTU colorer.- Returns:
- returns the GTU colorer
-
check
- Specified by:
checkin interfaceorg.djutils.cli.Checkable- Throws:
Exception
-
start
Starts the simulation.- Throws:
Exception- on any exception
-
notify
- Specified by:
notifyin interfaceorg.djutils.event.EventListener- Throws:
RemoteException
-
getSimulator
public final org.opentrafficsim.core.dsol.OtsSimulatorInterface getSimulator()Returns the simulator.- Returns:
- OtsSimulatorInterface; simulator
-
getNetwork
Returns the network.- Returns:
- Network; network
-
animateNetwork
protected void animateNetwork(org.opentrafficsim.core.network.Network net) Creates animations for nodes, links and lanes. This can be used if the network is not read from XML.- Parameters:
net- Network; network
-
addTabs
protected void addTabs(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim, OtsSimulationApplication<?> animation) Adds tabs to the animation. May be overridden.- Parameters:
sim- OtsSimulatorInterface; simulatoranimation- OtsSimulationApplication<?>; animation to add tabs to
-
onSimulationEnd
protected void onSimulationEnd()Method that is called when the simulation has ended. This can be used to store data. -
setupDemo
Method that is called when the animation has been created, to add components for a demo.- Parameters:
animationPanel- OtsAnimationPanel; animation panelnet- Network; network
-
setAnimationToggles
Sets the animation toggles. May be overridden.- Parameters:
animation- OtsAnimationPanel; animation to set the toggle on
-
setupSimulation
protected abstract RoadNetwork setupSimulation(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim) throws Exception Sets up the simulation based on provided properties. Properties can be obtained withgetProperty(). Setting up a simulation should at least create a network and some demand. Additionally this may setup traffic control, sampling, etc.- Parameters:
sim- OtsSimulatorInterface; simulator- Returns:
- Network; network
- Throws:
Exception- on any exception
-