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

awkward behavior of macro @variable #818

Closed
IssamT opened this issue Aug 3, 2016 · 1 comment
Closed

awkward behavior of macro @variable #818

IssamT opened this issue Aug 3, 2016 · 1 comment

Comments

@IssamT
Copy link
Contributor

IssamT commented Aug 3, 2016

FIRST_INPUT

workspace()

using JuMP
using Cbc
using Graphs

petersen = simple_petersen_graph()

function max_independent_set(g::SimpleGraph)

    m = Model(solver=CbcSolver())      
    @variable(m, b[v in vertices(g)], Bin)   
    @constraint(m , nonadjacency[e in edges(g)], b[source(e)] + b[target(e)] <= 1)
    @objective(m, Max, sum{b[v] , v in vertices(g)})

    solve(m)

    @show typeof(1:10)
    @show typeof(vertices(g))    
    @show typeof(b)         
end

max_independent_set(petersen)

FIRST_OUTPUT:

typeof(1:10) = UnitRange{Int32}
typeof(vertices(g)) = UnitRange{Int32}
typeof(b) = JuMP.JuMPArray{JuMP.Variable,1,Tuple{UnitRange{Int32}}}

MODIFYING_INPUT

Instead of
@variable(m, b[v in vertices(g)], Bin)
I write
@variable(m, b[v in 1:10], Bin)

SECOND_OUTPUT

typeof(1:10) = UnitRange{Int32}
typeof(vertices(g)) = UnitRange{Int32}
typeof(b) = Array{JuMP.Variable,1}

Notice that 1:10 and vertices(g) are exactly the same (and have the same type) in my case, except on the symbolic level which, in my opinion, is causing the issue here.

I think that for the current version, it would be worth mentioning somewhere in the doc that if you use, for indices, a unit range as a "literal" the variables will be stored in an array but if you use a unit range not as a "literal" the variables will be stored in a dictionary; since this can have an impact on the performance, especially for callbacks...

@mlubin
Copy link
Member

mlubin commented Aug 3, 2016

This is a dup of the longstanding issue #346. Shouldn't be too hard to implement at this point.

@mlubin mlubin closed this as completed Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants