Class Experiment<T extends Number & Comparable<T>,S extends SimulatorInterface<T>>
- java.lang.Object
-
- org.djutils.event.LocalEventProducer
-
- nl.tudelft.simulation.dsol.experiment.Experiment<T,S>
-
- Type Parameters:
T- the extended type itself to be able to implement a comparator on the simulation time.S- the simulator to use
- All Implemented Interfaces:
Serializable,Remote,EventListener,Treatment<T>,Contextualized,EventListener,EventProducer
public class Experiment<T extends Number & Comparable<T>,S extends SimulatorInterface<T>> extends LocalEventProducer implements EventListener, Treatment<T>, Contextualized
The Experiment specifies the parameters for a number of simulation replications, and can execute a series of replications.Copyright (c) 2002-2023 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://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Author:
- Alexander Verbraeck relative types are the same.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classExperiment.ExperimentThreadThe ExperimentRunner job.
-
Field Summary
Fields Modifier and Type Field Description static EventTypeEND_EXPERIMENT_EVENTEND_EXPERIMENT_EVENT is fired when the experiment is ended.static EventTypeSTART_EXPERIMENT_EVENTSTART_EXPERIMENT_EVENT is fired when the experiment starts.-
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description Experiment(String id, S simulator, DSOLModel<T,? extends S> model, T startTime, T warmupPeriod, T runLength, int numberOfReplications)Construct a new Experiment.Experiment(S simulator, DSOLModel<T,? extends S> model, ExperimentRunControl<T> runControl)Construct a new Experiment, using a RunControl to store the run control information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSummaryStatistic(String statistic, String field, double value)Tally a value in a summary statistic over multiple replications.protected voidendExperiment()Fire the end Experiment event.protected voidendReplication()Create or update summary statistics for the experiment based on the statistics of the just completed replication.ContextInterfacegetContext()intgetCurrentReplication()Return the current (running or finished) replication.intgetCurrentReplicationNumber()Return the current replication number, which is -1 if the experiment has not yet started.DSOLModel<T,? extends S>getModel()Return the model.intgetNumberOfReplications()Return the total number of replications to execute.RunControl<T>getRunControl()Return the RunControl object that contains the treatment information.SgetSimulator()Return the simulator.List<? extends ExperimentReplication<T,S>>getStartedReplications()Return the list of started replications.StreamUpdatergetStreamUpdater()Return the current stream updater.SortedMap<String,SortedMap<String,Tally>>getSummaryStatistics()The summary statistics over multiple replications.booleanisRunning()Return whether the experiment is running or not.protected ExperimentReplication<T,S>makeExperimentReplication()Create a new replication for an experiment.voidnotify(Event event)voidremoveFromContext()Remove the entire experiment tree from the context.voidreset()Reset the experiment so it can be run again.voidsetStreamUpdater(StreamUpdater streamUpdater)Set a new StreamUpdater to update the random seeds between replications.voidstart()Start the extire experiment on a simulator, and execute ehe replications one by one.protected voidstartNextReplication()Start the next replication from the list of replications, or fire END_EXPERIMENT_EVENT when there are no more non-executed replications.StringtoString()-
Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface nl.tudelft.simulation.dsol.experiment.Treatment
getDescription, getEndTime, getId, getRunLength, getStartTime, getWarmupPeriod, getWarmupTime, setDescription
-
-
-
-
Constructor Detail
-
Experiment
public Experiment(String id, S simulator, DSOLModel<T,? extends S> model, T startTime, T warmupPeriod, T runLength, int numberOfReplications)
Construct a new Experiment.- Parameters:
id- String; the id of the experimentsimulator- S; the simulatormodel- DSOLModel<T, S>; the model to experiment withstartTime- T; the start time of the simulation.warmupPeriod- R; the warmup period, included in the runlength (!)runLength- R; the total length of the run, including the warm-up period.numberOfReplications- int; the number of replications to execute- Throws:
NullPointerException- when id, startTime, warmupPeriod or runLength is nullIllegalArgumentException- when warmup period is negative, or run length is zero or negative, or when the warmup time is longer than or equal to the runlength, or the number of replications is zero or negative
-
Experiment
public Experiment(S simulator, DSOLModel<T,? extends S> model, ExperimentRunControl<T> runControl)
Construct a new Experiment, using a RunControl to store the run control information.- Parameters:
simulator- S; the simulatormodel- DSOLModel<T, S>; the model to experiment withrunControl- ExperimentRunControl; the run control information- Throws:
NullPointerException- when id, startTime, warmupPeriod or runLength is null
-
-
Method Detail
-
getRunControl
public RunControl<T> getRunControl()
Return the RunControl object that contains the treatment information.- Specified by:
getRunControlin interfaceTreatment<T extends Number & Comparable<T>>- Returns:
- RunControl; the RunControl object that contains the treatment information
-
getSimulator
public S getSimulator()
Return the simulator.- Returns:
- S; the simulator
-
getModel
public DSOLModel<T,? extends S> getModel()
Return the model.- Returns:
- DSOLModel; the model
-
getStartedReplications
public List<? extends ExperimentReplication<T,S>> getStartedReplications()
Return the list of started replications. Not all replications might have finished yet.- Returns:
- List<Replication<T, S>>; the list of started replications
-
start
public void start() throws RemoteExceptionStart the extire experiment on a simulator, and execute ehe replications one by one.- Throws:
RemoteException- on network error if started by RMIIllegalArgumentException- when there are no more replications to run, or when the simulator is already running
-
startNextReplication
protected void startNextReplication() throws RemoteExceptionStart the next replication from the list of replications, or fire END_EXPERIMENT_EVENT when there are no more non-executed replications.- Throws:
RemoteException- on network error if started by RMI
-
endExperiment
protected void endExperiment()
Fire the end Experiment event.
-
makeExperimentReplication
protected ExperimentReplication<T,S> makeExperimentReplication()
Create a new replication for an experiment. This method can be overridden in the inner classes.- Returns:
- ExperimentReplication; a new replication for an experiment
-
notify
public void notify(Event event) throws RemoteException
- Specified by:
notifyin interfaceEventListener- Throws:
RemoteException
-
reset
public void reset()
Reset the experiment so it can be run again.
-
endReplication
protected void endReplication()
Create or update summary statistics for the experiment based on the statistics of the just completed replication.
-
addSummaryStatistic
protected void addSummaryStatistic(String statistic, String field, double value)
Tally a value in a summary statistic over multiple replications.- Parameters:
statistic- String; the name of the statisticfield- String; the name of the field for the summary statisticvalue- double; the value to tally by the summary statistic
-
getSummaryStatistics
public SortedMap<String,SortedMap<String,Tally>> getSummaryStatistics()
The summary statistics over multiple replications. The table maps the name of the statistic to a map of fields to tallies that contain the statistics of the tallied values. Suppose we run a model with 10 replications, which has a tally named "waiting time". Then there will be an entry in this table called "waiting time" as well. This "waiting time" maps to several sub-maps, such as "N", "Population mean", "Population variance", "Min", "Max", etc. Each of these is a Tally for which the final values of the replications for that value have been tallied. The "Population Mean" for "waiting time" in this example therefore contains the average of the 10 average waiting times that have been alculated in the 10 replications.- Returns:
- summaryStatistics SortedMap<String, SortedMap<String, Tally>>; the summary statistics
-
getCurrentReplication
public int getCurrentReplication()
Return the current (running or finished) replication.- Returns:
- int; the current replication (still running or finished in case of last replication)
-
getContext
public ContextInterface getContext()
- Specified by:
getContextin interfaceContextualized
-
removeFromContext
public void removeFromContext()
Remove the entire experiment tree from the context.
-
getStreamUpdater
public StreamUpdater getStreamUpdater()
Return the current stream updater.- Returns:
- streamUpdater StreamUpdater; the current stream updater
-
setStreamUpdater
public void setStreamUpdater(StreamUpdater streamUpdater)
Set a new StreamUpdater to update the random seeds between replications.- Parameters:
streamUpdater- StreamUpdater; the new stream updater
-
getCurrentReplicationNumber
public int getCurrentReplicationNumber()
Return the current replication number, which is -1 if the experiment has not yet started.- Returns:
- int; the current replication number
-
getNumberOfReplications
public int getNumberOfReplications()
Return the total number of replications to execute.- Returns:
- int; the total number of replications to execute
-
isRunning
public boolean isRunning()
Return whether the experiment is running or not.- Returns:
- boolean; whether the experiment is running or not
-
-