Get rid of a JuMP model

Hi All,

I have a function in my code that builds a model and solve it and return the result. I have to call this function repeatedly. Although my code works properly I get the following warning after calling the function which makes my code super sluggish as it goes forward.

Warning: A variable or constraint named va is already attached to this model. If creating variables programmatically, use the anonymous variable syntax x = @variable(m, [1:N], ...).

Can you please let me know how I can get rid of the model after it is solved to prevent this issue. Any help would be appreciated.

All the best,
Rasoul

What do you get when you replace the declaration for va by something like

x = @variable(m, [1:N], ...).

as suggested?

It is not clear how to define variables as is suggested by the warnings. variables in the model are kept and new variables would be added to the model as the code goes forward. There should be a way to get rid of the older variables in the model. Please let me know if you have any information about removing variables in a model. Thanks in advance!

Do post some code so we can help you.

1 Like

The current released version of JuMP (0.18) does not have the ability to delete variables.

This oversight is fixed in the upcoming release of JuMP. (Read more about that here.)

If you want to try it out for a spin, there are installation instructions at JuMP 0.19-beta released (JuMP/MathOptInterface). (Warning! It’s a beta!)

Once you’re using the beta, you can read about deleting variables in the new docs .

2 Likes