24 """Index measurements by descriptor cell and configuration.
26 The cells contain one best feasible measurement per configuration.
27 Iteration and len() operate over all cell/configuration entries.
28 best_grid is the live native projection of the best entry in each
29 occupied cell. Obtain a separate native snapshot for a single
30 configuration with configuration_grid().
33 def __init__(self, best_grid, configurations):
40 """Count occupied cell/configuration pairs."""
44 """Iterate configuration elites in admission order."""
48 """Get a configuration elite by position in admission order."""
53 """Count cells with at least one feasible configuration elite."""
58 """Return occupied cell counts in the order of the declared configurations."""
60 for alternatives
in self.
_cells.values():
61 for branch
in alternatives:
67 """Return mean retained configurations per occupied cell, or zero when empty."""
72 """Return a read-only map from configuration indices to the retained individuals."""
73 return MappingProxyType(self.
_cells.get(tuple(cell), {}))
77 """Copy one layer by configuration index into an independent native grid."""
78 configuration = index(configuration)
80 raise IndexError(
"Configuration index is out of range.")
83 for alternatives
in self.
_cells.values():
84 if configuration
in alternatives:
85 grid.add(deepcopy(alternatives[configuration]))
88 def _offer(self, individual):
90 branch = individual[0]
91 cell = grid.index_grid(individual)
92 alternatives = self.
_cells.get(cell)
93 previous = alternatives.get(branch)
if alternatives
else None
94 if previous
is not None and not grid.get_ind_fitness(individual).dominates(grid.get_ind_fitness(previous)):
97 fitness=deepcopy(individual.fitness), features=deepcopy(individual.features),
98 scores=deepcopy(individual.scores))
99 record.elapsed = individual.elapsed
101 if previous
is not None:
104 self.
_cells.setdefault(cell, {})[branch] = record
111 """Evolve feasible conditional designs into a layered archive.
113 Accept the same conditional variables, constraints and evaluator
114 results as HiGeME. Parent selection uses all retained configuration
115 elites. Standard QDpy callbacks, best() and the supplied container
116 use the per-cell best projection. Access all alternatives through
117 deep_archive and update the live archives through the search.
119 :param container: Empty parentless Grid or CVTGrid with one slot per cell.
120 :param budget: Attempted evaluations.
121 :param variables: Mapping of names to the shared variable schema.
122 :param configurations: Sequence of ConditionalConfiguration objects.
123 :param kwargs: HiGeME variation, batching, and optimisation settings.
126 def __init__(self, container, budget, variables, *, configurations, **kwargs):
127 if (type(container)
not in (Grid, CVTGrid)
or container.parents
128 or container.capacity < len(container.solutions)):
129 raise ValueError(
"Supply a parentless Grid or CVTGrid with capacity for every cell.")
130 if container.fitness_weights
is not None:
131 kwargs.setdefault(
"optimisation_task", container.fitness_weights)
132 super().__init__(container, budget, variables, configurations=configurations, **kwargs)
135 def __deepcopy__(self, memo):
139 return super().__deepcopy__(memo)
141 def _parent_pool(self):
145 return {slot
for slot, ind
in enumerate(evaluated)
147 and _constraint_violation(ind, self.
configurations[ind[0]].constraints) == 0