Class ChoiceGenerator

java.lang.Object
edu.cmu.tetrad.util.ChoiceGenerator

public final class ChoiceGenerator extends Object
Generates (nonrecursively) all of the combinations of a choose b, where a, b are nonnegative integers and a >= b. The values of a and b are given in the constructor, and the sequence of choices is obtained by repeatedly calling the next() method. When the sequence is finished, null is returned.

A valid combination for the sequence of combinations for a choose b generated by this class is an array x[] of b integers i, 0 <= i < a, such that x[j] < x[j + 1] for each j from 0 to b - 1.

To see what this class does, try calling ChoiceGenerator.testPrint(5, 3), for instance.

Author:
josephramsey
  • Constructor Details

    • ChoiceGenerator

      public ChoiceGenerator(int a, int b)
      Constructs a new choice generator for a choose b. Once this initialization has been performed, successive calls to next() will produce the series of combinations. To begin a new series at any time, call this init method again with new values for a and b.
      Parameters:
      a - the number of objects being selected from.
      b - the number of objects in the desired selection.
  • Method Details

    • testPrint

      public static void testPrint(int a, int b)
      This static method will print the series of combinations for a choose b to System.out.
      Parameters:
      a - the number of objects being selected from.
      b - the number of objects in the desired selection.
    • getNumCombinations

      public static int getNumCombinations(int a, int b)
    • logCombinations

      public static double logCombinations(int a, int b)
    • next

      public int[] next()
      Returns:
      the next combination in the series, or null if the series is finished.
    • getA

      public int getA()
      Returns:
      Ibid.
    • getB

      public int getB()
      Returns:
      Ibid.