Julia 跳转:LoadError:无法识别的函数:f1用于非线性表达式
我必须生成所有的帕累托点,但我得到了这个错误Julia 跳转:LoadError:无法识别的函数:f1用于非线性表达式,julia,julia-jump,ipopt,Julia,Julia Jump,Ipopt,我必须生成所有的帕累托点,但我得到了这个错误 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
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)
使用跳转
使用古罗比
使用牛虻
使用Ipopt
m=模型(解算器=IpoptSolver(打印级别=0))
@变量(m,0.1
解决了这个问题
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) )
如果将f1
的所有实例替换为x
,会发生什么情况?我的直觉告诉我,在@nlobective
sYes中不允许进行任意函数调用,但我会使用任意函数重用此函数来生成帕累托点。对于此用例,由于您的函数只是封闭形式的表达式,y你应该只使用@NLexpression
而不是用户定义的函数。这通常会表现得更好,因为如果存在用户定义的函数,JuMP当前不会计算二阶导数。请注意JuMP.register
仅定义用于非线性表达式中的函数,例如@NLobjective
或@NLconstraint
。上面的示例是意外工作的,因为f1
是@objective
中使用的线性函数。
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) )