|
SSJ V. labo. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectumontreal.iro.lecuyer.simexp.SimExp
umontreal.iro.lecuyer.simexp.BatchMeansSim
public abstract class BatchMeansSim
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
Vj before the counters are reset. Alternatively, a simulation
may compute and update the Vj's directly, without
using intermediate counters. A set of data
structures is needed to collect and store these Vj's,
the simplest option being a set of
TallyStore
instances.
This generates values for m real batches.
The
sample
(X0,…, Xn-1) is then obtained
from
(V0,…,Vm-1), so a second set
of data structures is needed to collect the Xr's,
the simplest being a set of Tally
instances.
The most straightforward way to estimate covariances on components of
Xr is by considering
the vectors Xr 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 Xr's are approximately i.i.d. and normally distributed.
If batches correspond to regenerative cycles,
the Xr are then truly i.i.d., but only approximately normally distributed.
Confidence intervals on functions of μ 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 Xr = Vr 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 Xr = Vr. 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 Vj 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,
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 Vj's,
initRealBatchProbes
and
addRealBatchObs
to initialize statistical probes and add observations
for real batches,
initEffectiveBatchProbes
and
addEffectiveBatchObs
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
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
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
and regroupRealBatches
.
Constructor Summary | |
---|---|
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. |
|
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. |
|
BatchMeansSim(Simulator sim,
int minBatches,
double batchSize,
double warmupTime)
Equivalent to the first constructor, with a user-defined simulator sim. |
|
BatchMeansSim(Simulator sim,
int minBatches,
int maxBatches,
double batchSize,
double warmupTime)
Equivalent to the second constructor, with a user-defined simulator sim. |
Method Summary | |
---|---|
abstract void |
addEffectiveBatchObs(int s,
int h,
double l)
Adds an observation to each statistical collector corresponding to an effective batch. |
abstract void |
addRealBatchObs()
Collects values of a Vj vector concerning the last simulated real batch. |
void |
adjustTargetBatches(int numNewBatches)
Adjusts the target number of real batches to simulate numNewBatches additionnal real batches. |
void |
allocateCapacity(int capacity)
Allocates the necessary memory for storing capacity real batches. |
void |
dropFirstRealBatches(int n)
Drops the n first real batches to save memory. |
int |
getBatch(double time)
Returns the real batch corresponding to simulation time time when batch lengths are kept. |
boolean |
getBatchAggregation()
Returns true if the aggregation of batches is turned ON. |
double |
getBatchFraction()
Returns the remaining fraction of batch to be simulated. |
boolean |
getBatchLengthsKeeping()
Indicates that the length, in simulation time units, of each real batch has to be kept. |
double |
getBatchSize()
Returns the current batch size as defined for this simulator. |
double |
getBatchSizeMultiplier()
Returns the batch size multiplier after the simulation of a new batch. |
int |
getCompletedRealBatches()
Returns the number of completed real batches since the beginning of the run. |
int |
getDroppedRealBatches()
Returns the number of real batches dropped. |
Event |
getEndSimEvent()
Returns the event used to stop the simulation at the end of the warmup or batches. |
int |
getMaxBatches()
Returns M, the maximal number of batches to be used for estimating the steady-state performance measures of interest. |
int |
getMinBatches()
Returns the minimal number of batches required for estimating the steady-state performance measures of interest. |
int |
getNumAggregates()
Returns h, the number of real batches contained into an effective batch. |
double |
getRealBatchEndingTime(int batch)
Returns the ending simulation time of batch batch. |
double |
getRealBatchLength(int batch)
Returns the length, in simulation time units, of the real batch batch. |
double |
getRealBatchStartingTime(int batch)
Returns the starting simulation time of batch batch. |
int |
getRequiredNewBatches()
Computes the approximate number of required real batches to be simulated before the simulation can be stopped. |
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. |
static double |
getSum(double[] a,
int start,
int length)
Returns the sum of elements start, ..., start + length - 1, in the array a. |
static double |
getSum(DoubleArrayList l,
int start,
int length)
Returns the sum of elements start, ..., start + length - 1, in the array list l. |
static double |
getSum(DoubleMatrix1D m,
int start,
int length)
Returns the sum of elements start, ..., start + length - 1, in the 1D matrix m. |
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. |
int |
getTargetBatches()
Returns the target number of simulated real batches at the next time the stopping condition is checked. |
double |
getWarmupTime()
Returns the duration of the warmup period for the simulation. |
void |
init()
Initializes the simulator for a new experiment. |
abstract void |
initBatchStat()
Resets the counters used for computing observations during the simulation at the beginning of a new batch. |
abstract void |
initEffectiveBatchProbes()
Initializes any statistical collector for effective batches. |
abstract void |
initRealBatchProbes()
Initializes any statistical collector for real batches. |
abstract void |
initSimulation()
Initializes the simulator for a new run. |
boolean |
isWarmupDone()
Determines if the warmup period for the simulation is over. |
static void |
regroupElements(double[] a,
int x)
Regroups the elements in array a by summing each successive x values. |
static void |
regroupElements(DoubleArrayList l,
int x)
Same as regroupElements for an array list. |
static void |
regroupElements(DoubleMatrix1D mat,
int x)
Same as regroupElements for a 1D matrix. |
static void |
regroupElements(DoubleMatrix2D mat,
int x)
Same as regroupElements for a 2D matrix. |
void |
regroupRealBatches(int x)
Regroups real batches x by x. |
void |
setBatchAggregation(boolean a)
Sets the batch aggregation indicator to a. |
void |
setBatchLengthsKeeping(boolean b)
Sets the batch lengths keeping indicator to b. |
void |
setBatchSize(double batchSize)
Sets the batch size to batchSize. |
void |
setMaxBatches(int maxBatches)
Sets the maximal number of batches to maxBatches. |
void |
setMinBatches(int minBatches)
Sets the minimal number of batches to minBatches. |
void |
setTargetBatches(int targetBatches)
Sets the target number of simulated batches before an error check or the end of the simulation to targetBatches. |
void |
setWarmupTime(double warmupTime)
Sets the warmup time to warmupTime. |
void |
simulate()
Performs a batch means simulation. |
void |
simulateBatch()
Simulate a new batch with default length. |
void |
simulateBatch(double batchLength)
Simulates a batch with length batchLength. |
void |
simulateBatches()
Simulates batches until the number of completed real batches corresponds to the target number of batches. |
String |
toString()
|
void |
warmup()
Performs a warmup by calling warmup . |
void |
warmup(double warmupTime)
Performs a warmup of fixed duration warmupTime. |
Methods inherited from class umontreal.iro.lecuyer.simexp.SimExp |
---|
getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservations, getRequiredNewObservationsTally, getRequiredNewObservationsTally, isSimulating, setSimulator, simulator |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BatchMeansSim(int minBatches, double batchSize, double warmupTime)
minBatches
- the minimal number of batches to simulate.batchSize
- the size of the batches.warmupTime
- the duration of the warmup period.
IllegalArgumentException
- if the minimal number of
batches is smaller than or equal to 0, or if the warmup time
is smaller than 0.public BatchMeansSim(int minBatches, int maxBatches, double batchSize, double warmupTime)
BatchMeansSim
for more information about the other parameters.
minBatches
- the minimal number of batches to simulate.maxBatches
- the maximal number of batches to simulate.batchSize
- the size of the batches.warmupTime
- the duration of the warmup period.
IllegalArgumentException
- if the minimal number of
batches is smaller than or equal to 0, or if the warmup time
is smaller than 0.public BatchMeansSim(Simulator sim, int minBatches, double batchSize, double warmupTime)
sim
- the simulator attached to this object.minBatches
- the minimal number of batches to simulate.batchSize
- the size of the batches.warmupTime
- the duration of the warmup period.
IllegalArgumentException
- if the minimal number of
batches is smaller than or equal to 0, or if the warmup time
is smaller than 0.public BatchMeansSim(Simulator sim, int minBatches, int maxBatches, double batchSize, double warmupTime)
sim
- the simulator attached to this object.minBatches
- the minimal number of batches to simulate.maxBatches
- the maximal number of batches to simulate.batchSize
- the size of the batches.warmupTime
- the duration of the warmup period.
IllegalArgumentException
- if the minimal number of
batches is smaller than or equal to 0, or if the warmup time
is smaller than 0.Method Detail |
---|
public boolean getBatchAggregation()
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.
public void setBatchAggregation(boolean a)
a
- the new batch aggregation indicator.
IllegalStateException
- if the warmup period is over, and
simulation is not terminated.public boolean getBatchLengthsKeeping()
public void setBatchLengthsKeeping(boolean b)
b
- the new value of the indicator.
IllegalStateException
- if the warmup period is over and
simulation is not terminated.public int getMinBatches()
public void setMinBatches(int minBatches)
minBatches
- the new minimal number of batches.
IllegalArgumentException
- if the specified minimal number
of batches is smaller than 0.public int getMaxBatches()
MAX_VALUE
,
which is equivalent to infinity in practice.
public void setMaxBatches(int maxBatches)
maxBatches
- the new maximal number of batches.
IllegalArgumentException
- if the maximal number
of batches is smaller than the actual minimal number of batches.public double getBatchSize()
simulateBatch
, it can be
the number of occurrences of an event, or 1
for regenerative cycles.
public void setBatchSize(double batchSize)
batchSize
- the new batch size.
IllegalArgumentException
- if the given batch size
is negative or 0.public double getWarmupTime()
warmup
.
public void setWarmupTime(double warmupTime)
warmupTime
- the new warmup time.
IllegalArgumentException
- if the warmup time
is smaller than 0.public double getBatchFraction()
allocateCapacity
,
and regroupRealBatches
.
public double getBatchSizeMultiplier()
regroupRealBatches
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
,
and regroupRealBatches
.
public int getTargetBatches()
simulate
.
public void setTargetBatches(int targetBatches)
targetBatches
- the target number of batches.
IllegalArgumentException
- if the new target number
of batches is smaller than the minimal number of batches, or
greater than the maximal number of batches.public int getCompletedRealBatches()
public int getDroppedRealBatches()
public void dropFirstRealBatches(int n)
n
- the number of real batches to drop.
IllegalArgumentException
- if
n is negative or greater than the
number of stored real batches.
#getDroppedRealBatches()public int getBatch(double time)
time
- the simulation time.
public boolean isWarmupDone()
public int getNumAggregates()
addEffectiveBatchObs
is called.
IllegalStateException
- if h is not available.public double getRealBatchLength(int batch)
batch
- the batch index.
IndexOutOfBoundsException
- if the batch index
is out of bounds.
IllegalArgumentException
- if the batch length
is not available for batch.public double getRealBatchStartingTime(int batch)
batch
- the queried batch index.
public double getRealBatchEndingTime(int batch)
batch
- the queried batch index.
public void allocateCapacity(int capacity)
UnsupportedOperationException
.
regroupRealBatches
must be implemented if this method
does not throw this exception.
capacity
- the number of real batches to store.
UnsupportedOperationException
- to indicate that
capacity allocation is not supportedpublic void regroupRealBatches(int x)
regroupElements
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.
x
- the regrouping factor.
UnsupportedOperationException
- if regrouping is
not supported.public abstract void initSimulation()
init
method after init
is called.
public abstract void initBatchStat()
public abstract void initRealBatchProbes()
public abstract void initEffectiveBatchProbes()
public abstract void addRealBatchObs()
public abstract void addEffectiveBatchObs(int s, int h, double l)
public int getRequiredNewBatches()
getTargetBatches
real batches are
obtained; sequential sampling is not used by default.
Note: if the method uses getRequiredNewObservations
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.
public void init()
simulate
, resets the counter for
the number of batches, calls
simulator().init, followed by initSimulation
.
public Event getEndSimEvent()
public void warmup()
warmup
.
By default, this method calls warmup
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
with
Double.POSITIVE_INFINITY;
this prevents the method from scheduling the ending event, and let
the simulator call simulator().stop at appropriate time.
public void warmup(double warmupTime)
initRealBatchProbes
.
If the duration of the warmup period is not fixed, one can
call warmup
with
Double.POSITIVE_INFINITY;
this prevents the method from scheduling the ending event, and let
the simulator call simulator().stop at appropriate time.
public void simulateBatch()
getBatchSizeMultiplier
,
and schedules the next end-batch event to happen in
getBatchSize
*getBatchFraction
simulation
time units, by using simulateBatch
.
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
with
Double.POSITIVE_INFINITY;
this prevents the method from scheduling the ending event, and let
the simulator call simulator().stop at appropriate time.
public void simulateBatch(double batchLength)
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
with
Double.POSITIVE_INFINITY;
this prevents the method from scheduling the ending event, and let
the simulator call simulator().stop at appropriate time.
public void adjustTargetBatches(int numNewBatches)
public void simulateBatches()
getTargetBatches
.
It then simulate each batch using simulateBatch
.
If aggregation is turned ON, this method also calls
initEffectiveBatchProbes
, and
addEffectiveBatchObs
to manage effective batches.
public void simulate()
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.
simulate
in class SimExp
public String toString()
toString
in class Object
public static double getSum(double[] a, int start, int length)
a
- the source array.start
- the index of the first element to sum.length
- the number of elements in the sum.
NullPointerException
- if a is null.
IllegalArgumentException
- length is negative.
IndexOutOfBoundsException
- if start is negative, or
start + length is greater than the length of a.public static double getSum(DoubleArrayList l, int start, int length)
l
- the source array list.start
- the index of the first element to sum.length
- the number of elements in the sum.
NullPointerException
- if l is null.
IllegalArgumentException
- length is negative.
IndexOutOfBoundsException
- if start is negative, or
start + length is greater than the size of l.public static double getSum(DoubleMatrix1D m, int start, int length)
m
- the source 1D matrix.start
- the index of the first element to sum.length
- the number of elements in the sum.
NullPointerException
- if m is null.
IllegalArgumentException
- length is negative.
IndexOutOfBoundsException
- if start is negative, or
start + length is greater than the size of m.public static double[] getSum(double[][] a, int startColumn, int numColumns)
a
- the source 2D array.startColumn
- the index of the first column to sum.numColumns
- the number of columns in the sum.
NullPointerException
- if a is null.
IllegalArgumentException
- numColumns is negative.
IndexOutOfBoundsException
- if startColumn is negative, or
startColumn + numColumns is greater than the number of
columns in the matrix represented by a.public static double[] getSum(DoubleMatrix2D m, int startColumn, int numColumns)
m
- the source 2D matrix.startColumn
- the index of the first column to sum.numColumns
- the number of columns in the sum.
NullPointerException
- if m is null.
IllegalArgumentException
- numColumns is negative.
IndexOutOfBoundsException
- if startColumn is negative, or
startColumn + numColumns is greater than the number of
columns in m.public static void regroupElements(double[] a, int x)
a
- the array being processed.x
- the regrouping factor.
NullPointerException
- if a is null.
IllegalArgumentException
- if x is smaller than 1.public static void regroupElements(DoubleArrayList l, int x)
regroupElements
for an array list.
The size of the list is also divided by x.
l
- the array list being processed.x
- the regrouping factor.
NullPointerException
- if l is null.
IllegalArgumentException
- if x is smaller than 1.public static void regroupElements(DoubleMatrix1D mat, int x)
regroupElements
for a 1D matrix.
mat
- the 1D matrix being processed.x
- the regrouping factor.
NullPointerException
- if mat is null.
IllegalArgumentException
- if x is smaller than 1.public static void regroupElements(DoubleMatrix2D mat, int x)
regroupElements
for a 2D matrix.
This method regroups columns and considers each row as an independent
array.
mat
- the 2D matrix being processed.x
- the regrouping factor.
NullPointerException
- if mat is null.
IllegalArgumentException
- if x is smaller than 1.
|
SSJ V. labo. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |