Edit: I have also added a constraint 1.5 to illustrate maybe a different way of approaching the constraint.
I am trying to write the following constraints in Pyomo for each (i,j) pair on an MxN grid:
The code that I have thus far is as follows, and I am just hoping I can get some feedback on whether or not the constraint definition is written properly to meet the intention.The idea is that each (i,j) cell on the 6x6 grid will have the following two constraints.
model = AbstractModel()
#Define the index sets for the grid, time horizions, and age classes:
model.Iset = RangeSet(6)
model.Jset = RangeSet(6)
model.Tset = RangeSet(7)
model.Kset = RangeSet(50)
#Define model parameters:
model.s = Param(within=NonNegativeIntegers)
#Define model variables:
model.juvenille = Var(model.Iset, model.Jset, model.Tset, model.Kset,
within=NonNegativeReals, initialize = "some expression"
#Constraints:
# Constraint #1
def juv_advance(model, i, j, t, k):
return model.juvenille[i,j,t+1,k+1] == model.juvenille[i,j,t,k]*model.juvsurv
# Constraint #1.5
def juv_advance(model, t, k):
return model.juvenille[t+1,k+1] == model.juvenille[t,k]*model.s \\
for i in model.Iset for j in model.Jset
# Constraint #2
def juv_total(model, i, j, t, k):
return sum(model.juvenille[k] for k in range(1,50))
Additionally, if anybody feels like answering this... how could you save the calculated j_t+1 value to use as the initial value in the next time period.