From 25affca3ec350555fefc1cbf8897d3df42611880 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Tue, 13 Apr 2021 10:39:36 -0500 Subject: [PATCH] GurobiSolver: Accept integer variables, as long as bounds=(0,1) --- miplearn/solvers/gurobi.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/miplearn/solvers/gurobi.py b/miplearn/solvers/gurobi.py index c0e2633..fd73b1c 100644 --- a/miplearn/solvers/gurobi.py +++ b/miplearn/solvers/gurobi.py @@ -476,12 +476,23 @@ class GurobiSolver(InternalSolver): f"Unique variable names are currently required." ) self._varname_to_var[var.varName] = var - assert var.vtype in ["B", "C"], ( + vtype = var.vtype + if vtype == "I": + assert var.ub == 1.0, ( + "Only binary and continuous variables are currently supported. " + "Integer variable {var.varName} has upper bound {var.ub}." + ) + assert var.lb == 0.0, ( + "Only binary and continuous variables are currently supported. " + "Integer variable {var.varName} has lower bound {var.ub}." + ) + vtype = "B" + assert vtype in ["B", "C"], ( "Only binary and continuous variables are currently supported. " - "Variable {var.varName} has type {var.vtype}." + "Variable {var.varName} has type {vtype}." ) - self._original_vtype[var] = var.vtype - if var.vtype == "B": + self._original_vtype[var] = vtype + if vtype == "B": self._bin_vars.append(var) def __getstate__(self) -> Dict: