Class SublistGenerator

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

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

A valid combination for the sublists 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.

Works by calling ChoiceGenerator with increasingly larger values of a.

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

Author:
josephramsey
  • Constructor Details

    • SublistGenerator

      public SublistGenerator(int a, int depth)
      Constructs a new generator for sublists for a list of size b taken a at a time. 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 size of the list being selected from.
      depth - the maximum number of elements selected.
  • Method Details

    • getNumCombinations

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

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

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

      public String toString()
      Overrides:
      toString in class Object
    • getA

      public int getA()
      Returns:
      Ibid.