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 SumMatrix

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

All Implemented Interfaces:
  Cloneable, MeasureMatrix

Direct Known Subclasses:
  ContactSumMatrix, SumMatrixSW

    public class SumMatrix

extends Object
implements MeasureMatrix, Cloneable

This matrix of measures can be used to compute sums of values, or the number of occurrences of events. It supports several types of observations on several simulation periods. This class supports every optional operation specified by the `MeasureMatrix` interface.

Field Summary
`protected double[]` | `count` Array containing the sums, in row major order.
`protected int` | `numPeriods` Number of periods.
`protected int` | `numStoredPeriods` Number of stored periods.
`protected int` | `numTypes` Number of types of events.

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

Method Summary
`void` | `add(int type, int period, double x)` Adds a new observation `x` of type `type` in the period `period`.
`void` | `add(int type, int period, double x, DoubleDoubleFunction fn)` Similar to `int, double)`, but applies a function `fn` instead of just adding.
`SumMatrix` | `clone()`
`double` | `getMeasure(int i, int p)` Returns the measure corresponding to the index `i` and period `p`.
`int` | `getNumMeasures()` Returns the number of measures calculated by the implementation of this interface.
`int` | `getNumPeriods()` Returns the number of periods stored into this matrix of measures.
`int` | `getNumStoredPeriods()` Returns the total number of periods stored in 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.
`void` | `regroupPeriods(int x)` Increases the length of stored periods by regrouping them.
`protected void` | `regroupPeriods(int x, boolean onlyFirst)` Similar to `regroupPeriods(int)`, but if `onlyFirst` is `false`, do not sum the values in each group.
`void` | `set(int type, int period, double x)` Sets the sum for event `type` in period `period` for this matrix to `x`.
`void` | `setNumMeasures(int nm)` Sets the number of measures to `nm`.
`void` | `setNumPeriods(int np)` Sets the number of periods to `np`.
`String` | `toString()`

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

Field Detail

### numTypes

    protected int numTypes

  Number of types of events.

### numPeriods

    protected int numPeriods

  Number of periods.

### numStoredPeriods

    protected int numStoredPeriods

  Number of stored periods.

### count

    protected double[] count

  Array containing the sums, in row major order. If `i` is an event type and `p` is a stored period, the value at `(i, p)` is given by `count[i + numTypes*p]`.

Constructor Detail

### SumMatrix

    public SumMatrix(int numTypes)

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

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

### SumMatrix

    public SumMatrix(int numTypes,
                     int numPeriods)

  Constructs a new matrix of sums 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

### getNumStoredPeriods

    public int getNumStoredPeriods()

  Returns the total number of periods stored in this matrix of sums. This corresponds to p + 1 if p is the maximal period index given to `add(int, int, double)` or `set(int, int, double)` since the last call to `init()`. If `add(int, int, double)` or `set(int, int, double)` were not called since the last initialization, this returns 0. The returned value cannot be larger than the number of stored periods (`getNumPeriods()`).

  Returns:
    the number of used periods.

### add

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

  Adds a new observation `x` of type `type` in the period `period`.

  Parameters:
    `type` - the type of the new value.
    `period` - the period of the new value.
    `x` - the value being added.
  Throws:
    `ArrayIndexOutOfBoundsException` - if `type` or `period` are negative, if `type` is greater than or equal to the number of supported types, or if `period` is greater than or equal to the number of supported periods.

### add

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

  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.

### set

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

  Sets the sum for event `type` in period `period` 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.

  Parameters:
    `type` - the type of the event.
    `period` - the period of the event.
    `x` - the new value.
  Throws:
    `ArrayIndexOutOfBoundsException` - if `type` or `period` are negative, if `type` is greater than or equal to the number of supported types, or if `period` is greater than or equal to the number of supported periods.

### 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`

### getNumMeasures

    public int getNumMeasures()

  Description copied from interface: `MeasureMatrix`
  Returns the number of measures calculated by the implementation of this interface.

  Specified by:
    `getNumMeasures` in interface `MeasureMatrix`
  Returns:
    the number of computed values.

### setNumMeasures

    public void setNumMeasures(int nm)

  Sets the number of measures to `nm`. If `nm` is greater than `getNumMeasures()`, new measures are added and initialized to 0. If `nm` is smaller than `getNumMeasures()`, the last `getNumMeasures()``- nm` measures are removed. Otherwise, nothing happens.

  Specified by:
    `setNumMeasures` in interface `MeasureMatrix`
  Parameters:
    `nm` - the new number of measures.
  Throws:
    `IllegalArgumentException` - if the given number is negative.

### getNumPeriods

    public int getNumPeriods()

  Description copied from interface: `MeasureMatrix`
  Returns the number of periods stored into this matrix of measures.

  Specified by:
    `getNumPeriods` in interface `MeasureMatrix`
  Returns:
    the number of stored periods.

### setNumPeriods

    public void setNumPeriods(int np)

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

  Specified by:
    `setNumPeriods` in interface `MeasureMatrix`
  Parameters:
    `np` - the new number of periods.
  Throws:
    `IllegalArgumentException` - if the given number is negative.

### getMeasure

    public double getMeasure(int i,
                             int p)

  Description copied from interface: `MeasureMatrix`
  Returns the measure corresponding to the index `i` and period `p`.

  Specified by:
    `getMeasure` in interface `MeasureMatrix`
  Parameters:
    `i` - the index of the measure.
    `p` - the period of the measure.
  Returns:
    the corresponding value.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### regroupPeriods

    public void regroupPeriods(int x)

  Description copied from interface: `MeasureMatrix`
  Increases the length of stored periods by regrouping them. If this method is supported, for `p = 0`, ..., `MeasureMatrix.getNumPeriods()``/x - 1`, it sums the values for periods `xp`, ...,`xp+x-1`, and stores the results in period `p` whose length will be `x` times the length of original periods. If the number of periods is not a multiple of `x`, an additional period is used to contain the remaining sums of values. The unused periods are zeroed for future use. This method can be useful for memory management when using batch means to estimate steady-state performance measures.

  Specified by:
    `regroupPeriods` in interface `MeasureMatrix`
  Parameters:
    `x` - the number of periods per group.

### regroupPeriods

    protected void regroupPeriods(int x,
                                  boolean onlyFirst)

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

### clone

    public SumMatrix clone()

  Overrides:
    `clone` in class `Object`

### getPeriod

    protected int getPeriod(int p)

  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.

  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.