begginer to pyomo I'm having a hard time to fully understand the set declaration of pyomo. Here's my code:
D = [1,2]
S = ['E', 'L', 'D', 'N']
CoverRequirement = {(1, 'E'): 2,
(1, 'L'): 2,
(1, 'D'): 1,
(1, 'N'): 1,
(2, 'E'): 2,
(2, 'L'): 1,
(2, 'D'): 1,
(2, 'N'): 2}
model.S = Set(initialize = S)
model.D = Set(initialize = D)
model.D_S = model.D_S = Set(within = model.D * model.S,
initialize = [(d, s) for d in model.D for s in model.S])
model.CoverRequirement = Set(model.D_S, initialize = CoverRequirement)
Error:
ERROR: Initializer for Set R[(1, 'E')] returned non-iterable object of type
int.
ERROR: Constructing component 'R' from data=None failed: TypeError: 'int'
object is not iterable
The set R is the numbered of required employees at day d and shift s
I have tried things like this but it does not look correct:
model.CoverRquirement = Set(model.D_S, initialize = [((d,s),r) for (d,s) in R for r in R[r]])
How to declare my set cover requirement with d
& s
as index ? Thank you
Gor my answer, should have declare my input cover requierement using Param
and not Set
:
model.R1 = Param(model.D_S, initialize = R)