Suspected bug in LP parser: Constraint without variables introduces new variables
AnsweredI think I found a bug in Gurobi 9.0.3. Take this example.lp file:
Maximize
x
Subject To
test: 10 >= 5
Bounds
0 <= x <= 5
Generals
x
End
If I run
from gurobipy import read
m = read('example.lp')
print(m.getVars())
I get the output
[<gurobi.Var x>, <gurobi.Var 10>]
Obviously, that constraint is not very useful. However, according to the specification of the LP format in the documentation, it is valid: Both the left-hand and the right-hand side are required to be "linear expressions", and a constant should be a linear expression, right?
In any case, introducing a new variable named "10" seems to be the wrong behavior.
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Lukas,
I don't get your point. The constraint in this LP file is obviously nonsense. Gurobi handling it by adding a variable called "10" seems to be a straight-forward and logical resolution.
Please note that the LP file documentation also states:
Note that the left-hand side of a constraint may not contain a constant term; the constant must appear on the right-hand side.
This renders this LP file formulation incorrect and when using the Gurobi command line tool, a warning is displayed:
Warning: Numeric variable name in LP file ('10') - often the result
of a constant term in the left-hand side of a constraint.Cheers,
Matthias0 -
Hi Matthias,
Thanks for your reply. I missed the part about the left-hand side not being allowed to contain any constants, so Gurobi is right here!
While these "constraints" are certainly nonsense, I'm faced with a tool that generates models for Gurobi, and in some specific cases generates constraints of this form. I probably need to patch it to avoid this.
Thanks,
Lukas
0 -
Hi Lukas,
Just a piece of advice: don't use LP files for anything other than manually inspecting a model. There are many pitfalls when automatically generating LP files. I strongly recommend using our Python API or any other API to do this job and then save the model as MPS file.
Cheers,
Matthias0
Post is closed for comments.
Comments
4 comments