I have a model like the one shown below. In its current form, the model yields the same solution in each iteration. How can I modify the loop statement to solve the model n times (n=10 in my example) where in each iteration set p1 contains 50 observations but instead of being the first 50 ones (as is the case in my model) they are drawn randomly from the larger set i with or without replacement?
Thank you.
SETS i /1*100/
p1(i) /1*50/
j /y, x1,x2/
outp(j) /y/
inp(j) /x1, x2/
ALIAS (i,ii) ;
Parameter
data(i,j);
data(i,j) = uniform(0,1);
display data;
PARAMETERS
x(inp,i)
y(outp,i)
;
Positive variables
f(i,p1)
b(i)
;
Variables
z1
;
loop(i,
x(inp,i)=data(i,inp);
y(outp,i)=data(i,outp);
);
Equations
objective1
output1(i,outp)
vinput1(i,inp)
;
objective1.. z1=E=sum(i$p1(i),b(i));
output1(i,outp).. sum(p1,f(i,p1)*y(outp,p1))=G=y(outp,i);
vinput1(i,inp).. sum(p1,f(i,p1)*x(inp,p1))=L=x(inp,i)*b(i);
model m /all/;
set k /1*10/
loop(k,
solve m using nlp minimizing z1;
);
Thank you for your prompt reply. The code you proposed, and more specifically the “option clear=p1” and “p1(i+adr) = yes” lines, results in the following errors, respectively:
Error 579…Cannot clear a set used as domain or used in lag/ord operations
Error 188… Assigning to this set is NOT allowed. The set may have been
**** used in a domain definition or is a predefined/readonly set.
Correct. I did not see the declaration “Positive variables f(i,p1)”. Change this to “Positive variables f(i,i)”. Since you use the variable f only over p1 there is no difference.