Run summation over subset

12 views
Skip to first unread message

p.jama...@gmail.com

unread,
Mar 22, 2018, 7:02:42 PM3/22/18
to AMPL Modeling Language
I have a set  K= 1..11, J= 1..9 and subset of K and J connection which is predefined as 
Jk1= {1}, Jk2 ={1,2}, 
Jk3={1,2,3}, Jk4 = {2,3,4}, .. JKn = {n-2,n-1,n}... until n = (|K|-2)
Jk10 = {8,9}, Jk11 = {11}

where set Jk1 includes the only elements in J that is connected to element "1" in set K.
Now, I need to run the optimization model as 
sum { k in K, j in JK[k] } Zijkr for all i and r, How can I do this in ampl 

AMPL Google Group

unread,
Mar 23, 2018, 12:20:02 AM3/23/18
to am...@googlegroups.com
You should define a indexed collection of sets as discussed in https://ampl.com/BOOK/CHAPTERS/09-sets2.pdf (pp 100). So, you need to define

set JK{K};

then you could write your summation as subject to c {k in K}: sum{j in JK[k]} j;


--
Paras Tiwari
am...@googlegroups.com
{#HS:546768140-3439#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages