Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIP check in gurobi interface and update shadow_prices and reduced_cost to throw proper error if MIP #259

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading