An alternative to using results.yml?

169 views
Skip to first unread message

Richard Dybowski

unread,
Feb 22, 2016, 10:50:53 AM2/22/16
to Pyomo Forum
If I run a Pyomo script using

pyomo --solver=glpk script.py

I get the right answer from the file results.yml

However, if I add the lines

opt = SolverFactory("glpk")
results = opt.solve(model)
print(results)

to the script and then try to run the script using

python script.py

the output is not the same (i.e. it claims that no solutions were found). How do I change the script so that the output is the same at that shown in the file results.yml? In particular, how can I extract the final values for the variables?

Richard

Siirola, John D

unread,
Feb 22, 2016, 12:16:55 PM2/22/16
to pyomo...@googlegroups.com

As of Pyomo 4.2, the results are automatically loaded back into the instance that you solved – so it is as simple as:

 

                model.myvar.display()

 

to show the value of any single variable,

 

                model.display()

 

to show all variables (and a lot of other information) about the model.

 

If you really need to recreate the old results object with the solution embedded within it, you can store the solution that is currently in the model into the results object with:

 

                model.solutions.store_to(results)

 

This change (and the reasons why) have been previously discussed in the forum, for example: https://groups.google.com/d/topic/pyomo-forum/wjjY2XvmG2w/discussion

 

john

--
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.
For more options, visit https://groups.google.com/d/optout.

rob nijland

unread,
Jul 13, 2016, 10:46:50 AM7/13/16
to Pyomo Forum
Thanks John for the reaction. 
It was a problem I had as well

Op maandag 22 februari 2016 16:50:53 UTC+1 schreef Richard Dybowski:
Reply all
Reply to author
Forward
0 new messages