我必须生成所有的帕累托点,但是我收到了这个错误。
using JuMP
using Gurobi
using Gadfly
using Ipopt
m = Model(solver=IpoptSolver(print_level=0))
@variable(m, 0.1 <= x <= 1.0)
@variable(m, 0.0 <= y <= 1.0)
pareto_x = Float16[]
pareto_y = Float16[]
for i in 0.0:0.1:1.0
for j in 0.0:0.1:1.0
f1(x,y) = x
f2(x,y) = (2.0-exp(-((y-0.2)/0.004)^2)-0.8*exp(-((y-0.6)/0.4)^2) )/x
@NLobjective(m, Min, i*f1(x,y) + j*f2(x,y) ) ## <<-- ERROR HERE
status = solve(m)
println("Objective value: ", getobjectivevalue(m))
x_opt = getvalue(x)
y_opt = getvalue(y)
println("x = ", x_opt)
println("y = ", y_opt)
push!(pareto_x,f1(x_opt,y_opt))
push!(pareto_y,f2(x_opt,y_opt))
end
end
plot(x=pareto_x, y=pareto_y)
答案 0 :(得分:1)
http://jump.readthedocs.io/en/latest/nlp.html#user-defined-functions
mysquare(x) = x^2
myf(x,y) = (x-1)^2+(y-2)^2
JuMP.register(:myf, 2, myf, autodiff=true)
JuMP.register(:mysquare, 1, mysquare, autodiff=true)
m = Model()
@variable(m, x[1:2] >= 0.5)
@NLobjective(m, Min, myf(x[1],mysquare(x[2])))
SOLVED with this
f1(x,y) = x
f2(x,y) = (2.0-exp(-((y-0.2)/0.004)^2)-0.8*exp(-((y-0.6)/0.4)^2) )/x
isdefined(:f1) || JuMP.register(:f1, 2, f1, autodiff=true)
isdefined(:f2) || JuMP.register(:f2, 2, f2, autodiff=true)
@objective(m, Min, f1(x,y) )