メインコンテンツへスキップ

Error reading LP format file - Neighboring tokens

ユーザーの入力を待っています。

コメント

5件のコメント

  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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
    End

    If you're interested in trying out the Python interface, I recommend:

    0
  • Federico Franceschini
    • Gurobi-versary
    • First Question
    • First Comment

    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
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    Yes, that means Gurobi successfully read the LP file, but the model is infeasible.

    0
  • Federico Franceschini
    • Gurobi-versary
    • First Question
    • First Comment

    Okay.

    By the way, these two webpages:

    https://support.gurobi.com/hc/en-us/articles/360029969391-How-do-I-determine-why-my-model-is-infeasible-

    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
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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

サインインしてコメントを残してください。