|
8 | 8 |
|
9 | 9 | The following benchmark problems are provided:
|
10 | 10 |
|
11 |
| -1. :mod:`~moptipy.examples.bitstrings.ising1d`, the one-dimensional |
12 |
| - Ising model, where the goal is that all bits should have the same value as |
13 |
| - their neighbors in a ring. |
14 |
| -2. :mod:`~moptipy.examples.bitstrings.ising2d`, the two-dimensional |
15 |
| - Ising model, where the goal is that all bits should have the same value as |
16 |
| - their neighbors on a torus. |
17 |
| -3. The :mod:`~moptipy.examples.bitstrings.jump` problem is equivalent |
18 |
| - to :mod:`~moptipy.examples.bitstrings.onemax`, but has a deceptive |
19 |
| - region right before the optimum. |
20 |
| -4. The :mod:`~moptipy.examples.bitstrings.leadingones` problem, |
| 11 | +1. The :mod:`~moptipy.examples.bitstrings.onemax` problem, where the |
| 12 | + goal is to find a bit string with the maximum number of ones. |
| 13 | +2. The :mod:`~moptipy.examples.bitstrings.leadingones` problem, |
21 | 14 | where the goal is to find a bit string with the maximum number of leading
|
22 | 15 | ones.
|
23 |
| -5. The :mod:`~moptipy.examples.bitstrings.linearharmonic` problem, |
| 16 | +3. The :mod:`~moptipy.examples.bitstrings.linearharmonic` problem, |
24 | 17 | where the goal is to find a bit string with the all ones, like in
|
25 | 18 | :mod:`~moptipy.examples.bitstrings.onemax`, but this time all bits have
|
26 | 19 | a different weight (namely their index, starting at 1).
|
27 |
| -6. The :mod:`~moptipy.examples.bitstrings.nqueens`, where the goal is to |
28 |
| - place `k` queens on a `k * k`-sized chess board such that no queen can |
29 |
| - beat any other queen. |
30 |
| -7. The :mod:`~moptipy.examples.bitstrings.onemax` problem, where the |
31 |
| - goal is to find a bit string with the maximum number of ones. |
32 |
| -8. The :mod:`~moptipy.examples.bitstrings.plateau` problem similar to the |
33 |
| - :mod:`~moptipy.examples.bitstrings.jump` problem, but this time the |
34 |
| - optimum is surrounded by a region of neutrality. |
35 |
| -9. The :mod:`~moptipy.examples.bitstrings.trap` problem, which is like |
| 20 | +4. The :mod:`~moptipy.examples.bitstrings.binint` problem, |
| 21 | + is again similar to :mod:`~moptipy.examples.bitstrings.onemax`, but the |
| 22 | + bits have exponential weight. Basically, we just decode the bit string |
| 23 | + into an integer. |
| 24 | +5. The :mod:`~moptipy.examples.bitstrings.trap` problem, which is like |
36 | 25 | OneMax, but with the optimum and worst-possible solution swapped. This
|
37 | 26 | problem is therefore highly deceptive.
|
38 |
| -10. The :mod:`~moptipy.examples.bitstrings.twomax` problem has the global |
| 27 | +6. The :mod:`~moptipy.examples.bitstrings.twomax` problem has the global |
39 | 28 | optimum at the string of all `1` bits and a local optimum at the string
|
40 | 29 | of all `0` bits. Both have basins of attraction of about the same size.
|
41 |
| -11. The :mod:`~moptipy.examples.bitstrings.w_model`, a benchmark |
| 30 | +7. :mod:`~moptipy.examples.bitstrings.ising1d`, the one-dimensional |
| 31 | + Ising model, where the goal is that all bits should have the same value as |
| 32 | + their neighbors in a ring. |
| 33 | +8. :mod:`~moptipy.examples.bitstrings.ising2d`, the two-dimensional |
| 34 | + Ising model, where the goal is that all bits should have the same value as |
| 35 | + their neighbors on a torus. |
| 36 | +9. The :mod:`~moptipy.examples.bitstrings.jump` problem is equivalent |
| 37 | + to :mod:`~moptipy.examples.bitstrings.onemax`, but has a deceptive |
| 38 | + region right before the optimum. |
| 39 | +10. The :mod:`~moptipy.examples.bitstrings.plateau` problem similar to the |
| 40 | + :mod:`~moptipy.examples.bitstrings.jump` problem, but this time the |
| 41 | + optimum is surrounded by a region of neutrality. |
| 42 | +11. The :mod:`~moptipy.examples.bitstrings.nqueens`, where the goal is to |
| 43 | + place `k` queens on a `k * k`-sized chess board such that no queen can |
| 44 | + beat any other queen. |
| 45 | +12. The :mod:`~moptipy.examples.bitstrings.w_model`, a benchmark |
42 | 46 | problem with tunable epistasis, uniform neutrality, and
|
43 | 47 | ruggedness/deceptiveness.
|
44 |
| -12. The :mod:`~moptipy.examples.bitstrings.zeromax` problem, where the |
| 48 | +13. The :mod:`~moptipy.examples.bitstrings.zeromax` problem, where the |
45 | 49 | goal is to find a bit string with the maximum number of zeros. This is the
|
46 | 50 | opposite of the OneMax problem.
|
47 | 51 |
|
|
53 | 57 | Hefei, Anhui, China (中国安徽省合肥市) under the supervision of
|
54 | 58 | Prof. Dr. Thomas Weise (汤卫思教授).
|
55 | 59 | """
|
| 60 | +from itertools import chain |
| 61 | +from typing import Callable, Iterator, cast |
| 62 | + |
| 63 | +from moptipy.examples.bitstrings.binint import BinInt |
| 64 | +from moptipy.examples.bitstrings.bitstring_problem import BitStringProblem |
| 65 | +from moptipy.examples.bitstrings.ising1d import Ising1d |
| 66 | +from moptipy.examples.bitstrings.ising2d import Ising2d |
| 67 | +from moptipy.examples.bitstrings.jump import Jump |
| 68 | +from moptipy.examples.bitstrings.leadingones import LeadingOnes |
| 69 | +from moptipy.examples.bitstrings.linearharmonic import LinearHarmonic |
| 70 | +from moptipy.examples.bitstrings.nqueens import NQueens |
| 71 | +from moptipy.examples.bitstrings.onemax import OneMax |
| 72 | +from moptipy.examples.bitstrings.plateau import Plateau |
| 73 | +from moptipy.examples.bitstrings.trap import Trap |
| 74 | +from moptipy.examples.bitstrings.twomax import TwoMax |
| 75 | +from moptipy.examples.bitstrings.w_model import WModel |
| 76 | + |
| 77 | + |
| 78 | +def default_instances( |
| 79 | + class_scales: Callable[[ |
| 80 | + type], Iterator[int]] = lambda s: cast(Iterator[int], ())) \ |
| 81 | + -> Iterator[Callable[[], BitStringProblem]]: |
| 82 | + """ |
| 83 | + Get the default bit-string based benchmark instances. |
| 84 | +
|
| 85 | + :param class_scales: a function that can override the minimum and |
| 86 | + maximimum problem scales on a per-benchmark-function-class |
| 87 | + basis. If this function returns an empty iterator, then the default |
| 88 | + scales are used. |
| 89 | + :return: an :class:`Iterator` with the default bit-string |
| 90 | + benchmark instances |
| 91 | +
|
| 92 | + >>> len(list(default_instances())) |
| 93 | + 963 |
| 94 | + """ |
| 95 | + return chain( |
| 96 | + BinInt.default_instances(*class_scales(BinInt)), # type: ignore |
| 97 | + Ising1d.default_instances(*class_scales(Ising1d)), # type: ignore |
| 98 | + Ising2d.default_instances(*class_scales(Ising2d)), # type: ignore |
| 99 | + Jump.default_instances(*class_scales(Jump)), # type: ignore |
| 100 | + LeadingOnes.default_instances( # type: ignore |
| 101 | + *class_scales(LeadingOnes)), |
| 102 | + LinearHarmonic.default_instances( # type: ignore |
| 103 | + *class_scales(LinearHarmonic)), |
| 104 | + NQueens.default_instances(*class_scales(NQueens)), # type: ignore |
| 105 | + OneMax.default_instances(*class_scales(OneMax)), # type: ignore |
| 106 | + Plateau.default_instances(*class_scales(Plateau)), # type: ignore |
| 107 | + Trap.default_instances(*class_scales(Trap)), # type: ignore |
| 108 | + TwoMax.default_instances(*class_scales(TwoMax)), # type: ignore |
| 109 | + WModel.default_instances(*class_scales(WModel))) # type: ignore |
0 commit comments