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.

Version:
$Id: $Id
Author:
josephramsey
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChoiceGenerator(int a, int b)
    Constructs a new choice generator for a choose b.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Getter for the field a.
    int
    Getter for the field b.
    static int
    getNumCombinations(int a, int b)
    Returns the number of combinations of a choose b.
    static double
    logCombinations(int a, int b)
    Returns the natural logarithm of the number of combinations of a choose b.
    int[]
    next.
    static void
    testPrint(int a, int b)
    This static method will print the series of combinations for a choose b to System.out.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
      Returns the number of combinations of a choose b.
      Parameters:
      a - the number of objects being selected from.
      b - the number of objects in the desired selection.
      Returns:
      the number of combinations of a choose b.
    • logCombinations

      public static double logCombinations(int a, int b)
      Returns the natural logarithm of the number of combinations of a choose b.
      Parameters:
      a - the number of objects being selected from.
      b - the number of objects in the desired selection.
      Returns:
      the natural logarithm of the number of combinations of a choose b.
    • next

      public int[] next()

      next.

      Returns:
      the next combination in the series, or null if the series is finished.
    • getA

      public int getA()

      Getter for the field a.

      Returns:
      Ibid.
    • getB

      public int getB()

      Getter for the field b.

      Returns:
      Ibid.