I'm working in Python 2.7 and using the PuLP library to setup a problem. Once the variables, objective and constraints are defined, I pickle my LpProblem object to send off to a Solver elsewhere. Upon un-pickling my problem, I notice that all of the variables are duplicated:
import pulp
import pickle
prob = pulp.LpProblem('test problem', pulp.LpMaximize)
x = pulp.LpVariable('x', 0, 10)
y = pulp.LpVariable('y', 3, 6)
prob += x + y
prob += x <= 5
print prob
print pickle.loads(pickle.dumps(prob))
The first print statement outputs:
>>> print prob
test problem:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x <= 5
VARIABLES
x <= 10 Continuous
3 <= y <= 6 Continuous
while the second prints:
>>> print pickle.loads(pickle.dumps(prob))
test problem:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x <= 5
VARIABLES
x <= 10 Continuous
x <= 10 Continuous
3 <= y <= 6 Continuous
3 <= y <= 6 Continuous
As you can see, the objective and constraints are fine, but all of the variables are duplicated. What causes this behavior, and how can I prevent this from happening?