|
| 1 | +""" |
| 2 | +Choose the `n` best elements from the source array. |
| 3 | +
|
| 4 | +"Best" selection is the standard way to perform survival selection in a |
| 5 | +(mu+lambda) Evolutionary Algorithm (:class:`~moptipy.algorithms.so.ea.EA`). |
| 6 | +It basically sorts the input array based on fitness and then copies the first |
| 7 | +`n` elements to the output array. The algorithm is not random but |
| 8 | +deterministic, i.e., it will always select each of the `n` best records |
| 9 | +exactly once. |
| 10 | +
|
| 11 | +This selection is also often called "mu+lambda," "mu,lambda," or "top-n" |
| 12 | +selection. It is similar to the selection scheme in Eshelman's CHC algorithm. |
| 13 | +A randomized version of this algorithm is called "truncation selection" in the |
| 14 | +paper of Blickle and Thiele. |
| 15 | +
|
| 16 | +1. Peter J. B. Hancock. An Empirical Comparison of Selection Methods in |
| 17 | + Evolutionary Algorithms. In Terence Claus Fogarty, editor, *Selected Papers |
| 18 | + from the AISB Workshop on Evolutionary Computing (AISB EC'94),* April |
| 19 | + 11-13, 1994, Leeds, UK, volume 865 of Lecture Notes in Computer Science, |
| 20 | + pages 80-94, Berlin/Heidelberg, Germany: Springer, ISBN: 978-3-540-58483-4. |
| 21 | + https://dx.doi.org/10.1007/3-540-58483-8_7. Conference organized by the |
| 22 | + Society for the Study of Artificial Intelligence and Simulation of |
| 23 | + Behaviour (AISB). |
| 24 | +2. Larry J.Eshelman. The CHC Adaptive Search Algorithm: How to Have Safe |
| 25 | + Search When Engaging in Nontraditional Genetic Recombination. In Gregory |
| 26 | + J. E. Rawlins, editor, Foundations of Genetic Algorithms, volume 1, 1991, |
| 27 | + pages 265-283. San Francisco, CA: Morgan Kaufmann. |
| 28 | + https://doi.org/10.1016/B978-0-08-050684-5.50020-3 |
| 29 | +3. Frank Hoffmeister and Thomas Bäck. Genetic Algorithms and Evolution |
| 30 | + Strategies: Similarities and Differences. In Hans-Paul Schwefel and |
| 31 | + Reinhard Männer, *Proceedings of the International Conference on Parallel |
| 32 | + Problem Solving from Nature (PPSN I),* October 1-3, 1990, Dortmund, |
| 33 | + Germany, volume 496 of Lecture Notes in Computer Science, pages 455-469, |
| 34 | + Berlin/Heidelberg, Germany: Springer. ISBN: 978-3-540-54148-6. |
| 35 | + https://doi.org/10.1007/BFb0029787. |
| 36 | +4. Uday Kumar Chakraborty and Kalyanmoy Deb and Mandira Chakraborty. Analysis |
| 37 | + of Selection Algorithms: A Markov Chain Approach. *Evolutionary |
| 38 | + Computation,* 4(2):133-167. Summer 1996. Cambridge, MA, USA: MIT Press. |
| 39 | + doi:10.1162/evco.1996.4.2.133. |
| 40 | + https://dl.acm.org/doi/pdf/10.1162/evco.1996.4.2.133 |
| 41 | +5. Tobias Blickle and Lothar Thiele. A Comparison of Selection Schemes used in |
| 42 | + Genetic Algorithms. Second edition, December 1995. TIK-Report 11 from the |
| 43 | + Eidgenössische Technische Hochschule (ETH) Zürich, Department of Electrical |
| 44 | + Engineering, Computer Engineering and Networks Laboratory (TIK), Zürich, |
| 45 | + Switzerland. ftp://ftp.tik.ee.ethz.ch/pub/publications/TIK-Report11.ps |
| 46 | +""" |
| 47 | + |
| 48 | +from typing import List |
| 49 | + |
| 50 | +from numpy.random import Generator |
| 51 | + |
| 52 | + |
| 53 | +from moptipy.algorithms.modules.selection import Selection, FitnessRecord |
| 54 | + |
| 55 | + |
| 56 | +class Best(Selection): |
| 57 | + """The best selection: select each of the best `n` elements once.""" |
| 58 | + |
| 59 | + def select(self, source: List[FitnessRecord], dest: List[FitnessRecord], |
| 60 | + n: int, random: Generator) -> None: # pylint: disable=W0613 |
| 61 | + """ |
| 62 | + Perform deterministic best selection without replacement. |
| 63 | +
|
| 64 | + :param source: the list with the records to select from |
| 65 | + :param dest: the destination to append the selected records to |
| 66 | + :param n: the number of records to select |
| 67 | + :param random: the random number generator |
| 68 | + """ |
| 69 | + source.sort() |
| 70 | + dest.extend(source[0:n]) |
| 71 | + |
| 72 | + def __str__(self): |
| 73 | + """ |
| 74 | + Get the name of the best selection algorithm. |
| 75 | +
|
| 76 | + :return: the name of the best selection algorithm |
| 77 | + """ |
| 78 | + return "trunc" |
0 commit comments