SSJ  3.3.1
Stochastic Simulation in Java
Classes | Public Member Functions | Static Public Member Functions | List of all members
BatchMeansSim Class Referenceabstract

Performs a simulation experiment on an infinite horizon, for estimating steady-state performance measures, using batch means. More...

Inheritance diagram for BatchMeansSim:
[legend]
Collaboration diagram for BatchMeansSim:
[legend]

Public Member Functions

 BatchMeansSim (int minBatches, double batchSize, double warmupTime)
 Constructs a new batch means simulator using at least minBatches batches with size batchSize, with a warmup period of duration warmupTime. More...
 
 BatchMeansSim (int minBatches, int maxBatches, double batchSize, double warmupTime)
 Constructs a batch means simulator with a maximum of maxBatches batches to avoid excessive memory usage and too long simulations when using sequential sampling. More...
 
 BatchMeansSim (Simulator sim, int minBatches, double batchSize, double warmupTime)
 Equivalent to the first constructor, with a user-defined simulator sim. More...
 
 BatchMeansSim (Simulator sim, int minBatches, int maxBatches, double batchSize, double warmupTime)
 Equivalent to the second constructor, with a user-defined simulator sim. More...
 
boolean getBatchAggregation ()
 Returns true if the aggregation of batches is turned ON. More...
 
void setBatchAggregation (boolean a)
 Sets the batch aggregation indicator to a. More...
 
boolean getBatchLengthsKeeping ()
 Indicates that the length, in simulation time units, of each real batch has to be kept. More...
 
void setBatchLengthsKeeping (boolean b)
 Sets the batch lengths keeping indicator to b. More...
 
int getMinBatches ()
 Returns the minimal number of batches required for estimating the steady-state performance measures of interest. More...
 
void setMinBatches (int minBatches)
 Sets the minimal number of batches to minBatches. More...
 
int getMaxBatches ()
 Returns \(M\), the maximal number of batches to be used for estimating the steady-state performance measures of interest. More...
 
void setMaxBatches (int maxBatches)
 Sets the maximal number of batches to maxBatches. More...
 
double getBatchSize ()
 Returns the current batch size as defined for this simulator. More...
 
void setBatchSize (double batchSize)
 Sets the batch size to batchSize. More...
 
double getWarmupTime ()
 Returns the duration of the warmup period for the simulation. More...
 
void setWarmupTime (double warmupTime)
 Sets the warmup time to warmupTime. More...
 
double getBatchFraction ()
 Returns the remaining fraction of batch to be simulated. More...
 
double getBatchSizeMultiplier ()
 Returns the batch size multiplier after the simulation of a new batch. More...
 
int getTargetBatches ()
 Returns the target number of simulated real batches at the next time the stopping condition is checked. More...
 
void setTargetBatches (int targetBatches)
 Sets the target number of simulated batches before an error check or the end of the simulation to targetBatches. More...
 
int getCompletedRealBatches ()
 Returns the number of completed real batches since the beginning of the run. More...
 
int getDroppedRealBatches ()
 Returns the number of real batches dropped. More...
 
void dropFirstRealBatches (int n)
 Drops the n first real batches to save memory. More...
 
int getBatch (double time)
 Returns the real batch corresponding to simulation time time when batch lengths are kept. More...
 
boolean isWarmupDone ()
 Determines if the warmup period for the simulation is over. More...
 
int getNumAggregates ()
 Returns \(h\), the number of real batches contained into an effective batch. More...
 
double getRealBatchLength (int batch)
 Returns the length, in simulation time units, of the real batch batch. More...
 
double getRealBatchStartingTime (int batch)
 Returns the starting simulation time of batch batch. More...
 
double getRealBatchEndingTime (int batch)
 Returns the ending simulation time of batch batch. More...
 
void allocateCapacity (int capacity)
 Allocates the necessary memory for storing capacity real batches. More...
 
void regroupRealBatches (int x)
 Regroups real batches x by x. More...
 
abstract void initSimulation ()
 Initializes the simulator for a new run. More...
 
abstract void initBatchStat ()
 Resets the counters used for computing observations during the simulation at the beginning of a new batch.
 
abstract void initRealBatchProbes ()
 Initializes any statistical collector for real batches. More...
 
abstract void initEffectiveBatchProbes ()
 Initializes any statistical collector for effective batches. More...
 
abstract void addRealBatchObs ()
 Collects values of a \(\mathbf{V}_j\) vector concerning the last simulated real batch. More...
 
abstract void addEffectiveBatchObs (int s, int h, double l)
 Adds an observation to each statistical collector corresponding to an effective batch. More...
 
int getRequiredNewBatches ()
 Computes the approximate number of required real batches to be simulated before the simulation can be stopped. More...
 
void init ()
 Initializes the simulator for a new experiment. More...
 
Event getEndSimEvent ()
 Returns the event used to stop the simulation at the end of the warmup or batches.
 
void warmup ()
 Performs a warmup by calling warmup(double). More...
 
void warmup (double warmupTime)
 Performs a warmup of fixed duration warmupTime. More...
 
void simulateBatch ()
 Simulate a new batch with default length. More...
 
void simulateBatch (double batchLength)
 Simulates a batch with length batchLength. More...
 
void adjustTargetBatches (int numNewBatches)
 Adjusts the target number of real batches to simulate numNewBatches additionnal real batches. More...
 
void simulateBatches ()
 Simulates batches until the number of completed real batches corresponds to the target number of batches. More...
 
void simulate ()
 Performs a batch means simulation. More...
 
String toString ()
 
- Public Member Functions inherited from SimExp
final Simulator simulator ()
 Returns the simulator linked to this experiment object. More...
 
final void setSimulator (Simulator sim)
 Sets the simulator associated with this experiment to sim. More...
 
boolean isSimulating ()
 Determines if the simulation is in progress. More...
 
abstract void simulate ()
 Performs an experiment whose logic depends on the used subclass. More...
 

Static Public Member Functions

static double getSum (double[] a, int start, int length)
 Returns the sum of elements start, …, start + length - 1, in the array a. More...
 
static double getSum (DoubleArrayList l, int start, int length)
 Returns the sum of elements start, …, start + length - 1, in the array list l. More...
 
static double getSum (DoubleMatrix1D m, int start, int length)
 Returns the sum of elements start, …, start + length - 1, in the 1D matrix m. More...
 
static double [] getSum (double[][] a, int startColumn, int numColumns)
 Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1, in the 2D matrix represented by the 2D array a. More...
 
static double [] getSum (DoubleMatrix2D m, int startColumn, int numColumns)
 Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1, in the 2D matrix m. More...
 
static void regroupElements (double[] a, int x)
 Regroups the elements in array a by summing each successive x values. More...
 
static void regroupElements (DoubleArrayList l, int x)
 Same as #regroupElements(double[],int) for an array list. More...
 
static void regroupElements (DoubleMatrix1D mat, int x)
 Same as #regroupElements(double[],int) for a 1D matrix. More...
 
static void regroupElements (DoubleMatrix2D mat, int x)
 Same as #regroupElements(double[],int) for a 2D matrix. More...
 
- Static Public Member Functions inherited from SimExp
static int getRequiredNewObservations (StatProbe[] a, double targetError, double level)
 Returns the approximate number of additional observations required to reach a relative error smaller than or equal to targetError for each tally in the array a when confidence intervals are computed with confidence level level. More...
 
static int getRequiredNewObservations (Iterable<? extends StatProbe > it, double targetError, double level)
 Returns the approximate number of additional observations required to reach a relative error smaller than or equal to targetError for each tally enumerated by it when confidence intervals are computed with confidence level level. More...
 
static int getRequiredNewObservations (StatProbe probe, double targetError, double level)
 Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radius, and number of observations given by the statistical probe probe. More...
 
static int getRequiredNewObservationsTally (Tally ta, double targetError, double level)
 Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radius, and number of observations given by the tally ta. More...
 
static int getRequiredNewObservationsTally (FunctionOfMultipleMeansTally fmmt, double targetError, double level)
 Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radius, and number of observations given by the function of multiple means fmmt. More...
 
static int getRequiredNewObservations (double center, double radius, int numberObs, double targetError)
 Returns the approximate number of additional observations needed for the point estimator \(\bar{X}_n=\) center, computed using \(n=\) numberObs observations and with a confidence interval having radius \(\delta_n/\sqrt{n}=\) radius, to have a relative error less than or equal to \(\epsilon=\) targetError. More...
 

Additional Inherited Members

- Protected Member Functions inherited from SimExp
 SimExp ()
 Constructs a new object for performing experiments using the default simulator returned by Simulator.getDefaultSimulator().
 
 SimExp (Simulator sim)
 Constructs a new object performing experiments using the given simulator sim. More...
 
