Package jsl.modeling.elements.variable
Class TWBatchingElement
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.variable.TWBatchingElement
-
- All Implemented Interfaces:
ObservableIfc,GetNameIfc,IdentityIfc
public class TWBatchingElement extends SchedulingElement
This class controls the batching of time weighted variables within the Model. The batch interval is used to schedule events during a replication and must be the same throughout the replication. If the supplied interval is 0.0, then the method getApproximateBatchInterval() will be used to determine the interval for the replication. Time-based variables (TimeWeighted) are first discretized based on a batching interval. The default batching interval is based on the value of the initial number of batches. This is by default set to DEFAULT_NUM_TW_BATCHES = 512. These initial batches are then rebatched according to the procedures within BatchStatistic Use addTimeWeighted(TimeWeighted tw) to add TimeWeighted variables to the batching.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classTWBatchingElement.TWBatchStatisticObserver-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_BATCH_INTERVALA constant for the default batch interval for a replication If there is no run length specified and the user turns on default batching, then the time interval between batches will be equal to this value.static doubleDEFAULT_NUM_TW_BATCHESA constant for the default number of batches for TimeWeighted variables.-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Constructor Summary
Constructors Constructor Description TWBatchingElement(ModelElement modelElement)Creates a time weighted batching elementTWBatchingElement(ModelElement modelElement, double interval)Creates a time weighted batching elementTWBatchingElement(ModelElement modelElement, double interval, java.lang.String name)Creates a time weighted batching element
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TWBatchingElement.TWBatchStatisticObserveradd(TimeWeighted tw)Adds the supplied TimeWeighted variable to the batchingTWBatchingElement.TWBatchStatisticObserveradd(TimeWeighted tw, int minNumBatches, int minBatchSize, int maxNBMultiple, java.lang.String name)Adds the supplied TimeWeighted variable to the batchingTWBatchingElement.TWBatchStatisticObserveradd(TimeWeighted tw, java.lang.String name)Adds the supplied TimeWeighted variable to the batchingjava.lang.StringasString()Allows sub-classes to provide more detail than toString() to represent the ModelElement as a Stringprotected voidbatch()The batch method is called during each replication when the batching event occurs This method ensures that each time weighted variable gets within replication batch statistics collected across batchesprotected voidbeforeReplication()This method should be overridden by subclasses that need actions performed prior to each replication.java.util.List<BatchStatistic>getAllBatchStatisitcs()Returns a list of summary statistics on all TimeWeighted variables.java.util.Map<TimeWeighted,BatchStatistic>getAllBatchStatisticsAsMap()protected doublegetApproximateBatchInterval()This method returns a suggested batching interval based on the length of the run, the warm up period, and default number of batches.doublegetApproximateBatchInterval(double repLength, double warmUp)This method returns a suggested batching interval based on the length of of the replication and warm up length for TimeWeighted variables.intgetBatchEventPriority()Gets the batch event prioritydoublegetBatchInterval()Gets the current batch interval length for time weighted variablesBatchStatisticgetBatchStatistic(TimeWeighted tw)Returns a statistical summary BatchStatistic on the TimeWeighted variable across the observed batches This returns a copy of the summary statistics.java.lang.StringgetCSVHeader(TimeWeighted tw)Gets the CSV Header for the TimeWeightedjava.lang.StringgetCSVRow(TimeWeighted tw)Gets the CSV row for the TimeWeighteddoublegetTimeWeightedStartingNumberOfBatches()The starting number of batches, used to determine the batch interval when it is not explicitly set.TWBatchingElement.TWBatchStatisticObservergetTWBatchStatisticObserver(TimeWeighted tw)Look up the TWBatchStatisticObserver for the given TimeWeighted variableprotected voidinitialize()This method should be overridden by subclasses that need actions performed to initialize prior to a replication.booleanisBatchEventScheduled()Checks if a batching event has been scheduled for this model elementvoidremove(TimeWeighted tw)Removes the supplied TimeWeighted variable from the batchingvoidremoveAll()Removes all previously added TimeWeighted from the batchingprotected voidsetBatchEventPriority(int priority)Sets the batch event priority.voidsetBatchInterval(double batchInterval)Sets the batch interval length.voidsetTimeWeightedStartingNumberOfBatches(int numBatches)Sets the initial number of batches for time-weighted variables The number of initial batches is not recommended to be less than 10.-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication, afterReplication_, beforeExperiment, beforeExperiment_, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, initialize_, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removedFromModel, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate, timedUpdate_, toString, update, useControls, warmUp, warmUp_, week
-
-
-
-
Field Detail
-
DEFAULT_BATCH_INTERVAL
public static final double DEFAULT_BATCH_INTERVAL
A constant for the default batch interval for a replication If there is no run length specified and the user turns on default batching, then the time interval between batches will be equal to this value. The default value is 10.0- See Also:
- Constant Field Values
-
DEFAULT_NUM_TW_BATCHES
public static final double DEFAULT_NUM_TW_BATCHES
A constant for the default number of batches for TimeWeighted variables. This value is used in the calculation of the approximate batching interval if batching is turned on and there is a finite run length. If the run length is finite, then the batch interval is approximated as follows: t = length of replication - length of warm up n = getTimeWeightedStartingNumberOfBatches() batching interval = t/n DEFAULT_NUM_TW_BATCHES = 512.0- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TWBatchingElement
public TWBatchingElement(ModelElement modelElement)
Creates a time weighted batching element- Parameters:
modelElement- the model element
-
TWBatchingElement
public TWBatchingElement(ModelElement modelElement, double interval)
Creates a time weighted batching element- Parameters:
modelElement- the model elementinterval- the batching interval, must be greater than 0
-
TWBatchingElement
public TWBatchingElement(ModelElement modelElement, double interval, java.lang.String name)
Creates a time weighted batching element- Parameters:
modelElement- the model elementinterval- the batching interval, must be greater than 0name- a name for the element
-
-
Method Detail
-
getTWBatchStatisticObserver
public final TWBatchingElement.TWBatchStatisticObserver getTWBatchStatisticObserver(TimeWeighted tw)
Look up the TWBatchStatisticObserver for the given TimeWeighted variable- Parameters:
tw- the TimeWeighted variable- Returns:
- the TWBatchStatisticObserver
-
add
public final TWBatchingElement.TWBatchStatisticObserver add(TimeWeighted tw)
Adds the supplied TimeWeighted variable to the batching- Parameters:
tw- the TimeWeighted variable to add- Returns:
- the TWBatchStatisticObserver
-
add
public final TWBatchingElement.TWBatchStatisticObserver add(TimeWeighted tw, java.lang.String name)
Adds the supplied TimeWeighted variable to the batching- Parameters:
tw- the TimeWeighted variable to addname- name for BatchStatistic- Returns:
- the TWBatchStatisticObserver
-
add
public final TWBatchingElement.TWBatchStatisticObserver add(TimeWeighted tw, int minNumBatches, int minBatchSize, int maxNBMultiple, java.lang.String name)
Adds the supplied TimeWeighted variable to the batching- Parameters:
tw- the TimeWeighted variable to addminNumBatches- minimum number of batchesminBatchSize- minimum batch sizemaxNBMultiple- batch size multiplename- name for BatchStatistic- Returns:
- the TWBatchStatisticObserver
-
remove
public final void remove(TimeWeighted tw)
Removes the supplied TimeWeighted variable from the batching- Parameters:
tw- the TimeWeighted to be removed
-
removeAll
public final void removeAll()
Removes all previously added TimeWeighted from the batching
-
getBatchStatistic
public final BatchStatistic getBatchStatistic(TimeWeighted tw)
Returns a statistical summary BatchStatistic on the TimeWeighted variable across the observed batches This returns a copy of the summary statistics.- Parameters:
tw- the TimeWeighted to look up- Returns:
- the returned BatchStatistic
-
getAllBatchStatisitcs
public final java.util.List<BatchStatistic> getAllBatchStatisitcs()
Returns a list of summary statistics on all TimeWeighted variables. The list is a copy of originals.- Returns:
- the filled up list
-
getAllBatchStatisticsAsMap
public final java.util.Map<TimeWeighted,BatchStatistic> getAllBatchStatisticsAsMap()
- Returns:
- a map of all batch statistics with the TimeWeighted variable as the key
-
setBatchEventPriority
protected final void setBatchEventPriority(int priority)
Sets the batch event priority.- Parameters:
priority- The batch event priority, lower means earlier
-
getBatchEventPriority
public final int getBatchEventPriority()
Gets the batch event priority- Returns:
- The batch event priority
-
getBatchInterval
public final double getBatchInterval()
Gets the current batch interval length for time weighted variables- Returns:
- The batch interval as time
-
getTimeWeightedStartingNumberOfBatches
public final double getTimeWeightedStartingNumberOfBatches()
The starting number of batches, used to determine the batch interval when it is not explicitly set.- Returns:
- number of batches
-
setTimeWeightedStartingNumberOfBatches
public final void setTimeWeightedStartingNumberOfBatches(int numBatches)
Sets the initial number of batches for time-weighted variables The number of initial batches is not recommended to be less than 10.- Parameters:
numBatches- must be bigger than 0
-
setBatchInterval
public final void setBatchInterval(double batchInterval)
Sets the batch interval length. Changing this during a replication has no effect. The batch interval is used to schedule events during a replication and must be the same throughout the replication. If the supplied interval is 0.0, then the method getApproximateBatchInterval() will be used to determine the interval for the replication- Parameters:
batchInterval- The batch interval size in time units must be >=0, if it is larger than run length it will not occur
-
isBatchEventScheduled
public final boolean isBatchEventScheduled()
Checks if a batching event has been scheduled for this model element- Returns:
- True means that it has been scheduled.
-
getApproximateBatchInterval
protected final double getApproximateBatchInterval()
This method returns a suggested batching interval based on the length of the run, the warm up period, and default number of batches.- Returns:
- a double representing an approximate batch interval
-
getApproximateBatchInterval
public final double getApproximateBatchInterval(double repLength, double warmUp)This method returns a suggested batching interval based on the length of of the replication and warm up length for TimeWeighted variables. This value is used in the calculation of the approximate batching interval if batching is turned on and there is a finite run length. If the run length is finite, then the batch interval is approximated as follows: t = length of replication - length of warm up n = getTimeWeightedStartingNumberOfBatches() batching interval = t/n DEFAULT_NUM_TW_BATCHES = 512.0- Parameters:
repLength- the length of the replicationwarmUp- the warm up period for the replication- Returns:
- the recommended batching interval
-
beforeReplication
protected void beforeReplication()
Description copied from class:ModelElementThis method should be overridden by subclasses that need actions performed prior to each replication. It is called prior to each replication and can be used to initialize the model element. It is called before initialize() is called.- Overrides:
beforeReplicationin classModelElement
-
initialize
protected void initialize()
Description copied from class:ModelElementThis method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called- Overrides:
initializein classModelElement
-
batch
protected void batch()
The batch method is called during each replication when the batching event occurs This method ensures that each time weighted variable gets within replication batch statistics collected across batches
-
asString
public java.lang.String asString()
Description copied from class:ModelElementAllows sub-classes to provide more detail than toString() to represent the ModelElement as a String- Overrides:
asStringin classModelElement- Returns:
- a detailed String representation
-
getCSVRow
public java.lang.String getCSVRow(TimeWeighted tw)
Gets the CSV row for the TimeWeighted- Parameters:
tw-- Returns:
- the data as a string
-
getCSVHeader
public java.lang.String getCSVHeader(TimeWeighted tw)
Gets the CSV Header for the TimeWeighted- Parameters:
tw- the time weighted variable- Returns:
- the header
-
-