3
$\begingroup$

I have just attempted to construct my first Pyomo model.

However, I was unable to locate any documentation that shows how to view constraints, decision variables.

As my model is big, I need to see that they are created and indexed correctly from time-to-time before proceeding further.

May I ask if anyone has chanced upon such documentation or have devised any ingenious method to do so within the confines of Python or Pyomo syntax?

Thank you!

$\endgroup$
  • 1
    $\begingroup$ Not too familiar with Pyomo, but wouldn’t model.write(“model.lp”) write your model to an lp file (which is very readable) $\endgroup$ – Mason Jul 22 at 1:27
2
$\begingroup$

After defining your model by putting the following statement in your code (wherever you want before or after solve command) your model with all the objects has been printed:

model.pprint() 

If you like to print constraints or variables individually:

model.cons1.pprint()  # For entire ConstraintList
print(model.cons2[i].expr)  # For only one index of ConstraintList
model.write() # To write the model into a file using .nl format

Assuming that model is the model that you defined and cons1 and cons2 are two ConstraintsList in that model.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Thanks again for your generosity! $\endgroup$ – Mike Jul 24 at 2:44
  • $\begingroup$ @Mike you are welcome... $\endgroup$ – Oguz Toragay Jul 24 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.