我正在學習如何在 Pyomo 中創建抽象模型并進行建模,但是,當我可視化 pprint 時,沒有宣告目標函式和約束。我怎樣才能解決這個問題?我附上了代碼
提前致謝。
import pyomo as pyo
from pyomo.environ import *
model = AbstractModel()
model.I = Set()
model.J = Set()
model.a = Param(model.I, model.J)
model.b = Param(model.I)
model.c = Param(model.J)
model.x = Var(model.J, domain = NonNegativeReals)
def obj (model):
return sum(model.c[j]*model.x[j] for j in model.J)
model.obj = Objective(rule = obj)
def ax_constraint_rule (model, i):
return sum(model.a[i,j]*model.x[j] for j in model.J) >= model.b[i]
model.AxbConstraint = Constraint(model.I, rule = ax_constraint_rule)
model.pprint()
3 Set Declarations
I : Size=0, Index=None, Ordered=Insertion
Not constructed
J : Size=0, Index=None, Ordered=Insertion
Not constructed
a_index : Size=0, Index=None, Ordered=True
Not constructed
3 Param Declarations
a : Size=0, Index=a_index, Domain=Any, Default=None, Mutable=False
Not constructed
b : Size=0, Index=I, Domain=Any, Default=None, Mutable=False
Not constructed
c : Size=0, Index=J, Domain=Any, Default=None, Mutable=False
Not constructed
1 Var Declarations
x : Size=0, Index=J
Not constructed
7 Declarations: I J a_index a b c x
uj5u.com熱心網友回復:
您似乎錯誤地縮進了下面的陳述句,這將使它們成為函式的一部分。他們不是。他們呼叫函式......通過使它們成為函式的一部分,在return陳述句之后它們是死代碼。
那至少應該可以列印一些東西。然后,你將要做出instance你的模型通過加載資料(請參閱檔案)和pprint中instance而不是模型。祝你好運!

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/391629.html
上一篇:忽略省略號函式中的引數缺失錯誤
