我试图在 Python 中使用 cvxpy 将变量强制为整数(整数约束),但结果一直是浮点数:
from cvxpy import *
Fi = Int()
Or = Int()
constr = [Fi <= 3000,
Or <= 3000,
Or >= 1000,
1.25*Or - Fi >= 0,
Fi >= 0,
Or >= 0]
obj= Maximize(50000*Fi + 25000*Or)
prob = Problem(obj, constr)
prob.solve()
print ("Status: ", prob.status)
print ("Fi: ", Fi.value)
print ("Or: ", Or.value)
print ("Obj: ", obj.value)
结果:
Status: optimal
Fi: 2999.9999999
Or: 2999.99999989
Obj: 224999999.992
我能做些什么来强迫它?
我也试过:
Fi = Variable()
Or = Variable()
constr = [Fi <= 3000,
Or <= 3000,
Or >= 1000,
1.25*Or - Fi >= 0,
Fi >= 0,
Or >= 0,
Fi == Int(),
Or == Int()]
Fi 和 Or 是变量。不仅仅是数字。