Skip to content

Commit

Permalink
fix(gurobi_interface): Added is_mip property function and updated sha…
Browse files Browse the repository at this point in the history
…dow_prices and reduced_costs to check for MIP before accessing non-existant variables. (#259)
  • Loading branch information
Palaract authored Feb 8, 2024
1 parent d84532d commit 92517c4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/optlang/gurobi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ def _get_reduced_costs(self):
if self.is_integer:
raise ValueError(
"Reduced costs are not well defined for integer problems.")
if self.is_mip:
raise ValueError(
"Reduced costs are not well defined for mixed integer problems. Try relaxing your model first.")
return self.problem.RC

def _get_shadow_prices(self):
Expand All @@ -789,13 +792,21 @@ def _get_shadow_prices(self):
if self.is_integer:
raise ValueError(
"Shadow prices are not well defined for integer problems.")
if self.is_mip:
raise ValueError(
"Shadow prices are not well defined for mixed integer problems. Try relaxing your model first.")
return self.problem.Pi

@property
def is_integer(self):
self.problem.update()
return self.problem.NumIntVars > 0

@property
def is_mip(self):
self.problem.update()
return self.problem.IsMIP == 1


if __name__ == '__main__':
x = Variable('x', lb=0, ub=10)
Expand Down

0 comments on commit 92517c4

Please sign in to comment.