loop until all values in a parameter reaches a specific value

Problems with syntax of GAMS
Post Reply
Jarenka
User
User
Posts: 64
Joined: 2 years ago

loop until all values in a parameter reaches a specific value

Post by Jarenka » 1 month ago

Dear,

I have an iteration (ITR) loop in which I have a p-parameter that has to have values between -1 and 1. For example, my parameter is p (PRISER,DKM,VAK,Tid) - 4 dimensional, that is calculated using gravity model. This parameter converges to 0, when iterating.
As I said, I want this parameter to have all values between -1 and 1. I do not know how many iterations I have to run to receive this condition for all cells in this parameter. Therefore, my question is: What kind of statement in the ITR-loop I need to include to fulfill the condition (-1,1) for this parameter? It can be more for some cells, but less for other cells. So I want to just stop iterating, once the condition is fulfilled for a cell.
I have tried with break statement, but it iterates over all iterations defined as a default (max ITR = 300).

Best regards
Irena

abhosekar
Moderator
Moderator
Posts: 93
Joined: 3 months ago

Re: loop until all values in a parameter reaches a specific value

Post by abhosekar » 1 month ago

You can declare a boolean indicator (could be a parameter or set which is 0/no if all elements elements of p are between -1 and 1; 1/yes otherwise).

You can use while loop

Code: Select all

parameter s;
s = 1;
while( (s eq 1),
s= 0;
*loop over all elements
loop((PRISER,DKM,VAK,Tid),
element = p(PRISER,DKM,VAK,Tid);
if ( (element > 1 or element < -1),
s = 1;
);

);
);
The code may have some syntax errors but hopefully it will help in conveying the logic.

- Atharv

Post Reply