LoadError: UndefVarError: @defVar not defined

I have a piece of code about JuMP. When I run it ,it says that LoadError: UndefVarError: @defVar not defined. I have tried using global forward or backward but both fails.


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, σ

LoadError: UndefVarError: @defVar not defined
in expression starting at In[44]:37

 [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


First of all, welcome to our community! :confetti_ball:

From where @defVar comes? JuMP uses @variable to define variables, not @defVar. Is this code wrote in a very old version of JuMP?

I have tried using global forward or backward but both fails.

I have no idea of what you mean by this.

1 Like

Thank you very much. I did use the old version of the jump command.Thanks again

1 Like

I haven’t seen @defVar in years! Where did you get the old code from? We’ve tried to excise old tutorials and documentation from the internet.


That’s great! I get the old code from: JuliaOpt - Optimization packages for the Julia language
Thank you for your work