de.uni_tuebingen.sfb.lichtenstein.combinatorics
Class VariatorWithRepetition<T>

java.lang.Object
  extended by de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator<T>
      extended by de.uni_tuebingen.sfb.lichtenstein.combinatorics.VariatorWithRepetition<T>
Type Parameters:
T - The type of the elements of which variations are to be returned.
All Implemented Interfaces:
java.lang.Iterable<T[]>, java.util.Iterator<T[]>

public final class VariatorWithRepetition<T>
extends CombinatoricOperator<T>

A class that sequentially returns all variations with repetition of a certain number out of an array of given elements.

Author:
Hendrik Maryns

Field Summary
 
Fields inherited from class de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator
elements, indices
 
Constructor Summary
VariatorWithRepetition(T[] elements, int r)
          Initialize a new variator, with given elements and size of the arrays to be returned.
 
Method Summary
protected  void computeNext()
          Compute the next array of indices.
protected  void initializeIndices()
          Initialize the array of indices.
protected  int initializeTotal(int n, int r)
          Compute the total number of elements to return.
 
Methods inherited from class de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator
collectionToArray, factorial, getNumLeft, getTotal, hasNext, iterator, next, remove, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariatorWithRepetition

public VariatorWithRepetition(T[] elements,
                              int r)
Initialize a new variator, with given elements and size of the arrays to be returned.

Parameters:
elements - The elements of which variations have to be computed.
r - The size of the variations to compute.
Precondition:
r should not be smaller than 0.
| 0 <= r
Postcondition:
The total number of iterations is set to the number of elements to the rth power.
| new.getTotal() == BigInteger.valueOf(elements.length).pow(r)
Postcondition:
The number of variations left is set to the total number.
| new.getNumLeft() == new.getTotal()
Method Detail

initializeIndices

protected void initializeIndices()
Initialize the array of indices. For variations with repetition, it needs to be initialized with all 0s.

Overrides:
initializeIndices in class CombinatoricOperator<T>

initializeTotal

protected int initializeTotal(int n,
                              int r)
Compute the total number of elements to return.

Specified by:
initializeTotal in class CombinatoricOperator<T>
Parameters:
n - The number of elements the operator works on.
r - The size of the arrays to return.

computeNext

protected void computeNext()
Compute the next array of indices.

Specified by:
computeNext in class CombinatoricOperator<T>