Error reading LP format file - Neighboring tokens
Awaiting user inputHi there,
I've been trying and trying to run a LP file but I always receive the following expressions: - Error reading LP format file (path) at line 3. Malformed term in expression. Neighboring tokens: " ( 7.5 r_1 + 15 r_2 + 16.5 r_3 + ". Error 10012: Unable to read file -
Here is the first piece of the LP file where I get the error:
Minimize
30 r_1 + 45 r_2 + 40 r_3 + 30 r_4 + 10 r_5 + 30 p
Subject To
v: ( 7.5 r_1 + 15 r_2 + 16.5 r_3 + 2.5 r_4 + 5 r_5 ) * 360 = d
I've also tried changing that constraint with the following:
v: ( 7.5 r_1 + 15 r_2 + 16.5 r_3 + 2.5 r_4 + 5 r_5 ) * 360 / d = 1
But I always have the same error. How can I solve the issue?
P.S. I've just noticed that it's forbidden to divide by a variable in Gurobi, but I don't know how I can change that constraint
Thanks in advance for your support!
-
Official comment
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
I really don't recommend building your model as an LP file. It's time-consuming, and you will run into a lot of formatting issues like this. The issues here are:
- The \(360\) should be distributed to each term inside the parentheses
- Variables like \(d\) should appear on the left-hand side of the constraint
Gurobi's Python API is straightforward to use and less error-prone. Here is a simple Python script that builds the same model:
import gurobipy as gp
from gurobipy import GRB
m = gp.Model()
r = m.addVars(5, name="r")
p = m.addVar(name="p")
d = m.addVar(name="d")
m.addConstr(
360 * (7.5 * r[0] + 15 * r[1] + 16.5 * r[2] + 2.5 * r[3] + 5 * r[4]) == d, name="v"
)
m.setObjective(
30 * r[0] + 45 * r[1] + 40 * r[2] + 30 * r[3] + 10 * r[4] + 30 * p, GRB.MINIMIZE
)
m.write("model.lp")
m.optimize()The LP file contains the following contents:
Minimize
30 r[0] + 45 r[1] + 40 r[2] + 30 r[3] + 10 r[4] + 30 p
Subject To
v: 2700 r[0] + 5400 r[1] + 5940 r[2] + 900 r[3] + 1800 r[4] - d = 0
Bounds
EndIf you're interested in trying out the Python interface, I recommend:
- The How do I install Gurobi for Python? article
- The Linear Programming Formulation with Gurobi Python API video
- Gurobi's functional code examples (mip1.py is a good start)
0 -
Dear Eli,
thank you for your reply. Unfortunately I had already corrected those issues and built the model as a LP file, before reading your kind reply.
Anyway, Gurobi says: "Solution count 0", "Model is infeasible", without finding any optimal solution.
So does it mean that the model has no formatting issue? Even though I must correct the model itself on my paper sheet.
0 -
Yes, that means Gurobi successfully read the LP file, but the model is infeasible.
0 -
Okay.
By the way, these two webpages:
https://www.gurobi.com/documentation/10.0/refman/py_model_computeiis.html
They explain the way to detect the subset of constraints which render the model not feasible, by computing an Irreducible Inconsistent Subsystem (IIS).
However I don't understand where and how I can compute it and, moreover, would it be fine to compute it with the LP file?
0 -
Are you solving the model with Gurobi's command-line tool (\(\texttt{gurobi_cl}\))? If so, you can set the ResultFile parameter to an ILP file. This will direct Gurobi to compute an IIS and write it to disk. For example:
gurobi_cl model.lp resultfile=model.ilp
0
Post is closed for comments.
Comments
6 comments