Stefan-Endres / shgo

Simplicial Homology Global Optimization
https://stefan-endres.github.io/shgo
MIT License
44 stars 12 forks source link

sampling_method='sobol' can't handle constraints with args #32

Closed JakobAntonT closed 3 years ago

JakobAntonT commented 5 years ago

from shgo import shgo import numpy as np

def eggholder(x): return (-(x[1] + 47.0)

def f(x): # (cattle-feed) return 24.55x[0] + 26.75x[1] + 39x[2] + 40.50x[3]

def g1(x): return 2.3x[0] + 5.6x[1] + 11.1x[2] + 1.3x[3] - 5 # >=0

def g2(x): return (12x[0] + 11.9x[1] +41.8x[2] + 52.1x[3] - 21

def h1(x): return x[0] + x[1] + x[2] + x[3] - 1 # == 0

cons = ({'type': 'ineq', 'fun': g1}, {'type': 'ineq', 'fun': g2}, {'type': 'eq', 'fun': h1}) bounds = [(0, 1.0),]*4 res = shgo(f, bounds, iters=3, constraints=cons) res

################################################## #################### modified ####################

using sampling method sobol

res_sobol = shgo(f, bounds, iters=3, constraints=cons,sampling_method='sobol') res_sobol # still working

using constrain with arguments

def g1_modified(x,i): return i2.3x[0] + i5.6x[1] + 11.1x[2] + 1.3x[3] - 5 # >=0 cons = ({'type': 'ineq', 'fun': g1_modified, "args":(0,)}, {'type': 'ineq', 'fun': g2}, {'type': 'eq', 'fun': h1}) res_modConstr = shgo(f, bounds, iters=3, constraints=cons) res_modConstr #still working

using constrain with arguments AND sampling method sobol

res_modConstr_sobol = shgo(f, bounds, iters=3, constraints=cons,sampling_method='sobol') res_modConstr_sobol #TypeError: g1_modified() missing 1 required positional argument: 'i'

Stefan-Endres commented 5 years ago

Thank you for reporting this issue, it should hopefully not take too long to fix.

JakobAntonT commented 5 years ago

Thanks a lot for your answer. This is my first reported issue, I didnt expect an answer that fast.

Stefan-Endres commented 3 years ago

Fixed with previous commits, apologies for not closing sooner.