简体   繁体   English

Python cvxopt忽略了约束

[英]Python cvxopt ignores constraints

I am using CVXOPT for linear programming according to the following example: http://abel.ee.ucla.edu/cvxopt/examples/tutorial/lp.html I am pretty sure I express a constraint that 我根据以下示例使用CVXOPT进行线性编程: http ://abel.ee.ucla.edu/cvxopt/examples/tutorial/lp.html我很确定我表达了一个约束条件

X1 >= 0 

But get a negative value for it. 但是得到负值。 How come? 怎么会? I get the "optimal solution found" message 我得到了“找到最佳解决方案”的消息

A = matrix( [ [0.0, 0.0, 1.0, 1.0, -0.0, -0.0, -1.0, -1.0, -1.0, 0.0, 0.0], 
              [0.0, 1.0, 1.0, 0.0, -0.0, -1.0, -1.0, -0.0, 0.0, -1.0, 0.0], 
              [1.0, 0.0, 0.0, 1.0, -1.0, -0.0, -0.0, -1.0, 0.0, 0.0, -1.0]
              ]
            ) 

Constraint values (right hand side) 约束值(右侧)

b = matrix( [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0] )

Minimizing function: 最小化功能:

c = matrix( [-1.0, -1.0, -1.0] )

Calling: 呼叫:

 sol=solvers.lp(c,A,b)

But: 但:

print (sol['x']): 
[-4.83e-09]
[ 1.00e+00]
[ 1.00e+00]

-4.83e-09>=0 
False

Thanks 谢谢

The default feasibility tolerance in CVXOPT is 1.0e-7, according to the user guide . 根据用户指南CVXOPT的默认可行性公差为1.0e-7。 Therefore you should expect that your constraints are only fulfilled to this level of accuracy. 因此,您应该期望您的约束仅满足此准确度。

EDIT Thus, to ensure that your "hard" constraint is fulfilled for certain, you need to set your lower variable bounds to equal your "hard" constraint (ie 0 in your case) plus the feasibility tolerance: 编辑因此,为了确保满足您的“硬”约束,您需要将下限变量设置为等于“硬”约束(即在您的情况下为0) 加上可行性公差:

X1 >= 1.0e-7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM