Package org.opentrafficsim.swing.script
Class AbstractSimulationScript
- java.lang.Object
-
- org.opentrafficsim.swing.script.AbstractSimulationScript
-
- All Implemented Interfaces:
Serializable,EventListener,Checkable,EventListenerInterface
public abstract class AbstractSimulationScript extends Object implements EventListenerInterface, 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@Optionsand similar annotations. Default values of the properties in this abstract class can be overwritten by the sub-class usingCliUtil.changeDefaultValue().Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version 9 apr. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSimulationScript(String name, String description)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddTabs(org.opentrafficsim.core.dsol.OTSSimulatorInterface sim, OTSSimulationApplication<?> animation)Adds tabs to the animation.protected voidanimateNetwork(org.opentrafficsim.core.network.OTSNetwork net)Creates animations for nodes, links and lanes.voidcheck()org.opentrafficsim.core.animation.gtu.colorer.GTUColorergetGtuColorer()Returns the GTU colorer.OTSRoadNetworkgetNetwork()Returns the network.longgetSeed()Returns the seed.DurationgetSimulationTime()Returns the simulation time.org.opentrafficsim.core.dsol.OTSSimulatorInterfacegetSimulator()Returns the simulator.TimegetStartTime()Returns the start time.DurationgetWarmupTime()Returns the warm-up time.booleanisAutorun()Returns whether to autorun.voidnotify(EventInterface event)protected voidonSimulationEnd()Method that is called when the simulation has ended.protected voidsetAnimationToggles(OTSAnimationPanel animation)Sets the animation toggles.voidsetGtuColorer(org.opentrafficsim.core.animation.gtu.colorer.GTUColorer colorer)Set GTU colorer.protected voidsetupDemo(OTSAnimationPanel animationPanel, OTSRoadNetwork net)Method that is called when the animation has been created, to add components for a demo.protected abstract OTSRoadNetworksetupSimulation(org.opentrafficsim.core.dsol.OTSSimulatorInterface sim)Sets up the simulation based on provided properties.voidstart()Starts the simulation.
-
-
-
Method Detail
-
getSeed
public long getSeed()
Returns the seed.- Returns:
- long; seed
-
getStartTime
public Time getStartTime()
Returns the start time.- Returns:
- Time; start time
-
getWarmupTime
public Duration getWarmupTime()
Returns the warm-up time.- Returns:
- Duration; warm-up time
-
getSimulationTime
public Duration getSimulationTime()
Returns the simulation time.- Returns:
- Duration; simulation time
-
isAutorun
public boolean isAutorun()
Returns whether to autorun.- Returns:
- boolean; whether to autorun
-
setGtuColorer
public final void setGtuColorer(org.opentrafficsim.core.animation.gtu.colorer.GTUColorer colorer)
Set GTU colorer.- Parameters:
colorer- GTUColorer; GTU colorer
-
getGtuColorer
public final org.opentrafficsim.core.animation.gtu.colorer.GTUColorer getGtuColorer()
Returns the GTU colorer.- Returns:
- returns the GTU colorer
-
check
public void check() throws Exception
-
start
public final void start() throws ExceptionStarts the simulation.- Throws:
Exception- on any exception
-
notify
public void notify(EventInterface event) throws RemoteException
- Specified by:
notifyin interfaceEventListenerInterface- Throws:
RemoteException
-
getSimulator
public final org.opentrafficsim.core.dsol.OTSSimulatorInterface getSimulator()
Returns the simulator.- Returns:
- OTSSimulatorInterface; simulator
-
getNetwork
public final OTSRoadNetwork getNetwork()
Returns the network.- Returns:
- OTSNetwork; network
-
animateNetwork
protected void animateNetwork(org.opentrafficsim.core.network.OTSNetwork net)
Creates animations for nodes, links and lanes. This can be used if the network is not read from XML.- Parameters:
net- OTSNetwork; 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
protected void setupDemo(OTSAnimationPanel animationPanel, OTSRoadNetwork net)
Method that is called when the animation has been created, to add components for a demo.- Parameters:
animationPanel- OTSAnimationPanel; animation panelnet- OTSNetwork; network
-
setAnimationToggles
protected void setAnimationToggles(OTSAnimationPanel animation)
Sets the animation toggles. May be overridden.- Parameters:
animation- OTSAnimationPanel; animation to set the toggle on
-
setupSimulation
protected abstract OTSRoadNetwork 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:
- OTSNetwork; network
- Throws:
Exception- on any exception
-
-