你能用纸浆对指标约束进行建模吗?

问题描述 投票:0回答:1

我想向用

if z=0, then x=0
编写的问题添加指标约束(例如
x>=0
z
PuLP
是二进制变量)。显然,我可以按照herehere的建议使用big-M方法。

但是,我无法使用 big-M 解决方法,因为我的术语在 MILP 内不受限制。我发现 this post from 2016 指出

PuLP
无法处理指标约束。

有谁知道情况是否仍然如此或有其他解决方案吗?

提前致谢。

python constraints pulp
1个回答
0
投票

我认为,您可以尝试使用 GEKKO

if2
if3
方法来处理 Binary Indicator_constraint

from gekko import GEKKO
import numpy as np


tm= np.array([0,1,2,3,4,5,6,7,8,9,10,11])
cost= np.array([4, 31, 30, 28, 28, 27, 26, 26, 25, 24, 24, 23 ])
d = np.array([ 0, 8, 9, 9, 10, 10, 10, 11, 12, 14, 16, 18])
cnt= len(tm); print(len(tm))
new_cost = 18
    
m = GEKKO(remote = False)

# Gekko has an integer tolerance where it can find a solution within 1e-2 of the integer value. This can be adjusted with the solver option minlp_integer_tol
# increase tolerance
m.options.RTOL = 1e-10
m.options.OTOL = 1e-10

m.solver_options = ['minlp_gap_tol 1.0e-5',\
                    'minlp_maximum_iterations 10000',\
                    'minlp_max_iter_with_int_sol 10000',\
                    'minlp_integer_tol 1e-8']

x = m.Array(m.Var,cnt,lb=0,ub=1,integer=True)

# !!!
x1= m.Const(1)
x0= m.Const(0)
m.Maximize(m.sum([ (cost[i]- d[i] +  m.if3(cost[i]- d[i] , x1, x0) *new_cost)  *x[i]  for i in range(cnt) ]))
y = m.Var()
m.Equation(y==m.sum([  (cost[i]- d[i] +  m.if3(cost[i]- d[i] , x1, x0) *new_cost)   *x[i]  for i in range(cnt)] ))

m.options.SOLVER = 1        #  APOPT
m.solve()

value = -1* m.options.objfcnval     # Maximize need *-1 to get max_val
print("y_total_: ", y.value[0])
© www.soinside.com 2019 - 2024. All rights reserved.