Skip to content

Commit

Permalink
Bug fix in MD mating for pymoo 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jbussemaker committed May 7, 2024
1 parent 2bec906 commit b40453a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sb_arch_opt/algo/pymoo_interface/md_mating.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ def _do(self, problem, pop, n_offsprings, parents=False, **kwargs):
crossover = self.crossover[clazz]
assert crossover.n_parents == n_parents_crossover and crossover.n_offsprings == n_offspring_crossover

_parents = [[Individual(X=parent.X[x_idx]) for parent in parents] for parents in pop]
_parents = [Population.new(X=[parent.X[x_idx].astype(float) for parent in parents]) for parents in pop]
# _parents = [[Individual(X=parent.X[x_idx]) for parent in parents] for parents in pop]

_vars = [var_defs[e] for e in list_of_vars]
_vars = {i: var_defs[e] for i, e in enumerate(list_of_vars)}
_xl, _xu = None, None

if clazz in [Real, Integer]:
_xl, _xu = np.array([v.bounds for v in _vars]).T
_xl, _xu = np.array([v.bounds for v in _vars.values()]).T

_problem = Problem(vars=_vars, xl=_xl, xu=_xu)

Expand All @@ -133,7 +134,7 @@ def _do(self, problem, pop, n_offsprings, parents=False, **kwargs):
_off = mutation(_problem, _off, **kwargs)

# Sometimes NaN's might sneak into the outputs, try again if this is the case
x_off = _off.get('X')[:n_offsprings, :]
x_off = _off.get('X')[:n_offsprings, :].astype(float)
if np.any(np.isnan(x_off)):
continue
break
Expand Down

0 comments on commit b40453a

Please sign in to comment.