Obtain and display only nonzero values of the variables

512 views
Skip to first unread message

Cacharmday

unread,
Jun 28, 2016, 10:24:57 AM6/28/16
to Pyomo Forum
Hi, 

After many hours of struggling i obtained the right output for my MIP problem. 
Now i want to process my results. I want to obtain (and display) only the non-zero values. 
Is there any possible way?

Something like 
model.x[model.x>=0]               where x is the decision variable.
or somthing like
model.x.pprint(option = PositiveIntegers)

Please help out:D
I want to make an schedule of the non-zero values. 

Thanks in advance, 

C.Day

jose santiago rodriguez

unread,
Jun 28, 2016, 1:15:23 PM6/28/16
to pyomo...@googlegroups.com
Hi,

tol = 1e-4
for k in model.x.keys():
    if abs(model.x[k].value)>tol:
        print model.x[k].cname(), model.x[k].value

Santiago   

Cacharmday

unread,
Jun 29, 2016, 3:22:31 AM6/29/16
to Pyomo Forum


Op dinsdag 28 juni 2016 19:15:23 UTC+2 schreef jose santiago rodriguez:
That helped. 
Thanks!
Do you know if there is any documentation about the operation which you could do on the pyomo variables like cname(), value an pprint()?
C.Day

jose santiago rodriguez

unread,
Jun 29, 2016, 8:45:52 AM6/29/16
to Pyomo Forum
Glad it help. 

You can go to pyomo.org and take a look at the documentation. If you do not find what you need in there you can always go to the source code and take a look at the implementation of the class you are using. For instance, you may want to have a look at var.py

"YourPython"/src/pyomo/pyomo/core/base/var.py


If you do not know where is your source code you can open a python shell and type


import pyomo

pyomo.__path__


That will tell you were is you pyomo package and you can explore the code to find what you need.


Santiago

Reply all
Reply to author
Forward
0 new messages