- Protected Attributes inherited from SimExp
Simulator sim
 
boolean simulating = false
 Determines if the simulation is in progress.
 

Detailed Description

Performs a simulation experiment on an infinite horizon, for estimating steady-state performance measures, using batch means.

Batches are delimited using a user-specified condition such as a fixed duration in simulation time units (the default), the number of occurrences of an event such as the arrival of a customer, a regenerative cycle, etc. After the condition for batch termination is defined, the batch size can be set. This size can be, depending on how batches are delimited, a time duration, a number of events, or 1 for regenerative cycles. The batch length is defined to be the duration of a batch, in simulation time units, independently of how batches are defined. By default, the batch size and the batch length are equivalent (and constant), but they may differ if the condition for batch termination is changed.

A warmup period is usually simulated to reduce the bias induced by the initial state of the system. During the warmup, the system runs without any observation being collected. By default, this period has a duration fixed in simulation time units, but this can also be changed.

After the warmup is over, events are counted as follows. The simulation model defines some counters being updated when events occur and reset at the beginning of each batch. At the end of a batch, the value of these counters are used to generate a random vector \(\mathbf{V}_j\) before the counters are reset. Alternatively, a simulation may compute and update the \(\mathbf{V}_j\)’s directly, without using intermediate counters. A set of data structures is needed to collect and store these \(\mathbf{V}_j\)’s, the simplest option being a set of umontreal.ssj.stat.TallyStore instances. This generates values for \(m\) real batches. The sample \((\mathbf{X}_0,…,\mathbf{X}_{n-1})\) is then obtained from \((\mathbf{V}_0,…,\mathbf{V}_{m-1})\), so a second set of data structures is needed to collect the \(\mathbf{X}_r\)’s, the simplest being a set of umontreal.ssj.stat.Tally instances. The most straightforward way to estimate covariances on components of \(\mathbf{X}_r\) is by considering the vectors \(\mathbf{X}_r\) i.i.d., which is not true in general. However, by choosing a sufficiently large simulation time and batch lengths, the correlation between batches can be reduced, and the \(\mathbf{X}_r\)’s are approximately i.i.d. and normally distributed. If batches correspond to regenerative cycles, the \(\mathbf{X}_r\) are then truly i.i.d., but only approximately normally distributed. Confidence intervals on functions of \(\boldsymbol{\mu}\) can be approximated using the central limit theorem, as with independent replications, or using the delta theorem for functions of multiple means or when batches have different lengths.

The sample size corresponding to the number of simulated batches is always fixed when sequential sampling is not used; we have \(n=m\) and \(\mathbf{X}_r=\mathbf{V}_r\) for \(r=0,…,n-1\). However, when sequential sampling is used, the sample size can be random or fixed. If the sample size is random, we still have \(\mathbf{X}_r=\mathbf{V}_r\). When using this mode, the batch size must be chosen carefully to reduce correlation between batches.

On the other hand, if the sample size \(n\) is required to be fixed while sequential sampling is used, batch aggregation must be activated to have effective batches with random lengths. When aggregation is enabled, real batches are simulated as usual, but the obtained values \(\mathbf{V}_j\) are regrouped (or aggregated) to form effective batches. The number of real batches must be \(m=h*n\) to get a sample of size \(n\), and \(h\) can be any integer greater than or equal to 1. In this case,

\[ \mathbf{X}_r=\sum_{k=0}^{h-1} \mathbf{V}_{hr+k}. \]

The size of the effective batches increases while the sample size remains fixed because the group size \(h\) increases with simulation length. When aggregation is used, the effective batches become longer while simulation time increases, and the correlation between effective batches should decrease with simulation time. However, the increment to the target number of batches must always be a multiple of the sample size, which can lead to useless simulation if the sample size is large.

This class must be extended to implement a batch means simulator, and the appropriate methods must be defined or overridden. This class uses a simulation event to stop the simulation at the end of the warmup period and batches. One can use this event for fixed-duration warmup and batches, or schedule their own events which call Sim.stop to end warmup or batches. To change how the warmup period is terminated, one must override the method warmup. For the batch termination condition to be redefined, simulateBatch must be overridden.

One must implement initSimulation to initialize the simulated model before the warmup, initBatchStat to reset the model-specific counters used to compute the \(\mathbf{V}_j\)’s, initRealBatchProbes and addRealBatchObs to initialize statistical probes and add observations for real batches, initEffectiveBatchProbes and addEffectiveBatchObs(int,int,double) to initialize statistical probes and add observations for effective batches.

