Reputation: 7
I have an optimization problem that I want to solve via tools in pymoo package of version 0.6.1 in Python. I defined my problem as follows,
class Problem(ElementwiseProblem):
def __init__(self):
vol_frac_vars = {'vol_frac_' + str(i): Real(bounds=(0, 1)) for i in range(LAM_NUM)}
theta_vars = {'theta_' + str(i): Choice(options=[-45, 0, 45, 90]) for i in range(LAM_NUM)}
vars = {**vol_frac_vars, **theta_vars}
super().__init__(vars=vars,
n_obj=1,
n_eq_constr=0,
n_ieq_constr=1)
def _evaluate(self, X, out, *args, **kwargs):
v = [X['vol_frac_' + str(i)] for i in range(LAM_NUM)]
t = [X['theta_' + str(i)] for i in range(LAM_NUM)]
f1 = # Objective function here
g1 = # Constraint function here
out['F'] = [f1]
out['G'] = [g1]
problem = Problem()
algorithm = MixedVariableGA(pop_size=100,
n_offsprings=10,
sampling=FloatRandomSampling(),
crossover=SBX(prob=0.9, eta=15),
mutation=PM(eta=20),
eliminate_duplicates=True)
termination = get_termination('n_gen', 1000)
result = minimize(problem,
algorithm,
termination,
save_history=True,
return_least_infeasible=True,
seed=SEED)
It is a mixed-variable-type problem so I used MixedVariableGA as stipulated in the documentation of the package. Also variables in capitals are pre-defined constants specific for my problem. My goal is to find the minimum value of f1 subjected to constraint g1 for n number of vol_frac_vars and n number of theta_vars variables, which in total adds up to 2n number of variables. However, when I run the code, I encounter the following error,
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-57a92730b50b> in <cell line: 10>()
8 termination = get_termination('n_gen', 1000)
9
---> 10 result = minimize(problem,
11 algorithm,
12 termination,
8 frames
/usr/local/lib/python3.10/dist-packages/pymoo/operators/sampling/rnd.py in _do(self, problem, n_samples, **kwargs)
22 if problem.has_bounds():
23 xl, xu = problem.bounds()
---> 24 assert np.all(xu >= xl)
25 X = xl + (xu - xl) * X
26
TypeError: '>=' not supported between instances of 'dict' and 'dict'
How can I solve this error?
Upvotes: 0
Views: 254