Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.stat.mperiods
Class SumMatrixSW

    java.lang.Object
      umontreal.iro.lecuyer.stat.mperiods.SumMatrix
          umontreal.iro.lecuyer.stat.mperiods.SumMatrixSW

All Implemented Interfaces:
  Cloneable, MeasureMatrix

    public class SumMatrixSW

extends SumMatrix

Extends `SumMatrix` to add a sliding window. By using a circular buffer to store the values, it can compute observations for all the periods or for a subset of the periods.

When values are added to this matrix of sums using the `add(int, int, double)` method, the index of a real period needs to be specified. When obtaining a value from this object, the index of a stored period (or simply a period) is needed. If the number of considered periods is smaller than or equal to the number of stored periods, these two index spaces match, no information is lost, and this class behaves exactly as `SumMatrix`. This is the most common case.

However, if the number of real periods is greater than the number of stored periods, some values are lost. Only the values from the last periods are accessible at any time. For example, if a matrix of sums is defined to store 10 periods, values for the periods 0 to 9 are available until the `add(int, int, double)` method is required to add a value in the period 10 or greater. After a value is added into the real period 10, values for the period 0 are lost. The stored periods are shifted and stored periods 0 to 9 then correspond to real periods 1 to 10. This facility allows, for example, to compute a statistic for the last ten minutes, at any times during a simulation.

Field Summary

Fields inherited from class umontreal.iro.lecuyer.stat.mperiods.SumMatrix
`count, numPeriods, numStoredPeriods, numTypes`

Constructor Summary
`SumMatrixSW(int numTypes)` Constructs a new matrix of sums with sliding window for `numTypes` event types and a single period.
`SumMatrixSW(int numTypes, int numPeriods)` Constructs a new matrix of sums with sliding window for `numTypes` event types and `numPeriods` periods.

Method Summary
`void` | `add(int type, int realPeriod, double x)` Adds a new observation `x` of type `type` in the real period `realPeriod`.
`void` | `add(int type, int realPeriod, double x, DoubleDoubleFunction fn)` Similar to `int, double)`, but applies a function `fn` instead of just adding.
`int` | `getFirstRealPeriod()` Returns the real period corresponding to stored period having index 0 when using the `SumMatrix.getMeasure(int, int)` method.
`int` | `getNumRealPeriods()` Returns the number of real periods used by this matrix of sums.
`protected int` | `getPeriod(int p)` Returns the period index corresponding to period `p`.
`void` | `init()` Initializes this matrix of measures for a new simulation replication.
`protected void` | `regroupPeriods(int x, boolean onlyFirst)` Similar to `SumMatrix.regroupPeriods(int)`, but if `onlyFirst` is `false`, do not sum the values in each group.
`void` | `set(int type, int realPeriod, double x)` Sets the sum for event `type` in real period `realPeriod` for this matrix to `x`.
`void` | `setFirstRealPeriod(int firstRealPeriod)` Sets the index of the first real period to `firstRealPeriod`.
`void` | `setNumPeriods(int np)` Sets the number of periods to `np`.

Methods inherited from class umontreal.iro.lecuyer.stat.mperiods.SumMatrix
`clone, getMeasure, getNumMeasures, getNumPeriods, getNumStoredPeriods, regroupPeriods, setNumMeasures, toString`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### SumMatrixSW

    public SumMatrixSW(int numTypes)

  Constructs a new matrix of sums with sliding window for `numTypes` event types and a single period.

  Parameters:
    `numTypes` - the number of event types.
  Throws:
    `IllegalArgumentException` - if the number of types is negative.

### SumMatrixSW

    public SumMatrixSW(int numTypes,
                       int numPeriods)

  Constructs a new matrix of sums with sliding window for `numTypes` event types and `numPeriods` periods.

  Parameters:
    `numTypes` - the number of event types.
    `numPeriods` - the number of stored periods.
  Throws:
    `IllegalArgumentException` - if the number of types or periods is negative.

Method Detail

### getFirstRealPeriod

    public int getFirstRealPeriod()

  Returns the real period corresponding to stored period having index 0 when using the `SumMatrix.getMeasure(int, int)` method. If no period is currently lost, this returns 0.

  Returns:
    the first real period.

### setFirstRealPeriod

    public void setFirstRealPeriod(int firstRealPeriod)

  Sets the index of the first real period to `firstRealPeriod`.

  Parameters:
    `firstRealPeriod` - the new index of the first real period.
  Throws:
    `IllegalArgumentException` - if `firstRealPeriod` is negative.

### getNumRealPeriods

    public int getNumRealPeriods()

  Returns the number of real periods used by this matrix of sums. This corresponds to one plus the maximal value of `realPeriod` given to `add(int, int, double)` or `set(int, int, double)` since the last call to `init()`. In contrast with the similar method `SumMatrix.getNumStoredPeriods()`, the returned value can be greater than `SumMatrix.getNumPeriods()`.

  Returns:
    the number of used real periods.

### add

    public void add(int type,
                    int realPeriod,
                    double x)

  Adds a new observation `x` of type `type` in the real period `realPeriod`. If the given real period is inside the interval `[``getFirstRealPeriod()`, ..., `getFirstRealPeriod()``+` `SumMatrix.getNumPeriods()``- 1]`, which we will call the current interval, a new value is added; the corresponding measure is increased by `x`. If the period is at the left of the current interval, an exception is thrown. Otherwise, the window of observations slides and `getFirstRealPeriod()` is increased; some computed values are then lost.

  Overrides:
    `add` in class `SumMatrix`
  Parameters:
    `type` - the type of the new value.
    `realPeriod` - the real period of the new value.
    `x` - the value being added.
  Throws:
    `ArrayIndexOutOfBoundsException` - if `type` or `realPeriod` are negative, if `type` is greater than or equal to the number of supported types, or if `realPeriod` is smaller than `getFirstRealPeriod()`.

### add

    public void add(int type,
                    int realPeriod,
                    double x,
                    DoubleDoubleFunction fn)

  Description copied from class: `SumMatrix`
  Similar to `int, double)`, but applies a function `fn` instead of just adding. More specifically, if c is the original value in the matrix, and x is the new value, this method adds the value f (c, x) at the given position in the matrix.

  Overrides:
    `add` in class `SumMatrix`

### set

    public void set(int type,
                    int realPeriod,
                    double x)

  Sets the sum for event `type` in real period `realPeriod` for this matrix to `x`. This is the same as the `add(int, int, double)` method except the measure is replaced by `x` instead of being incremented.

  Overrides:
    `set` in class `SumMatrix`
  Parameters:
    `type` - the type of the event.
    `realPeriod` - the real period of the event.
    `x` - the new value.
  Throws:
    `ArrayIndexOutOfBoundsException` - if `type` or `realPeriod` are negative, if `type` is greater than or equal to the number of supported types, or if `realPeriod` is smaller than `getFirstRealPeriod()`.

### init

    public void init()

  Description copied from interface: `MeasureMatrix`
  Initializes this matrix of measures for a new simulation replication. This resets the measured values to 0, or initializes the probes used to compute them.

  Specified by:
    `init` in interface `MeasureMatrix`
  Overrides:
    `init` in class `SumMatrix`

### setNumPeriods

    public void setNumPeriods(int np)

  Description copied from class: `SumMatrix`
  Sets the number of periods to `np`. As with `SumMatrix.setNumMeasures(int)`, added periods are initialized to 0 and the last periods are removed if necessary.

  Specified by:
    `setNumPeriods` in interface `MeasureMatrix`
  Overrides:
    `setNumPeriods` in class `SumMatrix`
  Parameters:
    `np` - the new number of periods.

### regroupPeriods

    protected void regroupPeriods(int x,
                                  boolean onlyFirst)

  Description copied from class: `SumMatrix`
  Similar to `SumMatrix.regroupPeriods(int)`, but if `onlyFirst` is `false`, do not sum the values in each group. `regroupPeriods` with `onlyFirst = false` is internally used by `IntegralMeasureMatrix`.

  Overrides:
    `regroupPeriods` in class `SumMatrix`

### getPeriod

    protected int getPeriod(int p)

  Description copied from class: `SumMatrix`
  Returns the period index corresponding to period `p`. This returns `p` by default, but it is overridden by `SumMatrixSW` to take the sliding window into account.

  Overrides:
    `getPeriod` in class `SumMatrix`
  Parameters:
    `p` - the source period index.
  Returns:
    the target period index.

Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

To submit a bug or ask questions, send an e-mail to Richard Simard.