I'm trying to define a minimization problem in Pymoo as:
def objective_function(nodes):
loss = compute_loss(nodes)
return loss
constraints = [ lambda x: x[1]-x[0],
lambda x: x[2]-x[1],
lambda x: x[3]-x[2]]
xl = [0]*4
xu = [1]*4
problem = FunctionalProblem(n_var = 4, objs = objective_function, constrs_iq = constraints,xl =xl, xu = xu)
algorithm = NSGA2(pop_size=40,
n_offsprings = 10,
eliminate_duplicates = True)
res = minimize(problem, algorithm, ('n_gen',200), seed = 1, method = "trust-constr")
My problem is that to evaluate the function compute_loss(nodes)
, I need to guarantee that nodes
follows the specified constraints
at each iteration, if they are not defined as strictly increasing parameters, the simulation will fail.
How can I make sure that the new guess of optimization parameters (nodes)
always fulfill these conditions?