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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addTabs(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim, OtsSimulationApplication<?> animation)
    Adds tabs to the animation.
    protected void
    animateNetwork(org.opentrafficsim.core.network.Network net, OtsAnimationPanel animationPanel)
    Creates animations for nodes, links and lanes.
    void
     
    Returns the GTU colorers.
    Map<org.opentrafficsim.core.gtu.GtuType,org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData.GtuMarker>
    Returns map of (non-default) GTU type markers.
    final org.opentrafficsim.road.network.RoadNetwork
    Returns the network.
    long
    Returns the seed.
    org.djunits.value.vdouble.scalar.Duration
    Returns the simulation time.
    final org.opentrafficsim.core.dsol.OtsSimulatorInterface
    Returns the simulator.
    org.djunits.value.vdouble.scalar.Time
    Returns the start time.
    org.djunits.value.vdouble.scalar.Duration
    Returns the warm-up time.
    boolean
    Returns whether to autorun.
    void
    notify(org.djutils.event.Event event)
     
    protected void
    Method that is called when the simulation has ended.
    protected void
    Sets the animation toggles.
    final void
    Set GTU colorers.
    protected void
    setupDemo(OtsAnimationPanel animationPanel, org.opentrafficsim.road.network.RoadNetwork net)
    Method that is called when the animation has been created, to add components for a demo.
    protected abstract org.opentrafficsim.road.network.RoadNetwork
    setupSimulation(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim)
    Sets up the simulation based on provided properties.
    final void
    Starts the simulation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractSimulationScript

      protected AbstractSimulationScript(String name, String description)
      Constructor.
      Parameters:
      name - name
      description - description
  • Method Details

    • getSeed

      public long getSeed()
      Returns the seed.
      Returns:
      seed
    • getStartTime

      public org.djunits.value.vdouble.scalar.Time getStartTime()
      Returns the start time.
      Returns:
      start time
    • getWarmupTime

      public org.djunits.value.vdouble.scalar.Duration getWarmupTime()
      Returns the warm-up time.
      Returns:
      warm-up time
    • getSimulationTime

      public org.djunits.value.vdouble.scalar.Duration getSimulationTime()
      Returns the simulation time.
      Returns:
      simulation time
    • isAutorun

      public boolean isAutorun()
      Returns whether to autorun.
      Returns:
      whether to autorun
    • setGtuColorers

      public final void setGtuColorers(List<GtuColorer> colorers)
      Set GTU colorers.
      Parameters:
      colorers - GTU colorers
    • getGtuColorers

      public final List<GtuColorer> getGtuColorers()
      Returns the GTU colorers.
      Returns:
      returns the GTU colorers
    • getGtuMarkers

      public Map<org.opentrafficsim.core.gtu.GtuType,org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData.GtuMarker> 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

      public void check() throws Exception
      Specified by:
      check in interface org.djutils.cli.Checkable
      Throws:
      Exception
    • start

      public final void start() throws Exception
      Starts the simulation.
      Throws:
      Exception - on any exception
    • notify

      public void notify(org.djutils.event.Event event) throws RemoteException
      Specified by:
      notify in interface org.djutils.event.EventListener
      Throws:
      RemoteException
    • getSimulator

      public final org.opentrafficsim.core.dsol.OtsSimulatorInterface getSimulator()
      Returns the simulator.
      Returns:
      simulator
    • getNetwork

      public final org.opentrafficsim.road.network.RoadNetwork getNetwork()
      Returns the network.
      Returns:
      network
    • animateNetwork

      protected void animateNetwork(org.opentrafficsim.core.network.Network net, OtsAnimationPanel animationPanel)
      Creates animations for nodes, links and lanes. This can be used if the network is not read from XML.
      Parameters:
      net - network
      animationPanel - animation panel
    • addTabs

      protected void addTabs(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim, OtsSimulationApplication<?> animation)
      Adds tabs to the animation. May be overridden.
      Parameters:
      sim - simulator
      animation - 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, org.opentrafficsim.road.network.RoadNetwork net)
      Method that is called when the animation has been created, to add components for a demo.
      Parameters:
      animationPanel - animation panel
      net - network
    • setAnimationToggles

      protected void setAnimationToggles(OtsAnimationPanel animation)
      Sets the animation toggles. May be overridden.
      Parameters:
      animation - animation to set the toggle on
    • setupSimulation

      protected abstract org.opentrafficsim.road.network.RoadNetwork setupSimulation(org.opentrafficsim.core.dsol.OtsSimulatorInterface sim) throws Exception
      Sets up the simulation based on provided properties. Properties can be obtained with getProperty(). 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