combinatorics
Class Combinator<T>

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

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

A class that sequentially returns all combinations of a certain number out of an array of given elements. Thanks to Michael Gillegand for the base implementation: http://www.merriampark.com/comb.htm.

Author:
Hendrik Maryns

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

Constructor Detail

Combinator

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

Parameters:
elements - The elements of which combinations have to be computed.
r - The size of the combinations to compute.
Method Detail

initialiseTotal

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

Specified by:
initialiseTotal in class CombinatoricOperator<T>
Parameters:
n - The number of elements the operator works on.
r - The size of the arrays to return.
Returns:
The factorial of the number of elements divided by the factorials of the size of the combinations and the number of elements minus the size of the combinations. That is, with the number of elements = n and the size of the combinations = r: n n! ( ) = --------- r (n-r)!r!
See Also:
CombinatoricOperator.initialiseTotal(int, int)

computeNext

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

Specified by:
computeNext in class CombinatoricOperator<T>
See Also:
CombinatoricOperator.computeNext()


Copyright © 2008 This is an undergraduate research project at the University of Kent Computing Laboratory. All Rights Reserved.