Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot iterate over keys of a variable in 0.18.4 #2007

Closed
bbrunaud opened this issue Jul 11, 2019 · 6 comments
Closed

Cannot iterate over keys of a variable in 0.18.4 #2007

bbrunaud opened this issue Jul 11, 2019 · 6 comments

Comments

@bbrunaud
Copy link

I used to frequently iterate over the keys of a variable to get the nonzero values. Now I get an error with that code. I am using 0.18.4

julia> x = m[:x]
0 <= x[j,p,t] <= .. for all j in {FMP 01,FMP 03,..,TAM 05R,FMP 01R}, p in {1DAR,1NAR,..,TRI,TRIA}, t in {1,2,..,59,60}

julia> for k in keys(x)
         println(k)
       end
x[FMP 01,1DAR,1]
ERROR: UndefVarError: next not defined
Stacktrace:
 [1] __next(::JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}, ::Int64) at C:\Users\bbr
unaud\.julia\packages\JuMP\PbnIJ\src\JuMPContainer.jl:346
 [2] iterate(::JuMP.KeyIterator{JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}}, ::Int
64) at C:\Users\bbrunaud\.julia\packages\JuMP\PbnIJ\src\JuMPContainer.jl:355
 [3] top-level scope at .\REPL[2]:2 [inlined]
 [4] top-level scope at .\none:0

julia> collect(keys(x))
ERROR: UndefVarError: next not defined
Stacktrace:
 [1] __next(::JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}, ::Int64) at C:\Users\bbr
unaud\.julia\packages\JuMP\PbnIJ\src\JuMPContainer.jl:346
 [2] iterate(::JuMP.KeyIterator{JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}}, ::Int
64) at C:\Users\bbrunaud\.julia\packages\JuMP\PbnIJ\src\JuMPContainer.jl:355
 [3] copyto!(::Array{Any,1}, ::JuMP.KeyIterator{JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{In
t64,1}}}}) at .\abstractarray.jl:672
 [4] _collect at .\array.jl:550 [inlined]
 [5] collect(::JuMP.KeyIterator{JuMP.JuMPArray{Variable,3,Tuple{Array{String,1},Array{String,1},Array{Int64,1}}}}) at .\
array.jl:544
 [6] top-level scope at none:0
@odow odow added the Type: Bug label Jul 18, 2019
@odow
Copy link
Member

odow commented Jul 18, 2019

Can you test on 0.18.6 to see if it still broken?

@joyceraraujo
Copy link

Some update about this issue ? I got the same problem when I have tried to use:
for key in (sort!(collect(keys(var))))
That’s really bad for me because my whole set of variables is multi-index (like, [“id”,“region”,“city”] and it’s very important to me be able to sweep the index in many parts of my code.
I have to use Clp Solver, so the JuMP version I have been using is 0.9.0.

@odow
Copy link
Member

odow commented Sep 4, 2019

This is fixed in JuMP 0.19 onwards. Can you update?

@joyceraraujo
Copy link

Thanks for your return, but I cannot update because Clp is not compatible with new versions of JuMP.
I have found another way to iterate over the index, for someone is interested : https://discourse.julialang.org/t/jump-filtering-the-output-of-jump-value-x/25391/2

@blegat
Copy link
Member

blegat commented Sep 5, 2019

Clp is not compatible yet to JuMP v0.20 but it is compatible with JuMP v0.19

@odow
Copy link
Member

odow commented Nov 27, 2020

Closing as out-dated. We won't be fixing this in 0.18, and it is fixed in JuMP 0.21.

@odow odow closed this as completed Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants