问题描述
我正在使用Julia / JuMP编写算法。我之前已经定义了MILP,但是现在我想放宽一些整数限制。我该怎么办?
这是我的示例代码:
using JuMP
using Gurobi
model = Model(Gurobi.Optimizer)
@variable(model,0 <= x[i=1:2],Int)
@constraint(model,x[1] + x[2] >= 0.5)
@objective(model,Min,3*x[1] + x[2])
# *Here I want to relax the integer restriction on x[2]*
optimize!(model)
println(value.(x))
我发现了一个老问题相同的问题(How to convert type of a variable when using JuMP),但是该解决方案(使用功能setcategory()
)在当前的JuMP版本中似乎不起作用。
解决方法
您正在寻找unset_integer
:
https://jump.dev/JuMP.jl/stable/variables/#Integer-constraints-1
还有relax_integrality
https://jump.dev/JuMP.jl/stable/variables/#JuMP.relax_integrality