diff --git a/src/optlang/cplex_interface.py b/src/optlang/cplex_interface.py index c1184caf..5efa5756 100644 --- a/src/optlang/cplex_interface.py +++ b/src/optlang/cplex_interface.py @@ -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): diff --git a/src/optlang/glpk_interface.py b/src/optlang/glpk_interface.py index 6a9e237a..593f20d9 100644 --- a/src/optlang/glpk_interface.py +++ b/src/optlang/glpk_interface.py @@ -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, diff --git a/src/optlang/gurobi_interface.py b/src/optlang/gurobi_interface.py index 7528919f..f1f51767 100644 --- a/src/optlang/gurobi_interface.py +++ b/src/optlang/gurobi_interface.py @@ -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): diff --git a/src/optlang/tests/test_change_solver.py b/src/optlang/tests/test_change_solver.py index 8dc8e0d2..7cf412fe 100644 --- a/src/optlang/tests/test_change_solver.py +++ b/src/optlang/tests/test_change_solver.py @@ -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)