0

I am new to Pyomo and python and am currently trying to build a MILP model. It'd be great if someone can help me out on this.

So in my production model, I have packing families,pf, and a packing line,l, can handle a packing family at a time. I also have a set of products, p.

In my model, capacity is reserved on a family level, so I want to construct sets in such a way that pf1 in set pf includes product p1,p2,p3,p4 and pf2 includes p5,p6,p7,p8. For instance, a constraint for implementing packing capacity restriction would be:

model.ct6rePackCap = ConstraintList()
for pf in model.PF for l in model.L for t in model.T for s in model.S for n in model.N:
lhs = sum(r[p,l,t,s,n] for p in model.P)
rhs = RPack[l,pf,t,s]
model.ct6reCap.add (lhs <= rhs) 

Here r is the quantity of product with product index p and RPack is the capacity reserved for the packing family pf, to which each p belongs. How can I connect p and pf here such that each element of pf (pf1, pf2..) contains a set of products e.g. (pf1 = (p1,p2,p3,p4), pf2 =(p5,p6,p7,p8)) ?

I read pyomo document and read something about subset but it didn't seem like it would achieve what I want.

Thanks a lot in advance!

Lily Cole
  • 17
  • 4
  • I just answered a similar question here: https://stackoverflow.com/questions/70975575/how-to-implement-conditional-summing-within-pyomo-constraint/70977511#70977511 I think you want to create an indexed set as I do in that answer where you have sets that are indexed by another set. – AirSquid Feb 11 '22 at 16:01
  • Hi AirSquid, thanks for your comment! In fact I think I already had come across before but that time i couldn't understand as I just started reading Pyomo documents. Now it seems like I can apply directly for my case. :) Just to clarify, g_names in your post is just an element of set Group_names, right? – Lily Cole Feb 11 '22 at 19:37
  • In the other post, there is a set of group names, and that set serves as the **index** to the other sets of the groupings. So in your case, you would have "families" and use that set of families as the index for another collection of sets. Give it a try. Re-post if you get stuck. Stick with Concrete Model ! – AirSquid Feb 11 '22 at 23:51
  • It worked! As you said, I created another set to map the two sets, and used the family set as an index for the group mapping set. Thank you so much. :) – Lily Cole Feb 12 '22 at 09:18
  • Great. If the other answer was helpful, you could up-vote it. Good Luck! – AirSquid Feb 12 '22 at 16:29

0 Answers0