Skip to main content

How to get all constraints from my model as an output?

Awaiting user input

Comments

5 comments

  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    You can write the complete model using

    model.write("model.lp")

    in Python API, although the file will not look exactly the way you want.

    But I believe it should not be too difficult to come up with a simple Python script that will convert the .lp file. I am not aware of any off-the-shelf scripts which would format the model to the standard you wish to have.

    Best regards
    Jonasz

     

    0
  • Ali Jahanbani Ardakani

    Maybe `rlp` format is what you are looking for.

    model.write("model.rlp")

    but I am not sure how you can convert from the internal Gurobi variable names to the variable names used in your model. Maybe Jonasz Staszek can shed some light on that part (similar to the `dict` file used in GAMS)

    0
  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    Generally, I would recommend giving all the variables a custom name to quickly distinguish one from the other. Then the .lp file will contain the user-defined variable names.

     Just beware not to use spaces in such custom names - there are chances Gurobi will ignore these and use its defaults instead, especially when writing to .lp files.

    .lp files have the advantage over .rlp files that they keep the original variable names (if possible), but you can certainly experiment with other extensions. This article should give you guidance.

    Best regards
    Jonasz

    0
  • Ali Jahanbani Ardakani

    Jonasz Staszek

    None of my variable names contain spaces (they do contain "_" though) and the LP file is using the internal variable names instead of user-defined variable names. Are "_"s causing problems?

    0
  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    I have too little information to tell. I used "_" in my codes and it never caused any trouble.

    If you like, you can share a minimal reproducible example of your code and we'll see what could cause the trouble.

    Best regards
    Jonasz

    0

Please sign in to leave a comment.