UndefVarError in JuMP constraint

I’m using the dev version of JuMP (primarily for compatibility with Julia 1.0) with GLPK, and I encountered this error which I can’t figure out:

ERROR: LoadError: UndefVarError: ##366 not defined
 [1] macro expansion at /Users/chisquared/.julia/dev/JuMP/src/parseexpr.jl:354 [inlined]
 [2] top-level scope at /Users/chisquared/.julia/dev/JuMP/src/macros.jl:286
 [3] include_string(::Module, ::String, ::String) at ./loading.jl:1002
 [4] (::getfield(Atom, Symbol("##128#133")){String,String,Module})() at /Users/chisquared/.julia/packages/Atom/Fha1N/src/eval.jl:120
 [5] withpath(::getfield(Atom, Symbol("##128#133")){String,String,Module}, ::String) at /Users/chisquared/.julia/packages/CodeTools/hB4Hy/src/utils.jl:30
 [6] withpath at /Users/chisquared/.julia/packages/Atom/Fha1N/src/eval.jl:46 [inlined]
 [7] #127 at /Users/chisquared/.julia/packages/Atom/Fha1N/src/eval.jl:117 [inlined]
 [8] hideprompt(::getfield(Atom, Symbol("##127#132")){String,String,Module}) at /Users/chisquared/.julia/packages/Atom/Fha1N/src/repl.jl:84
 [9] macro expansion at /Users/chisquared/.julia/packages/Atom/Fha1N/src/eval.jl:116 [inlined]
 [10] (::getfield(Atom, Symbol("##126#131")){Dict{String,Any}})() at ./task.jl:85
in expression starting at /Users/chisquared/Dropbox/Julia/jumperr.jl:16

This is the code that generates the error:

using JuMP, GLPK

pH = 1/2
pL = 1 - pH
vH = 2/3
vL = 1/3

sigL = [1/3 1/3 1/3]
sigH = [1/3 1/3 1/3]
model = Model(with_optimizer(GLPK.Optimizer))
@variable(model,0 <= xH <= 1)
@variable(model,0 <= tH <= 1)

@constraint(model,ICH,vH*xH - tH >= sum(sigH[i]*(vH * xL[i] - tL[i]) for i in 1:length(sigH)))

The error occurs exclusively in the last line. If instead, I replace the last line with

@constraint(model,IRL,sum(sigL[i]*(vL*xL[i] - tL[i]) for i in 1:length(sigL)) >= 0)

I get a very similar, but different error:

ERROR: LoadError: UndefVarError: q not defined

Could someone explain what’s going on? I already have a workaround using dot, but I’d like to understand what is happening here. Thanks.

This was fixed in https://github.com/JuliaOpt/JuMP.jl/pull/1497 a few days ago but the PR is not merged yet.
You can do

] add JuMP#bl/hygiene

to use the fix.

This works. Thanks!

By the way, while your PR fixes the problems in my original post, but there still seems to be a similar error from the following line:

@objective(model,Max,pH * tH + pL * sum(sigL[i]*tL[i] for i in 1:length(sigL)))

Appending this line to the code in my original post gives the following error message:

ERROR: UndefVarError: ##385 not defined
 [1] macro expansion at /Users/chisquared/.julia/packages/JuMP/ETBj9/src/parseexpr.jl:354 [inlined]
 [2] top-level scope at /Users/chisquared/.julia/packages/JuMP/ETBj9/src/macros.jl:876

Should be fixed in https://github.com/JuliaOpt/JuMP.jl/pull/1517

1 Like