-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Copying a Model and adding new constraints generates an error when calling solve(m) #490
Comments
The error message is correct, the variables belong to the initial model, not the copy. |
Yes. In the code I am working on I have type instance
m :: Model
weight :: Array{Int}
profit :: Array{Int}
size :: Int
capacity :: Int
x
end When I copy the whole thing the model |
I think that #399 is what I want. I just pulled the last version, lets see if it works. |
Here julia> n = copy(m)
Maximization problem with:
* 1 linear constraint
* 2 variables
Solver set to Default
julia> print(m.varDict)
[:x=>x,:y=>y]
julia> print(n.varDict)
Dict{Symbol,Any}()
julia> getVar(m, :y)
y
julia> getVar(n, :y)
ERROR: No variable with name y
in error at error.jl:21
in getVar at /home/h3nnn4n/.julia/v0.3/JuMP/src/JuMP.jl:805
|
Thats true. We'll need to implement code to take an existing variable and mapping it to the new model. I've actually had to do something similar for a JuMP extension, funny enough. |
@h3nnn4n try pulling the latest master and see if it helps. |
It worked. Thank you for the quick responses and all the support. |
Is it still possible to copy a model like this? I get the same error message as @h3nnn4n if I try this (also on his snippet of code).
(Julia 0.4.6, JuMP 0.14) |
You can copy a model, but you can't mix variables from different models. Use |
Thanks Miles, that works! It makes sense as well of course, because you can refer to the variables without mentioning the model (with |
I am trying to do the same in JuMP 0.18.6 and I got exactly the same error: `
and this is the error: When I checked the models details, it seemed that I had the right variables in the copied model:
But when I checked the constraints in the models, the old constraint in the copied model didn't look to be right:
So, can someone tell me what can be wrong here? |
You probably need to use p.s. In future, please post questions like this on the Discourse forum: https://discourse.julialang.org/c/domain/opt. |
@odow Thanks! |
Here I have a small snippet of code that reproduces an error on a bigger piece of code.
The code is:
and the error:
The error happens on both Julia 0.3 and 0.4 using the following packages:
The text was updated successfully, but these errors were encountered: