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
opt_rolling.gms (8.28 KB)
inputdata.xlsx (19.7 KB)
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
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);
);
This basically means
R.fx('s1') = 0;
Q.fx('s1') = 0;
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
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.
If I understand correctly what you try to do, you could just write
[...]
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;
[...]
I hope this helps!
Fred