Pyomo: Access Solution From Python Code

后端 未结 3 1449
[愿得一人]
[愿得一人] 2020-12-29 14:58

I have a linear integer programme I want to solve. I installed solver glpk (thanks to this answer) and pyomo. I wrote code like this:

from pyomo.environ impo         


        
3条回答
  •  时光说笑
    2020-12-29 15:59

    I found the pyomoio module in the urbs project. It extracts sets, parameters, variables, and so on, and the returns them in pandas objects, which are very convenient for visualization in jupyter notebooks.

    I build a simple model

    model = ConcreteModel()
    model.act = Set(initialize=list('IJK'))
    model.goods = Set(initialize=list('ijk'))
    u0 = {}
    u0['i', 'J'] = 2.
    u0['k', 'I'] = .3
    model.U0 = Param(model.goods, model.act, initialize=u0, default=0)
    

    I can then read it in a pandas DataFrame, with all the labels set appropriately.

    import pyomoio as po
    u_df = po.get_entity(model, 'U0').unstack()
    print(u_df)
    
    # act      I    J    K
    # goods               
    # i      0.0  2.0  0.0
    # j      0.0  0.0  0.0
    # k      0.3  0.0  0.0
    

提交回复
热议问题