英文:
Constraint On Binary Variable Not Always Holding in Gekko
问题
我正在使用Gekko包在Python中创建一个非线性程序。该程序包括以下形式的约束条件:
m.Equation(i <= M*q)
其中,i 是一个决策变量,M 是一个大的常数(大于i的最大可能值),q 是一个二进制决策变量,如果i大于0,必须强制为1。
问题在于,这个约束条件并不总是成立,取决于i和M的值。例如,如果i为100,而M设置为10,000,那么q变为1。
然而,如果i为100,而M设置为100,000,那么q仍然为0,从而违反了约束条件。
这是有问题的,因为i可以取0到1,000,000之间的值,我需要这个约束条件始终成立,不管i的值是多少。
我尝试使用m.if3(),但导致没有找到答案。
英文:
I am creating a non-linear program in Python using the Gekko package. The program includes a constraint of the form:
m.Equation(i <= M*q)
where i is a decision variable, M is a large constant (larger than the max possible value of 'i'), and q is a binary decision variable that must be forced to 1 if i is greater than 0.
The issue is that this constraint doesn't always hold depending on the values of i and M. For example, if i is 100 and M is set to 10,000, then q becomes 1.
However, if i is 100 and M is set to 100,000, then q remains 0, therefore violating the constraint.
This is problematic because i can take on values between 0 and 1,000,000, and I need this constraint to always hold, regardless of the value of i.
I've tried using 'm.if3()' but that just led to no answer being found.
答案1
得分: 1
调整整数容差 minlp_integer_tol 以解决问题。APOPT 求解器将 0.01 视为整数值,除非将容差更改为更严格的值,例如 1.0e-6。
m = GEKKO(remote=True,server='https://byu.apmonitor.com')
# 多个选项作为一个列表
m.solver_options = ['minlp_gap_tol 1.0e-3',
'minlp_integer_tol 1.0e-6']
m.options.solver = 1
还要检查是否使用了 APOPT 求解器,并设置 m.options.SOLVER=1。默认情况下使用 IPOPT 求解器,不会强制整数变量。
英文:
Adjust the integer tolerance minlp_integer_tol to fix the problem. The APOPT solver considers 0.01 an integer value unless the tolerance is changed to a more stringent value such as 1.0e-6.
m = GEKKO(remote=True,server='https://byu.apmonitor.com')
# multiple options as one list
m.solver_options = ['minlp_gap_tol 1.0e-3',\
'minlp_integer_tol 1.0e-6']
m.options.solver = 1
Also check that the APOPT solver is selected with m.options.SOLVER=1. The default is to use the IPOPT solver that does not enforce integer variables.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论