我正在尝试使用IBM的Cplex Python API解决二次编程问题。该问题具有非线性约束。 Cplex是否接受非线性约束以进行二次编程?更具体地说,鉴于未知数[x1,x2,x3,x4,x5],我需要添加两个约束条件
约束A(x2 + x3)/(1-x1)= z1
约束B(x4 + x5)/(1-x1)= z2
其中z1和z2是已知数。
Cplex对于如何输入二次约束确实有instructions,但在输入非线性约束时我通常找不到。
答案 0 :(得分:1)
可以
from docplex.mp.model import Model
mdl = Model(name='example')
z1=2;
z2=3;
mdl.x1 = mdl.continuous_var(0,10,name='x1')
mdl.x2 = mdl.continuous_var(0,10,name='x2')
mdl.x3 = mdl.continuous_var(0,10,name='x3')
mdl.x4 = mdl.continuous_var(0,10,name='x4')
mdl.x5 = mdl.continuous_var(0,10,name='x5')
mdl.add_constraint(mdl.x2+mdl.x3==z1*(1-mdl.x1), 'A')
mdl.add_constraint(mdl.x4+mdl.x5==z2*(1-mdl.x1), 'B')
mdl.solve()
print(mdl.x1.solution_value);
print(mdl.x2.solution_value);
print(mdl.x3.solution_value);
print(mdl.x4.solution_value);
print(mdl.x5.solution_value);
帮助?