Hi,
I've noticed that docplex does not synchronize the variable bounds with cplex for the variables that updated their bounds after creation when exporting the model as sav or mps.
In my use case I build the model, save it and then load and solve it later. I've noticed the problem since building the model then solving it directly would produce a solution, while loading the saved model would not.
Below it's a simple reproduction of this issue:
from docplex.mp.model import Mode
model = Model('example')
v1 = model.continuous_var(-1, 1, 'v1')
v2 = model.continuous_var(-1, 2, 'v2')
model.add_constraint(v2>=v1)
v2.ub = 10
print(model.export_as_mps_string())
This prints:
* ENCODING=ISO-8859-1
NAME
ROWS
N obj1
G c1
COLUMNS
v1 c1 -1
v2 c1 1
RHS
BOUNDS
LO bnd v1 -1
UP bnd v1 1
LO bnd v2 -1
UP bnd v2 2
ENDATA
The variable v2 has the original upper bound of 2, not the correct one of 10.
Updating the example to call the internal method "model._Model__engine.sync_cplex(model)" like done before a solve will produce the correct output:
from docplex.mp.model import Model
model = Model('example')
v1 = model.continuous_var(-1, 1, 'v1')
v2 = model.continuous_var(-1, 2, 'v2')
model.add_constraint(v2>=v1)
v2.ub = 10
model._Model__engine.sync_cplex(model)
print(model.export_as_mps_string())
I've tested this on both docplex 2.19.202 and 2.15.194 and the result is the same.
Is there a way to force synchronization of the model that's not using the internal method?
I've noticed that solving the model, even without letting it complete, by setting a very small time limit, will make the synchronization happen allowing exporting the correct model.
Exporting to LP does not have this problem, but the LP format is not optimal for my use case.
Thank you,
Best
------------------------------
Federico Caselli
------------------------------
#DecisionOptimization