From c6b31a827d6c6e682d45171f21478162c0bc46d6 Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Fri, 13 Aug 2021 10:15:23 -0500 Subject: [PATCH] GurobiSolver: Accept non-binary integer variables --- miplearn/solvers/gurobi.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/miplearn/solvers/gurobi.py b/miplearn/solvers/gurobi.py index 751f66c..8311961 100644 --- a/miplearn/solvers/gurobi.py +++ b/miplearn/solvers/gurobi.py @@ -523,12 +523,16 @@ class GurobiSolver(InternalSolver): var.vtype = self.gp.GRB.CONTINUOUS var.lb = 0.0 var.ub = 1.0 + elif self._var_types[i] == b"I": + var.vtype = self.gp.GRB.CONTINUOUS with _RedirectOutput(streams): self.model.optimize() self._dirty = False for (i, var) in enumerate(self._gp_vars): if self._var_types[i] == b"B": var.vtype = self.gp.GRB.BINARY + elif self._var_types[i] == b"I": + var.vtype = self.gp.GRB.INTEGER log = streams[0].getvalue() self._has_lp_solution = self.model.solCount > 0 self._has_mip_solution = False @@ -620,17 +624,7 @@ class GurobiSolver(InternalSolver): f"Duplicated variable name detected: {var_names[i]}. " f"Unique variable names are currently required." ) - if var_types[i] == b"I": - assert var_ubs[i] == 1.0, ( - "Only binary and continuous variables are currently supported. " - f"Integer variable {var_names[i]} has upper bound {var_ubs[i]}." - ) - assert var_lbs[i] == 0.0, ( - "Only binary and continuous variables are currently supported. " - f"Integer variable {var_names[i]} has lower bound {var_ubs[i]}." - ) - var_types[i] = b"B" - assert var_types[i] in [b"B", b"C"], ( + assert var_types[i] in [b"B", b"C", b"I"], ( "Only binary and continuous variables are currently supported. " f"Variable {var_names[i]} has type {var_types[i]}." )