The moment the latter methods are called depends on the status of batch aggregation: when aggregation is turned ON, before any error check or the end of the simulation, initEffectiveBatchProbes is called once before addEffectiveBatchObs(int,int,double) is called \(n\) successive times, with different parameters. When aggregation is turned OFF, then method initEffectiveBatchProbes is called after the warmup is over, and addEffectiveBatchObs(int,int,double) is called each time a batch ends, after addRealBatchObs is called.

If sequential sampling is used, getRequiredNewBatches must be overridden to implement error checking. In some particular situations, the user may also need to override allocateCapacity(int) and regroupRealBatches(int).

Constructor & Destructor Documentation

◆ BatchMeansSim() [1/4]

BatchMeansSim ( int  minBatches,
double  batchSize,
double  warmupTime 
)

Constructs a new batch means simulator using at least minBatches batches with size batchSize, with a warmup period of duration warmupTime.

By default, batch aggregation and batch lengths keeping are turned off, and the maximal number of batches is infinite.

Parameters
minBatchesthe minimal number of batches to simulate.
batchSizethe size of the batches.
warmupTimethe duration of the warmup period.
Exceptions
IllegalArgumentExceptionif the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

◆ BatchMeansSim() [2/4]

BatchMeansSim ( int  minBatches,
int  maxBatches,
double  batchSize,
double  warmupTime 
)

Constructs a batch means simulator with a maximum of maxBatches batches to avoid excessive memory usage and too long simulations when using sequential sampling.

See BatchMeansSim(int,double,double) for more information about the other parameters.

Parameters
minBatchesthe minimal number of batches to simulate.
maxBatchesthe maximal number of batches to simulate.
batchSizethe size of the batches.
warmupTimethe duration of the warmup period.
Exceptions
IllegalArgumentExceptionif the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

◆ BatchMeansSim() [3/4]

BatchMeansSim ( Simulator  sim,
int  minBatches,
double  batchSize,
double  warmupTime 
)

Equivalent to the first constructor, with a user-defined simulator sim.

Parameters
simthe simulator attached to this object.
minBatchesthe minimal number of batches to simulate.
batchSizethe size of the batches.
warmupTimethe duration of the warmup period.
Exceptions
IllegalArgumentExceptionif the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

◆ BatchMeansSim() [4/4]

BatchMeansSim ( Simulator  sim,
int  minBatches,
int  maxBatches,
double  batchSize,
double  warmupTime 
)

Equivalent to the second constructor, with a user-defined simulator sim.

Parameters
simthe simulator attached to this object.
minBatchesthe minimal number of batches to simulate.
maxBatchesthe maximal number of batches to simulate.
batchSizethe size of the batches.
warmupTimethe duration of the warmup period.
Exceptions
IllegalArgumentExceptionif the minimal number of batches is smaller than or equal to 0, or if the warmup time is smaller than 0.

Member Function Documentation

◆ addEffectiveBatchObs()

abstract void addEffectiveBatchObs ( int  s,
int  h,
double  l 
)
abstract

Adds an observation to each statistical collector corresponding to an effective batch.

The effective batch for which this method is called has length l, and regroups real batches s, …, s + h - 1. This method is called after each error check if aggregation is turned ON, or after each real batch if it is turned OFF.

◆ addRealBatchObs()

abstract void addRealBatchObs ( )
abstract

Collects values of a \(\mathbf{V}_j\) vector concerning the last simulated real batch.

This method is called at the end of each real batch.

◆ adjustTargetBatches()

void adjustTargetBatches ( int  numNewBatches)

Adjusts the target number of real batches to simulate numNewBatches additionnal real batches.

This method clamps the target number of real batches to the maximal number of batches, and ensures that the target number of batches is a multiple of the minimal number of batches when aggregation is turned ON.

◆ allocateCapacity()

void allocateCapacity ( int  capacity)

Allocates the necessary memory for storing capacity real batches.

When using sequential sampling, if the variance of estimators is high, many additional batches may be needed to reach the target precision. To avoid memory problems after a long simulation time, this method can preallocate the necessary memory. The method must ensure that the data structures used to store the \(\mathbf{V}_j\)’s can contain capacity real batches. This is done by recreating arrays or resizing data structures. By default, this method throws an UnsupportedOperationException. regroupRealBatches must be implemented if this method does not throw this exception.

