我想将一个SymPy表达式转换为JuMP中的目标函数,假设该变量涉及两个变量。
"和模型"
这个问题也在另一个平台上提出过:https://discourse.julialang.org/t/how-to-pass-a-sympy-expression-supported-by-jump/62109/3。
x = Sym("x")
y = Sym("y")
expr = x^2 + y
fn = lambdify( expr )
"和模型"
model = Model(Ipopt.Optimizer)
l = zeros(1,2)
@variable(model, x[ j = 1:2] >= 0 )
register(model, :fn,2, fn, autodiff = true)
#obj function
@NLobjective(model,Min,fn)
print(model)
Unexpected object #99 (of type SymPy.var"#99#100"{SymPy.var"###792"} in nonlinear expression.
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] _parse_NL_expr_runtime(::Model, ::Function, ::Array{JuMP._Derivatives.NodeData,1}, ::Int64, ::Array{Float64,1}) at C:\Users\xxxxx\.julia\packages\JuMP\e0Uc2\src\parse_nlp.jl:223
[3] top-level scope at C:\Users\xxxxx\.julia\packages\JuMP\e0Uc2\src\parse_nlp.jl:247
[4] top-level scope at C:\Users\xxxxx\.julia\packages\JuMP\e0Uc2\src\macros.jl:1368
[5] top-level scope at In[92]:8
[6] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
这个问题也在另一个平台上提出过:https://discourse.julialang.org/t/how-to-pass-a-sympy-expression-supported-by-jump/62109/3。