QDpy
Loading...
Searching...
No Matches
populations.py
Go to the documentation of this file.
1# This file is part of qdpy.
2#
3# qdpy is free software: you can redistribute it and/or modify
4# it under the terms of the GNU Lesser General Public License as
5# published by the Free Software Foundation, either version 3 of
6# the License, or (at your option) any later version.
7#
8# qdpy is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU Lesser General Public License for more details.
12#
13# You should have received a copy of the GNU Lesser General Public
14# License along with qdpy. If not, see <http://www.gnu.org/licenses/>.
15
16
18
19"""TODO"""
20
21__all__ = ["Population"]
22
23
24import numpy as np
25from typing import Optional, Tuple, List, Iterable, Iterator, Any, TypeVar, Generic, Union, Sequence, MutableSet, MutableSequence, Type, Callable, Generator, MutableMapping, Mapping, overload
26
27from qdpy.utils import *
28from qdpy.phenotype import *
29from qdpy.base import *
30from qdpy.metrics import novelty, novelty_local_competition, novelty_nn
31from .base import *
32
33
34@registry.register
36 """Keep a fixed-size population in insertion order.
37
38 A new genome at capacity evicts the oldest local entry after
39 required parent admission succeeds. Equal genomes keep their
40 existing entry. A parent-only offer leaves the population intact.
41 """
42
43 def __init__(self, iterable: Optional[Iterable] = None,
44 capacity: Optional[float] = None,
45 **kwargs: Any) -> None:
46 assert(capacity is not None and not np.isinf(capacity))
47 super().__init__(iterable, capacity=capacity, **kwargs)
48
49
54 def _add_internal(self, individual: IndividualLike, raise_if_not_added_to_parents: bool, only_to_parents: bool) -> Optional[int]:
55 replace_index = None
56 if not only_to_parents and self.free < 1 and self.size and self._index_of(individual) is None:
57 replace_index = 0
58 return super()._add_internal(individual, raise_if_not_added_to_parents, only_to_parents, replace_index)
59
60
61
62
63
Optional[int] _index_of(self, IndividualLike individual)
Definition base.py:769
Optional[int] _add_internal(self, IndividualLike individual, bool raise_if_not_added_to_parents, bool only_to_parents)
Reserve FIFO eviction for a new local member at capacity.