Output concrete model like the pprint() format

338 views
Skip to first unread message

wt00...@gmail.com

unread,
Feb 4, 2021, 12:13:12 PM2/4/21
to Pyomo Forum
Dear All,

I would like to know if there is any way to output a concrete model with the format like pprint() function.

I know that I could use write() function to output the model as a LP file. However,  the generated format does not contribute to debug too much. Instead, pprint() function provides a pretty beautiful and clear way to display the model, which help the debugging a lot. How could I save the results in a text file?

Thank you very much.

Laird, Carl Damon

unread,
Feb 4, 2021, 12:16:12 PM2/4/21
to pyomo...@googlegroups.com

This doesn’t quite answer your question, however, I do the following very often.

 

I put “m.pprint()” in my Python script and then from the terminal:

 

  • Python mycode.py &> output.txt

 

Then the output is stored in output.txt. This is not a Pyomo command, but a bash shell capability. There may be other ways to capture the pprint output in Python.

 

Regards,

 

Carl.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/a7fc6493-1993-48f8-87b8-a71e9ff173aan%40googlegroups.com.

Siirola, John D

unread,
Feb 4, 2021, 12:37:05 PM2/4/21
to pyomo...@googlegroups.com

pprint() takes an ostream argument:

 

with open('output.txt', 'w') as FILE:

    model.pprint(ostream=FILE)

 

John

Tao Wu

unread,
Feb 4, 2021, 4:23:39 PM2/4/21
to pyomo...@googlegroups.com
Hi John,

Thank you very much. Your method works.
It seems that writing the file is a little time-consuming. May I ask do you have any other better methods to debug a concrete model?

Best regards,
Tao Wu


'Siirola, John D' via Pyomo Forum <pyomo...@googlegroups.com> 于2021年2月4日周四 上午11:37写道:

Tao Wu

unread,
Feb 4, 2021, 4:25:00 PM2/4/21
to pyomo...@googlegroups.com
Hi Carl,

Please see John's method. I think it's a good alternative.
Thanks for your email.

Best regards,
Tao Wu


'Laird, Carl Damon' via Pyomo Forum <pyomo...@googlegroups.com> 于2021年2月4日周四 上午11:16写道:
Reply all
Reply to author
Forward
0 new messages