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 interface gives incorrect primal for constraints #115

Closed
cdiener opened this issue Jul 18, 2017 · 1 comment
Closed

Gurobi interface gives incorrect primal for constraints #115

cdiener opened this issue Jul 18, 2017 · 1 comment

Comments

@cdiener
Copy link
Member

cdiener commented Jul 18, 2017

In the following model (zipped JSON) you have a constraint "test" whose primal will have the wrong sign after optimizing.

File: bad.zip

Basically you get stuff like this when having constraints with only a lower bound:

In [95]: mod.solver.optimize()
'optimal'

In [96]: print(mod.constraints.test)
test: 0.0 <= -1.0*Biomass_Ecoli_core_reverse_2cdba + 1.0*Biomass_Ecoli_core

In [97]: mod.constraints.test.primal
Out[97]: -0.8739215069684309

I think the problem is that optlang returns the slack variable from the associated optlang interface, however those change their sign depending on the type of constraint (negative for >= and positive for <=)...

@cdiener
Copy link
Member Author

cdiener commented Jul 27, 2017

Actually, it never gives the correct primals...

For instance:

In [1]: import optlang

In [2]: gurobi = optlang.gurobi_interface

In [3]: mod = gurobi.Model()
Academic license - for non-commercial use only

In [4]: x = gurobi.Variable(lb=3, ub=3, name="x")

In [5]: const = gurobi.Constraint(x, ub=5)

In [6]: mod.add([x, const])

In [7]: mod.optimize()
Out[7]: 'optimal'

In [8]: const.primal
Out[8]: 2.0

In [9]: x.primal
Out[9]: 3.0

In [10]: const.lb = 3

In [11]: const.ub = 3

In [12]: mod.optimize()
Out[12]: 'optimal'

In [13]: const.primal
Out[13]: 0.0

In both cases the correct primal for the constraint is 3, but optlang gives 2 and 0.

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

No branches or pull requests

2 participants