Use of sparse index sets

218 views
Skip to first unread message

mlang...@gmail.com

unread,
Apr 30, 2016, 7:13:02 AM4/30/16
to Pyomo Forum
Dear all,

currently I'm working on a model with different indices and I'm running inro difficulties while modellin these.

What I want is model is the following (just a short example):




My current attempt:
model.S = Set() #Plants
model
.K = Set(model.S) #Products k possible at plant s
model
.T = Set() #time-periods
model
.KS = Set(dimen=2,initialize=ks_init) #Assignment of products to plants

def obj_rule(model):
   
return sum(model.cL[s,k]*model.[s,k,t] for s in model.S for t in model.T for k in model.K[s])

def ks_init(model):
   
return ((k,s) for k in model.K for s in model.S)

model
.OBJ = Objective(rule=obj_rule)

My questions:
  • how do I have to adapt the ks_init function to ensure that some products are only assigned to certain plants (e.g plant 1 produces product 1,3 and plant 2 produces product 2)?
  • how can I ensure in the objective function, that for each plant only the products assigned to this plant are taken?

Please let me know if you have any hints or ideas for me.

Thanks in advance!


Best regard,


Max

Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3

David Woodruff

unread,
Apr 30, 2016, 11:32:21 AM4/30/16
to pyomo...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Braulio Brunaud

unread,
May 10, 2016, 12:33:21 AM5/10/16
to Pyomo Forum
Hello

I had the same problem and after looking at different alternatives I found the simplest one was to create a parameter that is 1 if product k is produced in plant s and 0 otherwise. Then you include an if statement to the sum

return sum(model.cL[s,k]*model.l[s,k] for s in model.S for k in model.K if model.prods[k,s]>0)

this will add the term to the sum only if allowed in the parameter.

hope it helps

Braulio
Reply all
Reply to author
Forward
0 new messages