我需要在 Pymoo 中为调度问题编写一个复杂的约束。对于所有 i = 1 到 7,t = 1 到 14
sum (k in 1 to 3 ) y(i)(k)(t) <= 1
如何将索引和总和合并到 Pymoo 约束/目标函数中?请分享任何显示编写此类约束的示例的参考。
这是我使用遗传算法 NSGA-II 创建的代码草案
import numpy as np
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.core.problem import Problem
from pymoo.optimize import minimize
from pymoo.factory import get_sampling, get_crossover, get_mutation
class MyProblem(Problem):
def __init__(self):
super().__init__(n_var=294, # since y is 3 indexed variable (7*3*14)
n_obj=1,
n_constr=56, # Constraint is written for all i range(4 to 7) & all t range (1 to 14) Total (14*4)
xl=np.array([0, 0, 0]),
xu=np.array([v, 1, 1]),
ElementwiseProblem=True)
def _evaluate(self, x, out, *args, **kwargs):
#f1 = Here the Obj. Function
#g1 = Jere is the Constraint
out["F"] = [f1]
out["G"] = [g1]
Problem = MyProblem()
algorithm = NSGA2(pop_size=40,
n_offsprings=10,
sampling="real_random",
crossover="real_sbx", prob=0.9, eta=15,
#mutation="real_pm", eta=20,// eta repeated error
eliminate_duplicates=True)
stop_criteria = ('n_gen', 60)
results = minimize(
problem = problem,
algorithm = algorithm,
termination =stop_criteria)