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

Gurobi: Can't access objective #289

Closed
Markus28 opened this issue Jul 12, 2022 · 2 comments · Fixed by #290
Closed

Gurobi: Can't access objective #289

Markus28 opened this issue Jul 12, 2022 · 2 comments · Fixed by #290
Labels
bug Something isn't working gurobi All items related to gurobi

Comments

@Markus28
Copy link
Contributor

In get_objective in gurobi.py you are trying to set the const property of LinExpr, which doesn't have a setter.
To reproduce:

>>> import mip
>>> model = mip.Model(solver_name="gurobi")
Set parameter Username
Academic license - for non-commercial use only - expires 2023-07-07
>>> x = model.add_var("x"I)
>>> model.objective = x
>>> model.objective
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mkrimmel/.local/lib/python3.8/site-packages/mip/model.py", line 821, in objective
    return self.solver.get_objective()
  File "/home/mkrimmel/.local/lib/python3.8/site-packages/mip/gurobi.py", line 543, in get_objective
    obj_expr.const = self.get_objective_const()
AttributeError: can't set attribute

Not sure why const cannot have a setter. Either way, you could just use the constructor of LinExpr directly. I may prepare a PR for this because I probably need to have this fixed.

@sebheger
Copy link
Collaborator

@Markus28 Feel free to open a PR, I will review it. Don't forget to write a unit-test.

@sebheger
Copy link
Collaborator

I guess that could be easily fixed by adding a constant (add_constant) to the expr instead of setting it.

@sebheger sebheger added gurobi All items related to gurobi bug Something isn't working labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gurobi All items related to gurobi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants