50 def __init__(self, archive, *, initialize, mutations, descriptors, coherence, transverse=True, seed=0):
54 or not archive.fitness_weights[0]
or archive.fitness_score_names
or archive.features_score_names):
78 def run(self, budget, *, proposal_limit=None):
79 """Score distinct combinations in direct-first order when the final edit is budget-cut."""
80 budget = _positive_int(budget,
"budget")
81 maximum = 10 * budget
if proposal_limit
is None else _positive_int(proposal_limit,
"proposal_limit")
82 edits = assessments = cross_assessments = accepted = 0
84 while edits < maximum
and assessments < budget:
87 parent = tuple(archive[self.
_rng.integers(len(archive))])
88 index = int(self.
_rng.integers(self.
_size))
90 direct = (*parent[:index], changed, *parent[index + 1:])
95 if not archive.in_bounds(measured, archive.features_domain):
97 cell = archive.index_grid(measured)
98 choices = {direct: measured}
100 for other_cell, items
in archive.solutions.items():
101 if other_cell[index] == cell[index]
and items:
102 other = tuple(items[0])
103 parts = (*other[:index], changed, *other[index + 1:])
104 if parts
not in choices:
105 features = list(archive.get_ind_features(items[0]))
106 features[index] = measured[index]
107 choices[parts] = tuple(features)
109 for number, (parts, features)
in enumerate(choices.items()):
110 if assessments == budget:
114 cross_assessments += number > 0
115 if not np.isfinite(quality):
116 raise ValueError(
"Coherence must be finite.")
117 if archive.in_bounds((quality,), archive.fitness_domain):
118 ranked.append((quality, parts, features))
119 for quality, parts, features
in sorted(ranked, key=
lambda row: self.
_weight * row[0], reverse=
True):
120 if archive.free < 1
and not archive.solutions[archive.index_grid(features)]:
124 if archive.add(elite)
is not None:
127 return MEliTAStats(edits, assessments, cross_assessments, accepted)