edu.ou.mlfw.ladder
Class CombinationGenerator

java.lang.Object
  extended by edu.ou.mlfw.ladder.CombinationGenerator

public class CombinationGenerator
extends java.lang.Object


Constructor Summary
CombinationGenerator(int n, int r)
          Create a new CombinationGenerator over the given population and selection sets.
 
Method Summary
static java.math.BigInteger combinations(int n, int r)
          A literal implementation of the combinations formula.
static java.math.BigInteger factorial(int n)
           
static java.math.BigInteger fastCombinations(int n, int r)
          An optimized implementation of the combinations formula.
 int[] getNext()
          Generate next combination (algorithm from Rosen p.
 java.math.BigInteger getNumLeft()
           
 java.math.BigInteger getTotal()
           
 boolean hasMore()
           
static java.math.BigInteger multiplyRange(int smaller, int bigger)
          Multiply the given range of integers (incrementing by 1), inclusive of both smaller and bigger, unless smaller == bigger, in which case that value will be returned.
 void reset()
          Clear the array, and reset the remaining number of combinations to the total calculated number of combinations for (n r).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CombinationGenerator

public CombinationGenerator(int n,
                            int r)
Create a new CombinationGenerator over the given population and selection sets.

Parameters:
n - The size of the total population set.
r - The size of the selection set.
Method Detail

multiplyRange

public static java.math.BigInteger multiplyRange(int smaller,
                                                 int bigger)
Multiply the given range of integers (incrementing by 1), inclusive of both smaller and bigger, unless smaller == bigger, in which case that value will be returned. For example: multiplyRange(2,2) = 2 multiplyRange(2,3) = 6 multiplyRange(2,4) = 24 multiplyRange(4,2) = IllegalArgumentException

Parameters:
smaller - The lower bound of the range to multiply, inclusive.
bigger - The upper bound of the range to multiply, inclusive.
Returns:
The multiplication of smaller to bigger, as a BigInteger.

factorial

public static java.math.BigInteger factorial(int n)
Parameters:
n - The integer value to calculate the factorial of
Returns:
n!

combinations

public static java.math.BigInteger combinations(int n,
                                                int r)
A literal implementation of the combinations formula.

Parameters:
n - The size of the total population set.
r - The size of the selection set.
Returns:
The number of combinations

fastCombinations

public static java.math.BigInteger fastCombinations(int n,
                                                    int r)
An optimized implementation of the combinations formula.

Parameters:
n - The size of the total population set.
r - The size of the selection set.
Returns:
The number of combinations

reset

public void reset()
Clear the array, and reset the remaining number of combinations to the total calculated number of combinations for (n r).


getNumLeft

public java.math.BigInteger getNumLeft()
Returns:
Number of combinations not yet generated

hasMore

public boolean hasMore()
Returns:
Whether there are more combinations remaining.

getTotal

public java.math.BigInteger getTotal()
Returns:
Total number of combinations

getNext

public int[] getNext()
Generate next combination (algorithm from Rosen p. 286)

Returns:
The next combination, as an int[] the length of the selection set size, with values corresponding to indices of the population set if it were an array. The returned array MUST be treated as read-only, and should not be shared. If persistence is required, the returned array MUST be copied.