因此,以下代码的目的是查找具有整数标准差的小型数据集的示例。这可以表述为一个二次约束的混合整数二次程序,所以我尝试使用来自 Julia 的 Gurobin。以下是我的代码:
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)
运行此结果:
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
有任何想法吗?