如何在Pyomo中获得双变量?

时间:2018-06-14 12:35:23

标签: python pyomo

我想在 中获取线性优化问题的双变量。我首先尝试了与记录here相同的书面文字。

model.dual = Suffix(direction=Suffix.IMPORT)
print( "Duals" )
from pyomo.core import Constraint
for c in model.component_objects( Constraint, active = True ):
    print( "Constraint", c )
    cobject = getattr( model, str( c ) )
    for index in cobject:
        print( "  ", index, model.dual[cobject[index]] )

它与文档中的完全相同,但我仍然收到以下错误消息:

Traceback (most recent call last):
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pyomo\core\kernel\component_map.py", line 97, in __getitem__
    return self._dict[id(obj)][1]
KeyError: 1401849508200

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1664, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Usuario/PycharmProjects/untitled/Model.py", line 214, in <module>
    model.dual[model.cPowermatched[(0,0)]]
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pyomo\core\kernel\component_map.py", line 100, in __getitem__
    % (id(obj), str(obj)))
KeyError: "Component with id '1401849508200': cPowermatched[0,0]"
Exception ignored in: <bound method Workbook.__del__ of <xlsxwriter.workbook.Workbook object at 0x00000146647164E0>>
Traceback (most recent call last):
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 154, in __del__
Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook.

当我尝试通过

访问双值时似乎卡住了
model.dual[cobject[index]]

有人知道如何解决这个问题吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

如果您的型号不是太大而无法显示所有双重功能,那么可能有助于您进行故障排除的事情就是model.dual.display()