You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I = 1:10
@variable(m, x[v in I], Bin)
...
solve(m)
b = getvalue(x)
This function, I wrote, crashes when I provide b as an argument
function bin_decisions(b::JuMP.JuMPArray)
ret = []
for v in keys(b)
b[v] == 1.0 && push!(ret,v)
end
ret
end
If I understood well the JuMPArray in this case is indexed with a tuple that contains one element, which I'm fine with, but the issue is that to access an element in b you can t use the 1-element tuple as index => inconsistency between keys and the operator [].
Basically the function that works is this one.
function bin_decisions(b::JuMP.JuMPArray)
ret = []
for v in keys(b)
b[v[1]] == 1.0 && push!(ret,v)
end
ret
end
I am quite new to julia and in particual to JuMP. So, I would like just a confirmation that this is a bug and I will try to find the error and suggest a fix.
The text was updated successfully, but these errors were encountered:
This is closely related to #646. This is a thorny issue and we're not entirely happy with the current implementation, but we also don't have a better solution that avoids the ambiguity here (suggestions welcome). Regardless, this code should work as well:
functionbin_decisions(b::JuMP.JuMPArray)
ret = []
for v inkeys(b)
b[v...] ==1.0&&push!(ret,v)
end
ret
end
Thanks for the fast reply. I confirm that your code works as well and is more generic than my solution.
The fact that my solution was not generic is the thing that annoyed me the most since I am not a language purist.
However I will think about a way to fix this inconsistency between keys and the operator[] and if I have a suggestion I will provide it in the thread #646 because it is indeed the same issue. So feel free to close this one.
For a binary variable that was created like this:
This function, I wrote, crashes when I provide b as an argument
If I understood well the JuMPArray in this case is indexed with a tuple that contains one element, which I'm fine with, but the issue is that to access an element in b you can t use the 1-element tuple as index => inconsistency between keys and the operator [].
Basically the function that works is this one.
I am quite new to julia and in particual to JuMP. So, I would like just a confirmation that this is a bug and I will try to find the error and suggest a fix.
The text was updated successfully, but these errors were encountered: