Skip to content

Commit

Permalink
1.4.7
Browse files Browse the repository at this point in the history
* fix: except AttributeError when setting tolerance on cloned Configuration
Enable cloning models between solver interfaces that do not support the same set of tolerance parameters.
  • Loading branch information
KristianJensen authored Oct 9, 2020
1 parent cb49106 commit a7c02b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/optlang/cplex_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ def __init__(self, lp_method='primal', presolve="auto", verbosity=0, timeout=Non
self.qp_method = qp_method
if "tolerances" in kwargs:
for key, val in six.iteritems(kwargs["tolerances"]):
setattr(self.tolerances, key, val)
try:
setattr(self.tolerances, key, val)
except AttributeError:
pass

@property
def lp_method(self):
Expand Down
5 changes: 4 additions & 1 deletion src/optlang/glpk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ def __init__(self, presolve="auto", verbosity=0, timeout=None, *args, **kwargs):
self.timeout = timeout
if "tolerances" in kwargs:
for key, val in six.iteritems(kwargs["tolerances"]):
setattr(self.tolerances, key, val)
try:
setattr(self.tolerances, key, val)
except AttributeError:
pass

def __getstate__(self):
return {'presolve': self.presolve,
Expand Down
6 changes: 6 additions & 0 deletions src/optlang/gurobi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ def __init__(self, lp_method='primal', qp_method='primal', presolve=False,
self.qp_method = qp_method
self.presolve = presolve
self.timeout = timeout
if "tolerances" in kwargs:
for key, val in six.iteritems(kwargs["tolerances"]):
try:
setattr(self.tolerances, key, val)
except AttributeError:
pass

@property
def lp_method(self):
Expand Down
3 changes: 2 additions & 1 deletion src/optlang/tests/test_change_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_clone_to_cplex(self):
self.assertIs(constraint.__class__, cplex.Constraint)

def test_clone_to_glpk(self):
glpk_model = glpk.Model.clone(self.model)
cplex_model = cplex.Model.clone(self.model)
glpk_model = glpk.Model.clone(cplex_model)
self.assertEqual(glpk_model.__class__, glpk.Model)
for variable in glpk_model.variables.values():
self.assertIs(variable.__class__, glpk.Variable)
Expand Down

0 comments on commit a7c02b2

Please sign in to comment.