- All Implemented Interfaces:
- IntegerCostOptimizationProblem<BitVector>,- Problem<BitVector>
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. The OneMax problem has no local optima, and thus should be trivially easy for hill climbers.
It was originally posed as a maximization problem because it was originally defined as a
 fitness function for a genetic algorithm. The value method simply counts the
 number of bits in the BitVector equal to 1, which is to be maximized. Thus, as a cost function,
 the cost method counts the number of bits not equal to 1, where the minimum cost is
 thus 0, corresponding to the case of maximal number of 1-bits.
 
The OneMax problem was introduced by Ackley (1985). His original definition of the problem was
 to maximize: f(x) = 10 * CountOfOneBits(x). Thus, Ackley's original OneMax multiplied the number
 of 1-bits by 10. Our implementation does not multiply by 10. Doing so does not change the optimal
 solution or the shape of the landscape. However, it may have an effect on the behavior of some
 search algorithms. For example, simulated annealing decides whether or not to accept a worsening
 move with a probability that depends on the difference in cost between the current solution and
 the random neighbor, as well as on its current temperature. Keeping all else the same and scaling
 the cost values can lead to different acceptance probabilities (for a specific temperature
 value). If you want to use Ackley's original version, or any other scaling for that matter, you
 can use the IntegerCostFunctionScaler class for this purpose. You can do so by defining
 your optimization problem with something like: IntegerCostFunctionScaler<BitVector> problem
 = new IntegerCostFunctionScaler<BitVector>(new OneMax()); Additionally, the OneMaxAckley class specifically implements Ackley's version with the costs scaled by a factor of
 10.
 
Although commonly used by others without reference, the OneMax problem was introduced by David
 Ackley in the following paper:
 David H. Ackley. A connectionist algorithm for genetic search. Proceedings of the First
 International Conference on Genetic Algorithms and Their Applications, pages 121-135, July 1985.
- 
Constructor SummaryConstructorsConstructorDescriptionOneMax()Constructs a OneMax object for use in evaluating candidate solutions to the OneMax problem.
- 
Method SummaryModifier and TypeMethodDescriptionintComputes the cost of a candidate solution to the problem instance.booleanisMinCost(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.intminCost()A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.intComputes the value of the candidate solution within the usual constraints and interpretation of the problem.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cicirello.search.problems.IntegerCostOptimizationProblemcostAsDouble, getSolutionCostPair
- 
Constructor Details- 
OneMaxpublic OneMax()Constructs a OneMax object for use in evaluating candidate solutions to the OneMax problem.
 
- 
- 
Method Details- 
costDescription copied from interface:IntegerCostOptimizationProblemComputes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.- Specified by:
- costin interface- IntegerCostOptimizationProblem<BitVector>
- Parameters:
- candidate- The candidate solution to evaluate.
- Returns:
- The cost of the candidate solution. Lower cost means better solution.
 
- 
minCostpublic int minCost()Description copied from interface:IntegerCostOptimizationProblemA 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:
- minCostin interface- IntegerCostOptimizationProblem<BitVector>
- Returns:
- A lower bound on the minimum theoretical cost of the problem instance.
 
- 
valueDescription copied from interface:IntegerCostOptimizationProblemComputes the value of the candidate solution within the usual constraints and interpretation of the problem.- Specified by:
- valuein interface- IntegerCostOptimizationProblem<BitVector>
- Parameters:
- candidate- The candidate solution to evaluate.
- Returns:
- The actual optimization value of the candidate solution.
 
- 
isMinCostpublic boolean isMinCost(int cost) Description copied from interface:IntegerCostOptimizationProblemChecks 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:
- isMinCostin interface- IntegerCostOptimizationProblem<BitVector>
- Parameters:
- cost- The cost to check.
- Returns:
- true if cost is equal to the minimum theoretical cost,
 
 
-