我在Python 3.6下使用Pyomo Pyomo 5.1.1(Linux 3.16.0-4-amd64上的CPython 3.6.0) ,並且當我想要時會收到錯誤消息使用求和在模型中構建表達式。 下面是一個小例子:使用python 3.6和pyomo表達式生成中的錯誤3.6
from pyomo.environ import *
from pyomo.opt import SolverFactory
model=ConcreteModel()
model.H=RangeSet(0,23)
model.x=Var(model.H)
E=summation(model.x)
我收到以下錯誤:
「
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/util.py", line 86, in summation
ans += item
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/numvalue.py", line 537, in __iadd__
return generate_expression(_iadd,self,other)
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/expr_coopr3.py", line 977, in generate_expression
_self = _generate_expression__clone_if_needed(_self, 1)
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/expr_coopr3.py", line 918, in _generate_expression__clone_if_needed
% (getrefcount(obj) - UNREFERENCED_EXPR_COUNT,))
RuntimeError: Expression entered generate_expression() with too few references (0<0); this is indicative of a SERIOUS ERROR in the expression reuse detection scheme.
」
我得到同樣的錯誤,如果我取代了 「求和」 的在model.H中的h循環。
這個bug已經注意到這裏也:https://github.com/Pyomo/pyomo/issues/103
有沒有一種簡單的方法來解決這個問題,不是退一步舊版本的Python的其他?
非常感謝您的幫助,
波林