53 """Run Antipov et al.'s GSEMO with diversity-aware tie replacement.
55 Sample a parent uniformly and flip each bit independently with
56 probability 1/dimension. For a previously seen objective vector,
57 replace its incumbent if population imbalance improves or ties.
58 For other vectors, use Pareto dominance on maximization objectives.
60 :param dimension: Number of bits per solution.
61 :param diversity: ``total`` minimizes summed imbalance and ``lexicographic``
62 minimizes the sorted imbalance vector. ``none`` is the GSEMO control.
63 :param initial: Optional binary starting genome.
64 :param seed: Seed for variation, parent selection, and evaluator calls.
67 def __init__(self, dimension, *, diversity="total", initial=None, seed=0):
68 self.
_dimension = _positive_int(dimension,
"dimension")
69 if diversity
not in (
"total",
"lexicographic",
"none"):
70 raise ValueError(
"Choose total, lexicographic, or none diversity.")
72 self.
_initial =
None if initial
is None else tuple(map(index, initial))
74 raise ValueError(
"initial must match dimension and contain only zero or one.")
75 self.
_rng, self.
_evaluation = map(np.random.default_rng, np.random.SeedSequence(seed).spawn(2))
77 self.
_ones = np.zeros(dimension, dtype=int)
83 """Return the nondominated representatives in admission order."""
88 """Return a snapshot of attempted evaluations and population diversity."""
92 def _imbalance(self, ones):
95 def _diversity_key(self, ones):
97 return int(imbalance.sum())
if self.
_diversity ==
"total" else tuple(sorted(imbalance, reverse=
True))
99 def _offer(self, genome, objectives):
101 if previous
is not None:
102 if genome == previous:
104 replacement = self.
_ones + np.asarray(genome) - np.asarray(previous)
109 elif not any(_dominates(other, objectives)
for other
in self.
_population):
110 for other
in [other
for other
in self.
_population if _dominates(objectives, other)]:
120 def run(self, evaluate, budget):
121 """Continue from the last Pareto population and random state."""
122 for _
in range(_attempt_budget(budget)):
125 parent = parents[self.
_rng.integers(len(parents))]
127 genome = tuple(map(int, np.bitwise_xor(parent, changed)))
131 genome = tuple(map(int, self.
_rng.integers(2, size=self.
_dimension)))
133 result = evaluate(genome, int(self.
_evaluation.integers(2**32)))
137 objectives = _finite_vector(result,
"Objective vector", self.
_objectives)
139 self.
_offer(genome, objectives)