Here is a few rows of my code for an operations planning optimization.I have 2 dictionaries for the product monthly demand .I have created two parameters with these two dictionaries. As m i have defined the months. After that, i want to multiply some variables with the parameters of demand(the following constraints) but there is an error KeyError: "Cannot treat the scalar component 'tsi' as an indexed component" I don't know what is wrong with that. I have tried a lot of things to fix it but nothing works.
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
def run(): model = pyo.ConcreteModel()
Dict1 = {1:28800,2:26200,3:20900,4:12660,5:25770,6:12350,7:28200,8:26200,9:30000,10:7400,11:24000,12:22200}
Dict2 = {1:5000,2:5700,3:4000,4:1540,5:9000,6:1800,7:7250,8:4000,9:8000,10:3000,11:5000,12:8100}
model.m = pyo.Param(initialize = 12)
model.k = pyo.Param(initialize=2)
model.i = pyo.Param(initialize=3)
model.j = pyo.Param(initialize=3)
model.l = pyo.Param(initialize=2)
model.tsi = pyo.Param(initialize = Dict1)
model.trc = pyo.Param(initialize = Dict2)
model.setm = pyo.RangeSet(1, model.m)
model.setk = pyo.RangeSet(1, model.k)
model.seti = pyo.RangeSet(1, model.i)
model.setj = pyo.RangeSet(1, model.j)
model.setl = pyo.RangeSet(1, model.l)
def sixteenthRule(model, m): return ([model.g[1,m] for m in model.setm]) == ([model.trc[m] for m in range(1,13)])*([model.G[1,m] for m in model.setm]) + ([model.tsi[m] for m in range [1,13]])
def seventeenthRule(model, m): return ([model.g[2,m] for m in model.setm]) == ([model.trc[m] for m in range(1,13)])*([1-model.G[1,m] for m in model.setm])
def twentyeightthRule(model, m): return ([model.z[1,1,m] for m in model.setm]) == ([model.z[1,1,m-1] for m in model.setm]) + ([model.p[1,1,m] for m in model.setm]) - ([model.tsi[m] for m in range [1,13]])
def thirtythRule(model, m): return ([model.z[1,2,m] for m in model.setm]) == ([model.z[1,2,m-1] for m in model.setm]) + ([model.p[2,2,m] for m in model.setm]) + ([model.dr[2,m] for m in model.setm]) - ([model.G[1,m] for m in model.setm])*([model.trc[m] for m in range [1,13]]) + ([model.p[1,2,m] for m in model.setm])