Package org.opentrafficsim.swing.script
Class AbstractSimulationScript
java.lang.Object
org.opentrafficsim.swing.script.AbstractSimulationScript
- All Implemented Interfaces:
EventListener,Checkable,EventListener
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
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSimulationScript(String name, String description) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTabs(OtsSimulatorInterface sim, OtsSimulationApplication<?> animation) Adds tabs to the animation.protected voidanimateNetwork(Network net, OtsAnimationPanel animationPanel) Creates animations for nodes, links and lanes.voidcheck()Returns the GTU colorers.Returns map of (non-default) GTU type markers.final RoadNetworkReturns the network.longgetSeed()Returns the seed.Returns the simulation time.final OtsSimulatorInterfaceReturns the simulator.Returns the start time.Returns the warm-up time.booleanReturns whether to autorun.voidprotected voidMethod that is called when the simulation has ended.protected voidsetAnimationToggles(OtsAnimationPanel animation) Sets the animation toggles.final voidsetGtuColorers(List<Colorer<? super Gtu>> colorers) Set GTU colorers.protected voidsetupDemo(OtsAnimationPanel animationPanel, RoadNetwork net) Method that is called when the animation has been created, to add components for a demo.protected abstract RoadNetworkSets up the simulation based on provided properties.final voidstart()Starts the simulation.
-
Constructor Details
-
AbstractSimulationScript
Constructor.- Parameters:
name- namedescription- description
-
-
Method Details
-
getSeed
public long getSeed()Returns the seed.- Returns:
- seed
-
getStartTime
Returns the start time.- Returns:
- start time
-
getWarmupTime
Returns the warm-up time.- Returns:
- warm-up time
-
getSimulationTime
Returns the simulation time.- Returns:
- simulation time
-
isAutorun
public boolean isAutorun()Returns whether to autorun.- Returns:
- whether to autorun
-
setGtuColorers
Set GTU colorers.- Parameters:
colorers- GTU colorers
-
getGtuColorers
Returns the GTU colorers.- Returns:
- returns the GTU colorers
-
getGtuMarkers
Returns map of (non-default) GTU type markers. The default implementation of this method returns an empty map.- Returns:
- map of GTU type markers
-
check
-
start
Starts the simulation.- Throws:
Exception- on any exception
-
notify
- Specified by:
notifyin interfaceEventListener
-
getSimulator
Returns the simulator.- Returns:
- simulator
-
getNetwork
Returns the network.- Returns:
- network
-
animateNetwork
Creates animations for nodes, links and lanes. This can be used if the network is not read from XML.- Parameters:
net- networkanimationPanel- animation panel
-
addTabs
Adds tabs to the animation. May be overridden.- Parameters:
sim- simulatoranimation- 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- animation panelnet- network
-
setAnimationToggles
Sets the animation toggles. May be overridden.- Parameters:
animation- animation to set the toggle on
-
setupSimulation
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- simulator- Returns:
- network
- Throws:
Exception- on any exception
-