Good morning everyone
I am optimizing an iterative process and I have to assign a certain variable result as the fixed value of that variable for the next iteration optimization.
I wonder how to code this. I tried to code it but when I run the model, from the listing file it seems that Gams assigns 'zero' as the fixed value
of the variable for the next iteration.
Please help me
Assign previous iteration result to starting value of next iteration Topic is solved
Re: Assign previous iteration result to starting value of next iteration
Hi,
You can see in the column listing column listing that R(s1) and Q(s1) are fixed to 4 for the first iteration which seems to be intended. For subsequent iterations you do
This basically means
The dollar condition on the left hand side restricts the assignment to s1. The dollar condition on the right hand side always evaluates to false:
- ord(s)=ch is false because s is controlled on the LHS already where you restrict the assignment to ord(s)=1. But ch is equal to 3
- ord(it)=ord(it)-1 is never true (I think this is obvious).
I hope this helps!
Fred
You can see in the column listing column listing that R(s1) and Q(s1) are fixed to 4 for the first iteration which seems to be intended. For subsequent iterations you do
Code: Select all
if (ord(it)>1,
R.fx(s)$(ord(s)=1)=R.l(s)$(ord(s)=ch and ord(it)=ord(it)-1);
Q.fx(s)$(ord(s)=1)=Q.l(s)$(ord(s)=ch and ord(it)=ord(it)-1);
);
Code: Select all
R.fx('s1') = 0;
Q.fx('s1') = 0;
- ord(s)=ch is false because s is controlled on the LHS already where you restrict the assignment to ord(s)=1. But ch is equal to 3
- ord(it)=ord(it)-1 is never true (I think this is obvious).
I hope this helps!
Fred
Re: Assign previous iteration result to starting value of next iteration
thanks, Ms. Fred for your answer and code explanation.
How should I code if I want gams to assign the result R.l (s=3, it=1) as fixed value R.fx(s=1, it=2) for iteration it=2
and R.l(s=3, it=2) for R.fx(s=1, it=3)
and finally for the last iteration R.l(s=3, it=3) for R.fx(s=1, it=4)
thanks to help me.
How should I code if I want gams to assign the result R.l (s=3, it=1) as fixed value R.fx(s=1, it=2) for iteration it=2
and R.l(s=3, it=2) for R.fx(s=1, it=3)
and finally for the last iteration R.l(s=3, it=3) for R.fx(s=1, it=4)
thanks to help me.
Re: Assign previous iteration result to starting value of next iteration
If I understand correctly what you try to do, you could just write
I hope this helps!
Fred
Code: Select all
[...]
if(ord(it)=1,
R.fx('s1')=4;
Q.fx('s1')=4;
else
R.fx('s1') = R.l('s3');
Q.fx('s1') = R.l('s3');
);
Solve rolling using LP minimizing cost;
[...]
Fred