Page 2 of 2
Re: How to loop the matrix
Posted: Sun Feb 24, 2019 11:30 am
by LiangYu
Sorry, Still Different dimensions at two codes. Are c1.l and bestns1 problem? I don't know.
************************************************
results(loopnr, "Mincl")$(loopnr.val = loopcount) = c1.l;
results(loopnr, "nsl")$(loopnr.val = loopcount) = bestns1;
************************************************
Code: Select all
set loopnr Loop number /1*100/;
parameter loopcount /1/;
parameter results(loopnr, *);
parameters
minc1
bestns1
sumz1
sumc1
;
bestns1(heatx)$(r(heatx) ne 1)=1;
minc1(heatx)$(r(heatx) ne 1)=inf;
sumz1=sum(heatx,minc1(heatx));
sumc1=sum(heatx,c1.l(heatx));
parameter n1;
while((smax(heatx, bestns1(heatx)) < 10),
bestns1(heatx)$(r(heatx) ne 1)=bestns1(heatx)+1;
ns1.fx(heatx)=bestns1(heatx);
solve exchanger1 using minlp minimizing z1;
loopcount = loopcount + 1;
results(loopnr, "Mincl")$(loopnr.val = loopcount) = cl.l;
results(loopnr, "nsl")$(loopnr.val = loopcount) = bestns1;
if ((exchanger1.modelstat=1 or exchanger1.modelstat=8) and (sumc1 < sumz1),
minc1(heatx) = c1.l(heatx);
n1(heatx)=bestns1(heatx);
);
);
display minc1,n1, results;
Re: How to loop the matrix
Posted: Mon Feb 25, 2019 11:08 am
by Renger
Here you go:
Code: Select all
parameter results(loopnr, *,*);
parameters
minc1
bestns1
sumz1
sumc1
;
bestns1(heatx)$(r(heatx) ne 1)=1;
minc1(heatx)$(r(heatx) ne 1)=inf;
sumz1=sum(heatx,minc1(heatx));
sumc1=sum(heatx,c1.l(heatx));
parameter n1;
while((smax(heatx, bestns1(heatx)) < 10),
bestns1(heatx)$(r(heatx) ne 1)=bestns1(heatx)+1;
ns1.fx(heatx)=bestns1(heatx);
solve exchanger1 using minlp minimizing z1;
loopcount = loopcount + 1;
results(loopnr, "Mincl",heatx)$(loopnr.val = loopcount) = c1.l(heatx);
results(loopnr, "nsl",heatx)$(loopnr.val = loopcount) = bestns1(heatx);
if ((exchanger1.modelstat=1 or exchanger1.modelstat=8) and (sumc1 < sumz1),
minc1(heatx) = c1.l(heatx);
n1(heatx)=bestns1(heatx);
);
);
display minc1,n1, results;
Re: How to loop the matrix
Posted: Mon Feb 25, 2019 1:15 pm
by LiangYu
Sorry, Renger. Bad things.
Still Different dimensions at two codes.
************************************************
results(loopnr, "minc1",heatx)$(loopnr.val = loopcount) = c1.l(heatx);
results(loopnr, "nsl",heatx)$(loopnr.val = loopcount) = bestns1(heatx);
************************************************
Code: Select all
set loopnr Loop number /1*100/;
parameter loopcount /1/;
parameter results(loopnr, *);
parameters
minc1
bestns1
sumz1
sumc1
;
bestns1(heatx)$(r(heatx) ne 1)=1;
minc1(heatx)$(r(heatx) ne 1)=inf;
sumz1=sum(heatx,minc1(heatx));
sumc1=sum(heatx,c1.l(heatx));
parameter n1;
while((smax(heatx, bestns1(heatx)) < 10),
bestns1(heatx)$(r(heatx) ne 1)=bestns1(heatx)+1;
ns1.fx(heatx)=bestns1(heatx);
solve exchanger1 using minlp minimizing z1;
loopcount = loopcount + 1;
results(loopnr, "minc1",heatx)$(loopnr.val = loopcount) = c1.l(heatx);
results(loopnr, "nsl",heatx)$(loopnr.val = loopcount) = bestns1(heatx);
if ((exchanger1.modelstat=1 or exchanger1.modelstat=8) and (sumc1 < sumz1),
minc1(heatx) = c1.l(heatx);
n1(heatx)=bestns1(heatx);
);
);
display minc1,n1, results;
Re: How to loop the matrix
Posted: Tue Feb 26, 2019 9:36 am
by Renger
Compare your code and my suggestion carefully, and you will find the mistake in your code.
Cheers
Renger
Re: How to loop the matrix
Posted: Fri Mar 08, 2019 3:37 pm
by LiangYu
Thank you very much, Renger.
There is a problem now, the result it displays will follow the EX1display(only ns1 to ns4 of ex1 is infeasible) , and the subsequent EX3 to EX7 will not be displayed.
ns1 to ns4 from ex3 to ex7 do not display minc1. (ex1 to ex7 are 7 different data that do not interfere with each other)
the file:
Code: Select all
---- 121 PARAMETER results
ex1 ex3 ex4 ex5 ex6 ex7
1 .ns1 1.000 1.000 1.000 1.000 1.000 1.000
2 .ns1 2.000 2.000 2.000 2.000 2.000 2.000
3 .ns1 3.000 3.000 3.000 3.000 3.000 3.000
4 .ns1 4.000 4.000 4.000 4.000 4.000 4.000
5 .minc1 110374.997 204393.067 263294.489 229423.575 217114.173 414231.210
5 .ns1 5.000 5.000 5.000 5.000 5.000 5.000
6 .minc1 109064.251 217714.346 280041.543 244262.139 230976.843 413380.078
6 .ns1 6.000 6.000 6.000 6.000 6.000 6.000
7 .minc1 109312.056 229690.175 295186.282 257626.515 243501.099 412870.786
7 .ns1 7.000 7.000 7.000 7.000 7.000 7.000
8 .minc1 110142.506 240616.567 309053.233 269833.378 254962.138 412541.793
8 .ns1 8.000 8.000 8.000 8.000 8.000 8.000
9 .minc1 111210.801 250697.943 321877.534 281104.421 265557.550 412316.940
9 .ns1 9.000 9.000 9.000 9.000 9.000 9.000
10.minc1 112371.675 260081.845 333833.750 291600.978 275433.284 412156.453
10.ns1 10.000 10.000 10.000 10.000 10.000 10.000
code show as below
Code: Select all
sets
loopnr Loop number /1*100/
;
parameter loopcount /0/;
parameters
results(loopnr, *,heatx);
scalar bestns1 /0/;
while(bestns1 < 10 ,
bestns1=bestns1+1;
ns1.fx(heatx)=bestns1;
solve exchanger1 using minlp minimizing z1;
loopcount = loopcount + 1;
results(loopnr,"minc1",heatx)$(loopnr.val = loopcount)= c1.l(heatx);
results(loopnr,"ns1",heatx)$[(loopnr.val = loopcount) and (r(heatx) ne 1)]= bestns1;
);
display results;
If use scalar solves ex4, the following results will be displayed.
the scalar file:
Code: Select all
---- 97 PARAMETER results
Mincl nsl
1 1.000
2 199050.374 2.000
3 223062.862 3.000
4 244493.148 4.000
5 263294.489 5.000
6 280041.543 6.000
7 295186.282 7.000
8 309053.233 8.000
9 321877.534 9.000
10 333833.750 10.000