1
私の人生にとって、私はpyomoプログラムを実行することができません。空モデルを取得するpyomo
私はPythonのファイルを持っている:あなたはソートの他に1から物事をマップする、これがどのように動作するかの私の理解から
set warehouses := warehouseone warehousetwo warehousethree warehousefour;
set stores := storeone storetwo storethree storefour storefive storesix;
param cost:
storeone storetwo storethree storefour storefive storesix :=
warehouseone 23 12 34 25 27 16
warehousetwo 29 24 43 35 28 19
warehousethree 43 31 52 36 30 21
warehousefour 54 36 54 46 34 27;
param m := 4 ;
param n := 6 ;
param: a:=
warehouseone 15
warehousetwo 25
warehousethree 40
warehousefour 70;
param: b :=
warehouseone 10
warehousetwo 5
warehousethree 7
warehousefour 4;
param: d :=
storeone 45
storetwo 120
storethree 165
storefour 214
storefive 64
storesix 93;
:
from pyomo.environ import *
#pyomo solve --solver=glpk diet.py diet.dat
model = AbstractModel()
# Foodss
model.m = Param(within=NonNegativeIntegers)
model.n = Param(within=NonNegativeIntegers)
model.warehouses = RangeSet(1, model.m)
model.stores = RangeSet(1, model.n)
model.cost = Param(model.warehouses,model.stores)
model.a = Param(model.warehouses)
model.b = Param(model.warehouses)
model.d = Param(model.stores)
model.amounts = Var(model.warehouses, model.stores, within = NonNegativeIntegers)
model.pprint()
# Minimize the cost of food that is consumed
def cost_rule(model):
return sum(
model.cost[n,i] * model.amounts[n,i]
for n in model.warehouses
for i in model.stores
)
model.cost = Objective(rule=cost_rule)
def minDemandRule(store, model):
return sum(model.a[i]*model.amounts[i, store] for i in model.warehouses) >= model.d[store]
model.demandConstraint = Constraint(model.stores, rule=minDemandRule)
# Limit the volume of food consumed
def maxSupplyRule(warehouse,model):
return sum(model.amounts[warehouses,j] for j in model.stores) <= self.b[warehouse]
model.supplyConstraint = Constraint(model.warehouses, rule=maxSupplyRule)
プラス.datファイルを。これは私にとっては大丈夫だと思うが、私がそれを実行するときだ。 DATファイルが正しく読み込まれていませんように
pyomo solve --solver=glpk transport.py data.dat
[ 0.00] Setting up Pyomo environment
[ 0.00] Applying Pyomo preprocessing actions
2 Set Declarations
amounts_index : Dim=0, Dimen=2, Size=0, Domain=None, Ordered=True, Bounds=None
Virtual
cost_index : Dim=0, Dimen=2, Size=0, Domain=None, Ordered=True, Bounds=None
Virtual
2 RangeSet Declarations
stores : Dim=0, Dimen=1, Size=0, Domain=None, Ordered=True, Bounds=None
Not constructed
warehouses : Dim=0, Dimen=1, Size=0, Domain=None, Ordered=True, Bounds=None
Not constructed
6 Param Declarations
a : Size=0, Index=warehouses, Domain=Any, Default=None, Mutable=False
Not constructed
b : Size=0, Index=warehouses, Domain=Any, Default=None, Mutable=False
Not constructed
cost : Size=0, Index=cost_index, Domain=Any, Default=None, Mutable=False
Not constructed
d : Size=0, Index=stores, Domain=Any, Default=None, Mutable=False
Not constructed
m : Size=1, Index=None, Domain=NonNegativeIntegers, Default=None, Mutable=False
Not constructed
n : Size=1, Index=None, Domain=NonNegativeIntegers, Default=None, Mutable=False
Not constructed
1 Var Declarations
amounts : Size=0, Index=amounts_index
Not constructed
11 Declarations: m n warehouses stores cost_index cost a b d amounts_index amounts
WARNING: Implicitly replacing the Component attribute cost (type=<class 'pyomo.core.base.param.IndexedParam'>) on block unknown with a new Component (type=<class 'pyomo.core.base.objective.SimpleObjective'>).
This is usually indicative of a modelling error.
To avoid this warning, use block.del_component() and block.add_component().
[ 0.01] Creating model
ERROR: Constructing component 'a' from data={'warehousefour': 70, 'warehouseone': 15, 'warehousethree': 40, 'warehousetwo': 25} failed:
RuntimeError: Failed to set value for param=a, index=warehousefour, value=70.
source error message="Error setting parameter value: Index 'warehousefour' is not valid for array Param 'a'"
[ 0.02] Pyomo Finished
ERROR: Unexpected exception while running model:
Failed to set value for param=a, index=warehousefour, value=70.
source error message="Error setting parameter value: Index 'warehousefour' is not valid for array Param 'a'"
は私が感じるが、私は他の例を見ると、これは、それがどのように行われるかであるので、私は少し困惑です。
こんにちはTimofey、 詳細な対応に感謝します。あなたのコードを見て、私は大きなミスをした場所を見ます。ちょっと不思議なことに、私はこれを新しくしているので、変数がソリューションファイルに報告されていなければ、それは全く同じであると仮定します。ガイダンスとこれに助けてくれてありがとう。 – Eigenvalue
@Eigenvalueはい、ソリューションに表示されていない変数は常にゼロとみなされます。 –