-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
@constraint
uses more memory with AffExpr
#1113
Comments
|
That should not really be related, right? I'm only timing the line with |
I don't know if the lines push!.(supply, 1.0, supply1)
push!.(supply, 1.0, supply2) are doing what you expect. When The version below runs in about the same time and memory as function addconst3(n)
demand = zeros(n)
model = Model()
supply1 = @variable(model, [1:n], lowerbound = 0, upperbound = 0.5)
supply2 = @variable(model, [1:n], lowerbound = 0, upperbound = 0.5)
supply = supply1 .+ supply2
@time @constraint(model, [i in 1:n], supply[i] == demand[i])
end |
Indeed, for i in 1:n
push!(supply[i], 1.0, supply1[i])
push!(supply[i], 1.0, supply2[i])
end I wrongly assumed that this would add |
Changing supply = zeros(AffExpr, n) to supply = [AffExpr(0) for i in 1:n] Fixes |
Consider the following code:
I get:
Why does the second version of
@constraints
consume so much more memory?Is there a way to make this more efficient?
I would like to have a demand and a supply AffExpr, to which I can programatically add different variables. Is this possible in a more memory-friendly way?
The text was updated successfully, but these errors were encountered: