Class BoundMax

  • All Implemented Interfaces:
    Splittable<Initializer<IntegerVector>>, Initializer<IntegerVector>, IntegerCostOptimizationProblem<IntegerVector>, Problem<IntegerVector>

    public final class BoundMax
    extends IntegerVectorInitializer
    implements IntegerCostOptimizationProblem<IntegerVector>

    The BoundMax class is an implementation of a generalization of the well-known OneMax problem, often used in benchmarking genetic algorithms and other metaheuristics.

    In the OneMax problem, the metaheuristic is searching the space of bit-strings of length n for the bit-string with the most bits equal to a 1. It originated as a test problem for genetic algorithms, where the standard form of a genetic algorithm represents solutions to the problem with a string of bits. The OneMax problem offers a test problem with a known optimal solution, a bit-string of all 1s. For example, if n=8, then the optimal solution is: 11111111.

    BoundMax generalizes OneMax to vectors of integers such that each integer is bound in the interval [0,B] for some B ≥ 1. The problem is to find the vector of length n with maximum number of integers equal to B. The optimal solution is thus n copies of B. For example, if n is 8, the optimal solution is [B, B, B, B, B, B, B, B]. The OneMax problem is the special case when B=1.

    The value method simply counts the number of components equal to B. The problem is to maximize this count. Thus, as a cost function, the cost method counts the number of components not equal to B, where the minimum cost is thus 0.

    The BoundMax class extends IntegerVectorInitializer to ensure that metaheuristics solving an instance have access to a correct means of generating valid vectors within the search space (correct length and components in the interval [0,B].

    Although technically you can use the BoundMax class, which evaluates IntegerVector objects, using a bound B=1, to define the OneMax problem, you should instead use the OneMax class for the original OneMax problem. The OneMax class evaluates BitVector objects, which is a proper implementation of an indexable vector of bits.

    • Constructor Detail

      • BoundMax

        public BoundMax​(int n,
                        int bound)
        Constructs an instance of the BoundMax problem.
        n - The length of the instance (length of the array under optimization).
        bound - The maximum value allowed for each integer.
        IllegalArgumentException - if bound is negative
        NegativeArraySizeException - if n is negative
    • Method Detail

      • cost

        public int cost​(IntegerVector candidate)
        Description copied from interface: IntegerCostOptimizationProblem
        Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.
        Specified by:
        cost in interface IntegerCostOptimizationProblem<IntegerVector>
        candidate - The candidate solution to evaluate.
        The cost of the candidate solution. Lower cost means better solution.
      • minCost

        public int minCost()
        Description copied from interface: IntegerCostOptimizationProblem
        A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution. The default implementation returns Integer.MIN_VALUE.
        Specified by:
        minCost in interface IntegerCostOptimizationProblem<IntegerVector>
        A lower bound on the minimum theoretical cost of the problem instance.
      • isMinCost

        public boolean isMinCost​(int cost)
        Description copied from interface: IntegerCostOptimizationProblem
        Checks if a given cost value is equal to the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
        Specified by:
        isMinCost in interface IntegerCostOptimizationProblem<IntegerVector>
        cost - The cost to check.
        true if cost is equal to the minimum theoretical cost,