Parameters
capacitythe number of real batches to store.
Exceptions
UnsupportedOperationExceptionto indicate that capacity allocation is not supported

◆ dropFirstRealBatches()

void dropFirstRealBatches ( int  n)

Drops the n first real batches to save memory.

Parameters
nthe number of real batches to drop.
Exceptions
IllegalArgumentExceptionif n is negative or greater than the number of stored real batches.
See also
getDroppedRealBatches()

◆ getBatch()

int getBatch ( double  time)

Returns the real batch corresponding to simulation time time when batch lengths are kept.

If batch lengths are not kept, or if the given time corresponds to the warmup period, this method returns a negative value.

Parameters
timethe simulation time.
Returns
the batch corresponding to the time, or a negative value.

◆ getBatchAggregation()

boolean getBatchAggregation ( )

Returns true if the aggregation of batches is turned ON.

If getRequiredNewBatches always returns 0 (the default), the aggregation has no effect since the number of batches is not random. By default, batch aggregation is turned OFF.

Returns
the batch aggregation indicator.

◆ getBatchFraction()

double getBatchFraction ( )

Returns the remaining fraction of batch to be simulated.

This method is called when scheduling the end of the next batch during a simulation. Sometimes, it can be necessary to increase the batch size to avoid excessive memory usage. In this case, stored real batches (the \(\mathbf{V}_j\)’s) have to be regrouped to use less memory, and the last stored \(\mathbf{V}_j\) may represent an incomplete batch with respect to the new batch size. This method returns the fraction of batch, with respect to the new batch size, remaining to be simulated before a new batch starts. If regrouping is not used, this always returns 1. The returned value is always greater than 0 and smaller than or equal to 1. For example, with a fixed time batch size s, the next end of batch will be scheduled in s*getBatchFraction() simulation time units. This method returns values different from 1 only if one overrides allocateCapacity(int), and regroupRealBatches.

Returns
the remaining fraction of batch to simulate.
See also
regroupRealBatches(int)

◆ getBatchLengthsKeeping()

boolean getBatchLengthsKeeping ( )

Indicates that the length, in simulation time units, of each real batch has to be kept.

By default, this is set to false. When batch aggregation is turned ON, the batch lengths are always kept.

Returns
the batch lengths keeping indicator.

◆ getBatchSize()

double getBatchSize ( )

Returns the current batch size as defined for this simulator.

By default, this is a duration in simulation time units. Depending on the batch termination condition, which can be changed by overriding simulateBatch, it can be the number of occurrences of an event, or 1 for regenerative cycles.

Returns
the current batch size.

◆ getBatchSizeMultiplier()

double getBatchSizeMultiplier ( )

Returns the batch size multiplier after the simulation of a new batch.

This is called when scheduling the end of a new batch, to multiply the batch size after regroupRealBatches(int) has regrouped real batches. This can return any value greater than 0, or 1 if the size is unchanged (the most common case) or if aggregation is not used. This method returns values different from 1 only if one overrides allocateCapacity(int), and regroupRealBatches.

Returns
the batch size multiplier.
See also
regroupRealBatches(int)

◆ getCompletedRealBatches()

int getCompletedRealBatches ( )

Returns the number of completed real batches since the beginning of the run.

Returns
the number of completed real batches.

◆ getDroppedRealBatches()

int getDroppedRealBatches ( )

Returns the number of real batches dropped.

When using sequential sampling, the target number of batches can become very high, resulting in not enough memory available to store the real batches. One simple heuristic to address this issue is to drop the first real batches, and increase the batch length. This method gives the number of real batches which have been dropped to save memory.

Returns
the number of dropped real batches.

◆ getMaxBatches()

int getMaxBatches ( )

Returns \(M\), the maximal number of batches to be used for estimating the steady-state performance measures of interest.

This is used to prevent the number of batches from growing indefinitely when using sequential sampling. By default, this is set to java.lang.Integer.MAX_VALUE, which is equivalent to infinity in practice.

Returns
the maximal number of batches.

◆ getMinBatches()

int getMinBatches ( )

Returns the minimal number of batches required for estimating the steady-state performance measures of interest.

If aggregation is turned ON, this is also the final number of effective batches, i.e., the sample size.

Returns
the minimal number of batches.

◆ getNumAggregates()

int getNumAggregates ( )

Returns \(h\), the number of real batches contained into an effective batch.

If aggregation is turned OFF, this always returns 1 as soon as at least one batch is simulated. Otherwise, this returns a number greater than or equal to 1 as soon as addEffectiveBatchObs(int,int,double) is called.

Returns
the number of real batches in one effective batch.
Exceptions
IllegalStateExceptionif \(h\) is not available.

◆ getRealBatchEndingTime()

double getRealBatchEndingTime ( int  batch)

Returns the ending simulation time of batch batch.

Parameters
batchthe queried batch index.
Returns
the ending time.

◆ getRealBatchLength()

double getRealBatchLength ( int  batch)

Returns the length, in simulation time units, of the real batch batch.

If batch lengths are not kept, this method can return the length of the last batch only.

Parameters
batchthe batch index.
Returns
the length of the batch.
Exceptions
IndexOutOfBoundsExceptionif the batch index is out of bounds.
IllegalArgumentExceptionif the batch length is not available for batch.

◆ getRealBatchStartingTime()

double getRealBatchStartingTime ( int  batch)

Returns the starting simulation time of batch batch.

Parameters
batchthe queried batch index.
Returns
the starting time.

◆ getRequiredNewBatches()

int getRequiredNewBatches ( )

Computes the approximate number of required real batches to be simulated before the simulation can be stopped.

The default implementation always returns 0, which stops the simulation after getTargetBatches real batches are obtained; sequential sampling is not used by default.

Note: if the method uses umontreal.ssj.simexp.SimExp.getRequiredNewObservations(StatProbe[],double,double) with a statistical probe containing one observation per effective batch, this gives the number of additional effective batches to simulate. This value should be multiplied with getNumAggregates to get the number of additional real batches.

Returns
the approximate required number of additionnal real batches.

◆ getSum() [1/5]

static double getSum ( double []  a,
int  start,
int  length 
)
static

Returns the sum of elements start, …, start + length - 1, in the array a.

Parameters
athe source array.
startthe index of the first element to sum.
lengththe number of elements in the sum.
Returns
the sum of the elements.
Exceptions
NullPointerExceptionif a is null.
IllegalArgumentExceptionlength is negative.
IndexOutOfBoundsExceptionif start is negative, or start + length is greater than the length of a.

◆ getSum() [2/5]

static double getSum ( DoubleArrayList  l,
int  start,
int  length 
)
static

Returns the sum of elements start, …, start + length - 1, in the array list l.

Parameters
lthe source array list.
startthe index of the first element to sum.
lengththe number of elements in the sum.
Returns
the sum of the elements.
Exceptions
NullPointerExceptionif l is null.
IllegalArgumentExceptionlength is negative.
IndexOutOfBoundsExceptionif start is negative, or start + length is greater than the size of l.

◆ getSum() [3/5]

static double getSum ( DoubleMatrix1D  m,
int  start,
int  length 
)
static

Returns the sum of elements start, …, start + length - 1, in the 1D matrix m.

Parameters
mthe source 1D matrix.
startthe index of the first element to sum.
lengththe number of elements in the sum.
Returns
the sum of the elements.
Exceptions
NullPointerExceptionif m is null.
IllegalArgumentExceptionlength is negative.
IndexOutOfBoundsExceptionif start is negative, or start + length is greater than the size of m.

◆ getSum() [4/5]

static double [] getSum ( double  a[][],
int  startColumn,
int  numColumns 
)
static

Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1, in the 2D matrix represented by the 2D array a.

The given array is assumed to be rectangular, i.e., each of its array elements has the same length.

Parameters
athe source 2D array.
startColumnthe index of the first column to sum.
numColumnsthe number of columns in the sum.
Returns
an array of a.length elements containing the sums of the columns.
Exceptions
NullPointerExceptionif a is null.
IllegalArgumentExceptionnumColumns is negative.
IndexOutOfBoundsExceptionif startColumn is negative, or startColumn + numColumns is greater than the number of columns in the matrix represented by a.

◆ getSum() [5/5]

static double [] getSum ( DoubleMatrix2D  m,
int  startColumn,
int  numColumns 
)
static

Returns an array containing the sum of columns startColumn, …, startColumn + numColumns - 1, in the 2D matrix m.

