Class EnumerationCartesian

  • All Implemented Interfaces:
    Iterator<int[]>
    Direct Known Subclasses:
    EnumerationOfCombinations

    public class EnumerationCartesian
    extends EnumerationAbstract
    This class allows iterating over all tuples of a given length from a given set of numbers (of possibilities at each position). Execute the main method for an illustration.
    • Field Detail

      • values

        protected final int[][] values
        Gives the sets of values on which the tuples will be built. values[i] is a 1-dimensional array with all possibles (ordered) values at position i in a tuple.
    • Constructor Detail

      • EnumerationCartesian

        public EnumerationCartesian​(int[][] values,
                                    boolean clone)
        Builds an object that can be used for enumerating tuples, using the specified sets of values. If the specified Boolean is true the specified 2-dimensional array is cloned.
        Parameters:
        values - the sets of values on which the tuples will be built
        clone - if true the specified 2-dimensional array is cloned
      • EnumerationCartesian

        public EnumerationCartesian​(int[][] values)
        Builds an object that can be used for enumerating tuples, using the specified sets of values.
        Parameters:
        values - the sets of values on which the tuples will be built
      • EnumerationCartesian

        public EnumerationCartesian​(int... nValues)
        Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple will contain a value at position i in the range 0 to nValues[i].length-1.
        Parameters:
        nValues - indicates how many values are possible at each position
      • EnumerationCartesian

        public EnumerationCartesian​(int nValues,
                                    int tupleLength)
        Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple has the specified length and will contain a value at position i in the range 0 to nValues-1.
        Parameters:
        nValues - the number of values used to form tuples
        tupleLength - the length of each tuple
    • Method Detail

      • tuplesWithDiffValuesSummingTo

        public static int[][] tuplesWithDiffValuesSummingTo​(int limit,
                                                            int nValues,
                                                            int tupleLength,
                                                            int offset)
        Returns an array with all tuples of the specified length such that for each tuple:
        • at each position, a value is between 0 (inclusive) and nValues (exclusive)
        • all values are all different
        • the sum of the values in the tuple is equal to the specified limit
        Parameters:
        limit - the integer denoting the limit of the sum
        nValues - indicates how many values are possible at each position
        tupleLength - the length of each tuple in the enumeration
        offset - the value that must be systematically added to each value of each tuple
        Returns:
        an array with all tuples of the specified length that respect a sum equality and an allDifferent restriction
      • valAt

        protected int valAt​(int i)
        Description copied from class: EnumerationAbstract
        Returns the value of the current tuple at the specified position.
        Specified by:
        valAt in class EnumerationAbstract
        Parameters:
        i - the position of an integer in the tuple
        Returns:
        the value of the current tuple at the specified position
      • main

        public static void main​(String[] args)