我有一段关于JuMP的代码。当我运行它时,它显示没有定义LoadError: UndefVarError:@defVar。我尝试使用全局向前或向后,但都失败了。
请参见:
function T1(w_func,grid_b,β,u,z)
# objective for each grid point
for j in 1:cp.Nb
b = grid_b[j]
choice1 = Model(solver=GLPKSolverLP())
@defVar (choice1, a >= 0)
@setObjective(choice1, Max, u(a) + cp.β * (w_func.((b*(1+cp.r)+cp.w-a) .* cp.z[i])))
results1 = solve(choice1)
Tw1 = getObjectiveValue(choice1)
c_choice1 = getValue(x)
return Tw, σ
end
end
LoadError: UndefVarError: @defVar not defined
in expression starting at In[44]:37
Stacktrace:
[1] top-level scope
@ :0
[2] eval
@ ./boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1094
thanks发布于 2021-08-09 07:03:50
看起来你使用的是过时的代码。查看fresh documentation,并确保安装了最新版本的库和Julia。
简而言之,@defVar和@setObjective相应地被@variable和@objective所取代。
function T1(w_func,grid_b,β,u,z)
# objective for each grid point
for j in 1:cp.Nb
b = grid_b[j]
choice1 = Model(solver=GLPKSolverLP())
@variable(choice1, a >= 0)
@objective(choice1, Max, u(a) + cp.β * (w_func.((b*(1+cp.r)+cp.w-a) .* cp.z[i])))
results1 = solve(choice1)
Tw1 = getObjectiveValue(choice1)
c_choice1 = getValue(x)
return Tw, σ
end
end https://stackoverflow.com/questions/68702123
复制相似问题