Store results in While loop with logical termination condition on iteration counter not over a set

Problems with syntax of GAMS
Post Reply
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Store results in While loop with logical termination condition on iteration counter not over a set

Post by Abhi140 »

Hi Everyone,

I am using a while loop with the logical condition on the iteration counter. I need to store & analyze the values of each variable and computed parameters (results1, results2, results3, CoupErr, PijCoupErr, VCoupErr in each iteration 'iter') in each iteration. Any idea how can I do that?

Code: Select all

Set i /1*4/;
Alias (i,j,k);

Scalar iter /1/;
Scalar iterMax /20/;

Set cx(i,j) /1.2, 2.3, 3.4/;


Equation PBalance(i);
PBalance(i).. Pg(i) =e= sum(j$cx(i,j), Pij(i,j)) - sum(k$cx(k,i), Pij(k,i));

Equation Voltage1(i,j);
Voltage1(i,j)$(cx(i,j)).. v(j) =e= v(i) - 2*(Pij(i,j) + Qij(i,j));

Equation obj;               
obj.. OF =g= sum(i, Pg(i));

Parameter results1(zz,i,j,*), results2(zz,i,*), results3(zz,*);

Parameters
PijCoup(i,j)       Parameter for line flow
VCoup(i)           Parameter for node voltage;

*Initial parameters
Parameters  PijCoupIn(i,j), VCoupIn(i);
PijCoupIn(i,j)$cx(i,j) = 1.5;
VCoupIn(i) = 1;

Parameters PijCoupErr(i,j), VCoupErr(i);

Parameters CoupErr;

Alias (i,zz);

while((iter < IterMax),

loop(zz,

solve ADMM using LP minimizing OF;

objv(zz) = OF.l;
results1(zz,i,j, "Pijs") = Pij.l(i,j);
results2(zz,i, "Vis") = V.l(i);
results3(zz,"Cost") = OF.l;
);

PijCoup(i,j)$cx(i,j) = (results1(i,i,j, "Pijs") + results1(j,i,j, "Pijs"))/2; 
VCoup(i) = (results2(i,i, "Vis") + sum(j$cx(i,j), results2(j,i, "Vis")))/(1 + sum(j$cx(i,j),1)); 

PijCoupErr(i,j)$cx(i,j) =  abs(PijCoup(i,j) - PijCoupIn(i,j));
VCoupErr(i) =  abs(VCoup(i) - VCoupIn(i));

CoupErr = sum((i,j)$cx(i,j), PijCoupErr(i,j));

*Previous iter values
PijCoupIn(i,j)$cx(i,j) = PijCoup(i,j);
VCoupIn(i) = VCoup(i);

iter = iter + 1;
display iter, CoupErr, PijCoupErr, VCoupErr;
display results1, results2, results3;
*I need to store the results1, results2, results3, CoupErr, PijCoupErr, VCoupErr in each iteration 'iter'.
);
execute_unload 'Output', results1, results2, results3,CoupErr, PijCoupErr, VCoupErr;
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: Store results in While loop with logical termination condition on iteration counter not over a set

Post by Abhi140 »

The problem is solved with extra loops and a set.
Used a break statement.


Thank you, Abhi140 and others, for your help.
Post Reply