Quadratically constrained MIQP with julia and gurobi

偶尔善良 提交于 2019-12-11 04:57:23

问题


This is an attempt to answer the following question: https://matheducators.stackexchange.com/questions/11757/small-data-sets-with-integral-sample-standard-deviations

So the intent of the following code is to find examples of small datasets with integer standard deviation. That can be formulated as a quadratically constrained mixed integer quadratic program, so I try to use Gurobin from Julia. Following is my code:

using JuMP  
using Gurobi

m = Model(solver = GurobiSolver() )
@variable(m,  0<= x[1:20] <= 100,  Int)
@variable(m,  Gj,  Int)
@constraint(m,  Gj == sum(x[1:20])/20 )
@variable(m,  Var,  Int)
@constraint(m,  Var == sum( (x[1:20]-Gj).^2/19) )
@variable(m,  sd,  Int)
@constraint(m, sd * sd == Var)
### We need some restrictions to avoid all equal, < or zero,  solutions:
@constraint(m,  sd >= 5)
@objective(m, Min, sd)

print(m)

status = solve(m)

println("Objective value: ", getobjectivevalue(m) )

x = getvalue(x)

Running this results in:

ERROR: Gurobi.GurobiError(10021, "Quadratic equality constraints")
Stacktrace:
 [1] optimize(::Gurobi.Model) at /home/kjetil/.julia/v0.6/Gurobi/src/grb_solve.jl:7
 [2] optimize!(::Gurobi.GurobiMathProgModel) at /home/kjetil/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:294
 [3] #solve#101(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /home/kjetil/.julia/v0.6/JuMP/src/solvers.jl:173
 [4] solve(::JuMP.Model) at /home/kjetil/.julia/v0.6/JuMP/src/solvers.jl:148

Any ideas?


回答1:


A math programming solver like Gurobi Optimizer cannot solve models with quadratic equality constraints. Here are the types of constraints that Gurobi Optimizer can solve. To solve your model using Gurobi Optimizer, you must transform your constraints into one of these forms, such as quadratic inequality constraints.



来源:https://stackoverflow.com/questions/42598827/quadratically-constrained-miqp-with-julia-and-gurobi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!