Skip to content

Commit

Permalink
random search batch solver compliant with constrained perf assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
paulduf authored and paulduf committed Mar 18, 2022
1 parent 7c04dc8 commit d2c9fe9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions code-experiments/build/python/python/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def random_search(fun, lbounds, ubounds, budget):
# about five times faster than "for k in range(budget):..."
X = lbounds + (ubounds - lbounds) * np.random.rand(chunk, dim)
if fun.number_of_constraints > 0:
C = [fun.constraint(x) for x in X] # call constraints
F = [fun(x) for i, x in enumerate(X) if np.all(C[i] <= 0)]
FC = [(fun(x), fun.constraint(x)) for x in X] # call objective and constraints
F = [fc[0] for fc in FC if all(fc[1] <= 0)]
budget -= chunk # one more to account for constraint evals
else:
F = [fun(x) for x in X]
if fun.number_of_objectives == 1:
Expand Down

0 comments on commit d2c9fe9

Please sign in to comment.