Class 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.
    • 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 element
        interval - 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 element
        interval - the batching interval, must be greater than 0
        name - 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,
                                                                    java.lang.String name)
        Adds the supplied TimeWeighted variable to the batching
        Parameters:
        tw - the TimeWeighted variable to add
        name - 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 add
        minNumBatches - minimum number of batches
        minBatchSize - minimum batch size
        maxNBMultiple - batch size multiple
        name - 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 replication
        warmUp - the warm up period for the replication
        Returns:
        the recommended batching interval
      • beforeReplication

        protected void beforeReplication()
        Description copied from class: ModelElement
        This 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:
        beforeReplication in class ModelElement
      • initialize

        protected void initialize()
        Description copied from class: ModelElement
        This 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:
        initialize in class ModelElement
      • 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: ModelElement
        Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String
        Overrides:
        asString in class ModelElement
        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