Class Combinatorics


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

      • arrayComparator

        static final java.util.Comparator<int[]> arrayComparator
    • Constructor Detail

      • Combinatorics

        private Combinatorics()
    • Method Detail

      • 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:
        IntCompositions
      • 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:
        IntDistinctTuples
      • 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:
        IntDistinctTuples
      • 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
      • 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:
        IntDistinctTuples
      • 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:
        IntDistinctTuples