:mod:`binary` --- Binary Test Problems ====================================== .. automodule:: optproblems.binary Basic Problems -------------- .. autofunction:: optproblems.binary.one_max .. autoclass:: optproblems.binary.OneMax :special-members: __init__ :members: .. autofunction:: optproblems.binary.leading_ones .. autoclass:: optproblems.binary.LeadingOnes :special-members: __init__ :members: .. autofunction:: optproblems.binary.trailing_zeros .. autoclass:: optproblems.binary.LeadingOnesTrailingZeros :special-members: __init__ :members: Binary Multiple-Peaks Problems ------------------------------ .. autofunction:: optproblems.binary.hamming_dist .. autoclass:: optproblems.binary.Peak :special-members: __init__ :members: .. autoclass:: optproblems.binary.PeakProblem :special-members: __init__ :members: .. autoclass:: optproblems.binary.NearestPeakProblem :special-members: __init__ :members: .. autoclass:: optproblems.binary.WeightedNearestPeakProblem :special-members: __init__ :members: .. autoclass:: optproblems.binary.AllPeaksProblem :special-members: __init__ :members: Helpers ------- .. autoclass:: optproblems.binary.BinaryChecker :special-members: __init__ :members: Example ------- Obtaining the known optimum of a unimodal test problem. .. code:: python import random from optproblems import * from optproblems.binary import OneMax # the binary test problem OneMax counts the ones in the bitstring onemax = OneMax(10) global_optima = onemax.get_optimal_solutions() # the known optima are not evaluated by default for opt in global_optima: print(opt.phenome, opt.objective_values) print(onemax.consumed_evaluations, onemax.remaining_evaluations) onemax.batch_evaluate(global_optima) print("after evaluation:") for opt in global_optima: print(opt.phenome, opt.objective_values) print(onemax.consumed_evaluations, onemax.remaining_evaluations) rand_solution = Individual(phenome=[random.choice((0, 1)) for _ in range(10)]) onemax.evaluate(rand_solution) print("after another evaluation:") print(rand_solution.phenome, rand_solution.objective_values) print(onemax.consumed_evaluations, onemax.remaining_evaluations) # the global optimum is also a local one local_optima = onemax.get_locally_optimal_solutions() for opt in local_optima: print(opt.phenome, opt.objective_values)