Class Combinatorics

java.lang.Object
cc.redberry.combinatorics.Combinatorics

public final class Combinatorics extends Object
This class provides factory and utility methods for combinatorics infrastructure.
Since:
1.0
  • Field Details

    • arrayComparator

      static final Comparator<int[]> arrayComparator
  • Constructor Details

    • Combinatorics

      private Combinatorics()
  • Method Details

    • combinations

      public static CombinatorialIterator<int[]> combinations(int n, int k)
      Iterator over all k-combinations from {code n}.
      Parameters:
      n - combination length
      k - the total
    • combinationsWithPermutations

      public static CombinatorialIterator<int[]> combinationsWithPermutations(int n, int k)
      Iterator over all k-combinations with permutations from {code n}.
      Parameters:
      n - combination length
      k - the total
    • permutations

      public static CombinatorialIterator<int[]> permutations(int n)
      Iterator over all permutations of the specified length
    • compositions

      public static CombinatorialIterator<int[]> compositions(int integer, int nPartitions)
      Iterator over all compositions of integer into nPartitions
      Parameters:
      integer - the sum
      nPartitions - number of partitions
      See Also:
    • distinctTuples

      public static CombinatorialIterator<int[]> distinctTuples(int[]... sets)
      Iterator over all distinct N-tuples, which can be chosen from N specified sets of integers.
      Parameters:
      sets - array of sets of integers
      See Also:
    • deepClone

      private static int[][] deepClone(int[][] sets)
    • tuples

      public static CombinatorialIterator<int[]> tuples(int... bounds)
      Iterator over all N-tuples (not necessary to be distinct), which can be chosen from N arrays of integers of the form arrayi = [0, 1, 2, ..., Ki]
      Parameters:
      bounds - the bounds on the tuple elements
      See Also:
    • map

      private static <T> T[] map(T[] array, int[] indices, Combinatorics.ArrayFactory<T> factory)
    • permutations

      public static <T> CombinatorialIterator<T[]> permutations(T[] input)
      Iterator over all permutations of the specified array
    • combinations

      public static <T> CombinatorialIterator<T[]> combinations(T[] input, int k)
      Iterator over all k-combinations from the specified array
    • combinationsWithPermutations

      public static <T> CombinatorialIterator<T[]> combinationsWithPermutations(T[] input, int k)
      Iterator over all k-combinations with permutations from the specified array
    • map

      private static <T> T[] map(T[][] arrays, int[] indices, Combinatorics.ArrayFactory<T> factory)
    • indices

      private static int[] indices(int length)
    • distinctTuples

      public static <T> CombinatorialIterator<T[]> distinctTuples(T[]... sets)
      Iterator over all N-tuples of elements at different positions, which can be chosen from N specified sets of elements.
      Parameters:
      sets - array of sets of integers
      See Also:
    • tuples

      public static <T> CombinatorialIterator<T[]> tuples(T[]... sets)
      Iterator over all N-tuples, which can be chosen from N specified sets of integers.
      Parameters:
      sets - array of sets of integers
      See Also: