SETS:

types/1..30/:n,s;

cap/h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 h24 h25 h26 h27 h28 h29 h30/:x0;

var(types,cap)|&2#GT#h0:x;

ENDSETS

DATA:

n= 5 10 6 8 12 6 20 15 8 6 3 2 0 1 4 10 5 20 0 0 10 0 5 1 3 0 0 0 0 0;

s= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30;

K=30;

ENDDATA

min=xx;

@FOR(cap(h) | (h#GT#h0)#AND#(h#LT#K+1) :

@SUM(types(i) | h#GT#s(i): x(i,h) ) + x0(h) =

@SUM(types(i) | h#LE#(K+1-s(i)): x(i,h+s(i)) )+ x0(h+1) ) ;

xx= @SUM(types(i) : x(i,h0+s(i)) )+ x0(h0+1) ;

@FOR(types(i): @SUM(cap(h) | h#GT#s(i): x(i,h) ) > n(i) );

tot=@sum(types: n*s);

@FOR(var: @GIN(x)); @FOR(cap: @GIN(x0)); @GIN(xx);