Parameters
mthe source 2D matrix.
startColumnthe index of the first column to sum.
numColumnsthe number of columns in the sum.
Returns
an array of m.rows() elements containing the sum of the columns.
Exceptions
NullPointerExceptionif m is null.
IllegalArgumentExceptionnumColumns is negative.
IndexOutOfBoundsExceptionif startColumn is negative, or startColumn + numColumns is greater than the number of columns in m.

◆ getTargetBatches()

int getTargetBatches ( )

Returns the target number of simulated real batches at the next time the stopping condition is checked.

By default, this number is set to the minimal number of batches and is increased if the stopping condition check requires new simulated batches. This target number of batches is not decreased automatically, even upon a new call to simulate.

Returns
the target number of batches.

◆ getWarmupTime()

double getWarmupTime ( )

Returns the duration of the warmup period for the simulation.

By default, this duration is expressed in simulation time units, but this can be changed by overriding warmup.

Returns
the warmup time for the simulation.

◆ init()

void init ( )

Initializes the simulator for a new experiment.

This method, called by simulate, resets the counter for the number of batches, calls simulator().init, followed by initSimulation.

◆ initEffectiveBatchProbes()

abstract void initEffectiveBatchProbes ( )
abstract

Initializes any statistical collector for effective batches.

This is called at every stopping condition check when aggregation is ON, or at the end of the warmup period when it is OFF.

◆ initRealBatchProbes()

abstract void initRealBatchProbes ( )
abstract

Initializes any statistical collector for real batches.

This is called at the end of the warmup period.

◆ initSimulation()

abstract void initSimulation ( )
abstract

Initializes the simulator for a new run.

This is called by the init method after umontreal.ssj.simevents.Sim.init is called.

◆ isWarmupDone()

boolean isWarmupDone ( )

Determines if the warmup period for the simulation is over.

Returns
true if the warmup period is finished, false otherwise.

◆ regroupElements() [1/4]

static void regroupElements ( double []  a,
int  x 
)
static

Regroups the elements in array a by summing each successive x values.

When this method returns, element i of the given array corresponds to the sum of elements ix, …, ix + x - 1 in the original array. If the size of the array is not a multiple of x, the remaining elements are summed up and added into an extra element of the transformed array. Remaining elements of the transformed array are set to 0.

Parameters
athe array being processed.
xthe regrouping factor.
Exceptions
NullPointerExceptionif a is null.
IllegalArgumentExceptionif x is smaller than 1.

◆ regroupElements() [2/4]

static void regroupElements ( DoubleArrayList  l,
int  x 
)
static

Same as #regroupElements(double[],int) for an array list.

The size of the list is also divided by x.

Parameters
lthe array list being processed.
xthe regrouping factor.
Exceptions
NullPointerExceptionif l is null.
IllegalArgumentExceptionif x is smaller than 1.

◆ regroupElements() [3/4]

static void regroupElements ( DoubleMatrix1D  mat,
int  x 
)
static

Same as #regroupElements(double[],int) for a 1D matrix.

Parameters
matthe 1D matrix being processed.
xthe regrouping factor.
Exceptions
NullPointerExceptionif mat is null.
IllegalArgumentExceptionif x is smaller than 1.

◆ regroupElements() [4/4]

static void regroupElements ( DoubleMatrix2D  mat,
int  x 
)
static

Same as #regroupElements(double[],int) for a 2D matrix.

This method regroups columns and considers each row as an independent array.

Parameters
matthe 2D matrix being processed.
xthe regrouping factor.
Exceptions
NullPointerExceptionif mat is null.
IllegalArgumentExceptionif x is smaller than 1.

◆ regroupRealBatches()

void regroupRealBatches ( int  x)

Regroups real batches x by x.

When memory is low, the simulator can try to regroup real batches and increase the batch size consequently. This is partly done by this method. The user must override it and modify the internal data structures storing the \(\mathbf{V}_j\)’s in order to regroup elements. The number of real batches \(m\) becomes \(m’=\lfloor m/x\rfloor\). After this method returns, each new \(\mathbf{V}_j\) should contain \(\mathbf{V}_j=\sum_{l=0}^{x-1}\mathbf{V}_{jx+l}\) for \(j=0,…, m’ - 1\), \(\mathbf{V}_{m’}=\sum_{l=0}^{(m \bmod x) - 1} \mathbf{V}_{m’x + l}\), and \(\mathbf{V}_j=0\) for \(j=m’+1, …, m - 1\). Some static methods called #regroupElements(double[],int) are provided by this class to help the user with this. By default, this method throws an UnsupportedOperationException, disabling this functionality which is not always needed.

Parameters
xthe regrouping factor.
Exceptions
UnsupportedOperationExceptionif regrouping is not supported.

◆ setBatchAggregation()

void setBatchAggregation ( boolean  a)

Sets the batch aggregation indicator to a.

This should not be called during an experiment.

Parameters
athe new batch aggregation indicator.
Exceptions
IllegalStateExceptionif the warmup period is over, and simulation is not terminated.

◆ setBatchLengthsKeeping()

void setBatchLengthsKeeping ( boolean  b)

Sets the batch lengths keeping indicator to b.

This has no impact if batch aggregation is turned ON.

Parameters
bthe new value of the indicator.
Exceptions
IllegalStateExceptionif the warmup period is over and simulation is not terminated.

◆ setBatchSize()

void setBatchSize ( double  batchSize)

Sets the batch size to batchSize.

Parameters
batchSizethe new batch size.
Exceptions
IllegalArgumentExceptionif the given batch size is negative or 0.

◆ setMaxBatches()

void setMaxBatches ( int  maxBatches)

Sets the maximal number of batches to maxBatches.

Parameters
maxBatchesthe new maximal number of batches.
Exceptions
IllegalArgumentExceptionif the maximal number of batches is smaller than the actual minimal number of batches.

◆ setMinBatches()

void setMinBatches ( int  minBatches)

Sets the minimal number of batches to minBatches.

Parameters
minBatchesthe new minimal number of batches.
Exceptions
IllegalArgumentExceptionif the specified minimal number of batches is smaller than 0.

◆ setTargetBatches()

void setTargetBatches ( int  targetBatches)

Sets the target number of simulated batches before an error check or the end of the simulation to targetBatches.

Parameters
targetBatchesthe target number of batches.
Exceptions
IllegalArgumentExceptionif the new target number of batches is smaller than the minimal number of batches, or greater than the maximal number of batches.

◆ setWarmupTime()

void setWarmupTime ( double  warmupTime)

Sets the warmup time to warmupTime.

If this method is called while a simulation is in progress, the new time will affect the next simulation only.

Parameters
warmupTimethe new warmup time.
Exceptions
IllegalArgumentExceptionif the warmup time is smaller than 0.

◆ simulate()

void simulate ( )

Performs a batch means simulation.

This method resets the state of the system by calling init, and calls warmup to perform the warmup. Then, the method calls simulateBatches and getRequiredNewBatches until the number of completed real batches equals or exceeds the target number of batches.

◆ simulateBatch() [1/2]

void simulateBatch ( )

Simulate a new batch with default length.

By default, this method multiplies the current batch size with getBatchSizeMultiplier, and schedules the next end-batch event to happen in getBatchSize * getBatchFraction simulation time units, by using simulateBatch(double). After the batch is simulated, the batch-size multiplier and fraction are reset to 1. If the batch lengths are not fixed, one can override this method to call simulateBatch(double) with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.

◆ simulateBatch() [2/2]

void simulateBatch ( double  batchLength)

Simulates a batch with length batchLength.

This method initializes the model-specific counters by using initBatchStat, simulates the batch, and adds observations using addRealBatchObs. It also calls addEffectiveBatchObs if aggregation is turned OFF. If the batch lengths are not fixed, one can call this method to call simulateBatch(double) with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.

◆ simulateBatches()

void simulateBatches ( )

Simulates batches until the number of completed real batches corresponds to the target number of batches.

This method first allocates the capacity for simulating getTargetBatches. It then simulate each batch using simulateBatch. If aggregation is turned ON, this method also calls initEffectiveBatchProbes, and addEffectiveBatchObs to manage effective batches.

◆ warmup() [1/2]

void warmup ( )

Performs a warmup by calling warmup(double).

By default, this method calls warmup(double) with the value returned by getWarmupTime, but one can override this method to simulate the warmup differently. If the duration of the warmup period is not fixed, one can call warmup(double) with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.

◆ warmup() [2/2]

void warmup ( double  warmupTime)

Performs a warmup of fixed duration warmupTime.

This method simulates for warmupTime simulation time units, and initializes statistical probes for real batches through initRealBatchProbes. If the duration of the warmup period is not fixed, one can call warmup(double) with Double.POSITIVE_INFINITY; this prevents the method from scheduling the ending event, and let the simulator call simulator().stop at appropriate time.


The documentation for this class was generated from the following file: