## 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 Summary

Constructors
Constructor Description
```BoundMax​(int n, int bound)```
Constructs an instance of the BoundMax problem.
• ### Method Summary

All Methods
Modifier and Type Method Description
`int` `cost​(IntegerVector candidate)`
Computes the cost of a candidate solution to the problem instance.
`boolean` `equals​(Object other)`
`boolean` `isMinCost​(int cost)`
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.
`int` `minCost()`
A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
`int` `value​(IntegerVector candidate)`
Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
• ### Methods inherited from class org.cicirello.search.operators.integers.IntegerVectorInitializer

`createCandidateSolution, hashCode, split`
• ### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface org.cicirello.search.problems.IntegerCostOptimizationProblem

`getSolutionCostPair`
• ### Constructor Detail

• #### BoundMax

```public BoundMax​(int n,
int bound)```
Constructs an instance of the BoundMax problem.
Parameters:
`n` - The length of the instance (length of the array under optimization).
`bound` - The maximum value allowed for each integer.
Throws:
`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>`
Parameters:
`candidate` - The candidate solution to evaluate.
Returns:
The cost of the candidate solution. Lower cost means better solution.
• #### value

`public int value​(IntegerVector candidate)`
Description copied from interface: `IntegerCostOptimizationProblem`
Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
Specified by:
`value` in interface `IntegerCostOptimizationProblem<IntegerVector>`
Parameters:
`candidate` - The candidate solution to evaluate.
Returns:
The actual optimization value of the candidate 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>`
Returns:
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>`
Parameters:
`cost` - The cost to check.
Returns:
true if cost is equal to the minimum theoretical cost,
• #### equals

`public boolean equals​(Object other)`
Overrides:
`equals` in class `IntegerVectorInitializer`