Copy a class of model
AnsweredHello,
I have a model that is defined inside a class. I am updating the model and apply changes to it using a class.
I am applying a branch and bound algorithm and when branching is required, I want to copy the class of model from the parent node and add new constraints on bounds. When I use copy.copy() in python and change the new node of branch a bound tree, the original model changes as well.
I tried using copy.deepcopy() but faced the error: "RecursionError: maximum recursion depth exceeded while calling a Python object". I tried it on a small model within a class but still having the same error. I increased the system recurssion limit by sys.setrecursionlimit(n), but did not work.
I am wondering what is causing the error and preventing copy of the class.
Thakns, Farzane
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Farzane,
Creating a (deep) copy of your model should be done with Model.copy().
Note however the object is just the model, it does not include the branch and bound tree (which exists inside the Gurobi Optimizer and not Python), solutions or anything related to prior optimizations and so optimization on the new model would start from scratch:
m = gp.read("mymodel.mps")
m.optimize()
print(m.Status) # prints 2 (= OPTIMAL)
m2 = m.copy()
print(m2.Status) # prints 1 (= LOADED)- Riley
0
Post is closed for comments.
Comments
2 comments