SSJ
V. labo.

umontreal.iro.lecuyer.simexp
Class RepSim

java.lang.Object
  extended by umontreal.iro.lecuyer.simexp.SimExp
      extended by umontreal.iro.lecuyer.simexp.RepSim

public abstract class RepSim
extends SimExp

Performs a simulation experiment on a finite horizon, using a certain number of independent runs or replications. During each run r, a complete simulation is executed, and the vector Xr is generated. If simulation runs are independent, and the same system is simulated during each run, after n runs are performed, a sample (X0,…, Xn-1) is obtained.

For such a simulation to be implemented, this class must be extended to override the required methods: initReplicationProbes to initialize the statistical probes collecting Xr's, initReplication to initialize the simulation model at the beginning of each replication, and addReplicationObs to add Xr to the statistical probes.


Constructor Summary
RepSim(int minReps)
          Constructs a new replications-based simulator with a minimal number of runs, minReps, and no maximal number of runs.
RepSim(int minReps, int maxReps)
          Constructs a new replications-based simulator with a minimal number of runs minReps, and a maximal number of runs maxReps.
RepSim(Simulator sim, int minReps)
          Equivalent to the first constructor, with the given simulator sim.
RepSim(Simulator sim, int minReps, int maxReps)
          Equivalent to the second constructor, with the given simulator sim.
 
Method Summary
abstract  void addReplicationObs(int r)
          Adds statistical observations for the replication r.
 void adjustTargetReplications(int numNewReplications)
          Adjusts the target number of replications to simulate numNewReplications additional replications.
 int getCompletedReplications()
          Returns the total number of completed replications for the current experiment.
 int getMaxReplications()
          Returns the maximal number of replications to be simulated before an error check.
 int getMinReplications()
          Returns the minimal number of replications to be simulated before an error check.
 int getRequiredNewReplications()
          Returns the approximate number of additional replications to meet an experiment-specific stopping criterion.
 int getTargetReplications()
          Returns the actual target number of replications to be simulated before an error check.
 void init()
          Initializes this simulator for a new experiment.
abstract  void initReplication(int r)
          Initializes the simulation model for a new replication r.
abstract  void initReplicationProbes()
          Initializes any statistical collector used to collect values for replications.
 void performReplication(int r)
          Contains the necessary logic to perform the rth replication of the simulation.
 void setMaxReplications(int maxReps)
          Sets the maximal number of replications required before an error check to maxReps.
 void setMinReplications(int minReps)
          Sets the minimal number of replications required before an error check to minReps.
 void setTargetReplications(int targetReps)
          Sets the target number of simulated replications before an error check to targetReps.
 void simulate()
          Simulates several independent simulation replications of a system.
 String toString()
           
 
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

RepSim

public RepSim(int minReps)
Constructs a new replications-based simulator with a minimal number of runs, minReps, and no maximal number of runs.

Parameters:
minReps - the minimal number of replications.
Throws:
IllegalArgumentException - if the minimal number of replications is smaller than 0.

RepSim

public RepSim(int minReps,
              int maxReps)
Constructs a new replications-based simulator with a minimal number of runs minReps, and a maximal number of runs maxReps. This maximum is used to avoid too long simulations when using sequential sampling.

Parameters:
minReps - the minimal number of replications.
maxReps - the maximal number of replications.
Throws:
IllegalArgumentException - if the minimal or maximal numbers of replications is smaller than 0, or if minReps is greater than maxReps.

RepSim

public RepSim(Simulator sim,
              int minReps)
Equivalent to the first constructor, with the given simulator sim.

Parameters:
sim - the simulator attached to this object.
minReps - the minimal number of replications.
Throws:
IllegalArgumentException - if the minimal number of replications is smaller than 0.

RepSim

public RepSim(Simulator sim,
              int minReps,
              int maxReps)
Equivalent to the second constructor, with the given simulator sim.

Parameters:
sim - the simulator attached to this object.
minReps - the minimal number of replications.
maxReps - the maximal number of replications.
Throws:
IllegalArgumentException - if the minimal or maximal numbers of replications is smaller than 0, or if minReps is greater than maxReps.
Method Detail

getMinReplications

public int getMinReplications()
Returns the minimal number of replications to be simulated before an error check.

Returns:
the minimal number of replications.

setMinReplications

public void setMinReplications(int minReps)
Sets the minimal number of replications required before an error check to minReps. This also updates the maximal number of replications if this maximum is smaller than the new minimum. This will take effect only at the next call to simulate.

Parameters:
minReps - the minimal number of replications.
Throws:
IllegalArgumentException - if the specified number of replications is negative.

getMaxReplications

public int getMaxReplications()
Returns the maximal number of replications to be simulated before an error check. By default, this is set to MAX_VALUE, which is equivalent to infinity in practice.

Returns:
the maximal number of replications.

setMaxReplications

public void setMaxReplications(int maxReps)
Sets the maximal number of replications required before an error check to maxReps. This will take effect only at the next call to simulate.

Parameters:
maxReps - the maximal number of replications.
Throws:
IllegalArgumentException - if the specified number of replications is negative.

getTargetReplications

public int getTargetReplications()
Returns the actual target number of replications to be simulated before an error check. By default, this is initialized to the minimal number of replications, and is increased if new replications are needed. However, it is not decreased by default, even upon a new call to simulate.

Returns:
the target number of replications.

setTargetReplications

public void setTargetReplications(int targetReps)
Sets the target number of simulated replications before an error check to targetReps. The value of targetReps must not be smaller than the minimal number of replications returned by getMinReplications, or greater than the maximal number of replications returned by getMaxReplications.

Parameters:
targetReps - the target number of replications.
Throws:
IllegalArgumentException - if the new target number of replications is smaller than the minimal number of replications.

getCompletedReplications

public int getCompletedReplications()
Returns the total number of completed replications for the current experiment.

Returns:
the number of completed replications.

initReplicationProbes

public abstract void initReplicationProbes()
Initializes any statistical collector used to collect values for replications.


performReplication

public void performReplication(int r)
Contains the necessary logic to perform the rth replication of the simulation. By default, the method calls init to clear the event list, and uses initReplication to initialize the model. It then calls start to start the simulation, calls replicationDone to increment the number of completed replications, and addReplicationObs to add observations to statistical probes.

Parameters:
r - the index of the replication.

initReplication

public abstract void initReplication(int r)
Initializes the simulation model for a new replication r. This method should reset any counter and model state, and schedule needed events. After the method returns, the model should be ready for calling start. This method is called just after the simulator is initialized.

Parameters:
r - the index of the replication.

addReplicationObs

public abstract void addReplicationObs(int r)
Adds statistical observations for the replication r. This method is called just after the replication r is simulated.

Parameters:
r - the index of the replication.

getRequiredNewReplications

public int getRequiredNewReplications()
Returns the approximate number of additional replications to meet an experiment-specific stopping criterion. This is called after getTargetReplications replications are simulated. Since sequential sampling is not used by default, the default implementation returns 0, which stops the simulation after getTargetReplications replications.

Returns:
the number of required additional replications.

init

public void init()
Initializes this simulator for a new experiment. This method resets the number of completed replications to 0, and calls initReplicationProbes to initialize statistical probes. This method is called by simulate.


adjustTargetReplications

public void adjustTargetReplications(int numNewReplications)
Adjusts the target number of replications to simulate numNewReplications additional replications. This method increases the target number of replications by numNewReplications, and sets the target number of replications to getMaxReplications if the new target exceeds the maximal number of replications. This is called by simulate for sequential sampling.

Parameters:
numNewReplications - the number of additionnal replications needed.

simulate

public void simulate()
Simulates several independent simulation replications of a system. When this method is called, the method init is called to initialize the system, and getTargetReplications replications are simulated by using performReplication. When the target number of replications is simulated, the stopping condition is checked using getRequiredNewReplications, and the target number of replications is adjusted using adjustTargetReplications. Additional replications are simulated until the method getRequiredNewReplications returns 0, or getMaxReplications replications are simulated.

Specified by:
simulate in class SimExp

toString

public String toString()
Overrides:
toString in class Object

SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.