Skip to content

Conversation

@shlee8585-lab
Copy link

@shlee8585-lab shlee8585-lab commented Oct 29, 2025

Hello,

This PR fixes a bug in the gurobi_py solver interface where binary variables (LpBinary) were being incorrectly treated as general countinuos (GRB.CONTINUOUS) when solving an MIP problem (i.e., when self.mip is True).

Description of the Bug
Currently, the variable type logic is:

"""
varType = gp.GRB.CONTINUOUS
if var.cat == constants.LpInteger and self.mip:
varType = gp.GRB.INTEGER
"""

Proposed Change
This patch adds a subsequent if statement to ensure that LpBinary variables are correctly identified and set to GRB.BINARY

Change:
"""
varType = gp.GRB.CONTINUOUS
if var.cat == constants.LpInteger and self.mip:
varType = gp.GRB.INTEGER
if var.cat == constants.LpBinary and self.mip:
varType = gp.GRB.BINARY
"""

Bug: Binary variables not treated as binary in gurobi_py MIP solve
@CLAassistant
Copy link

CLAassistant commented Oct 29, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pchtsp
Copy link
Collaborator

pchtsp commented Nov 3, 2025

I don't think this may work. You should also check for Integer variables with a [0, 1] range. A more robust way is just to ask the right method:

if var.isBinary() and self.mip:
    varType = gp.GRB.BINARY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants