I have an objective function equation which is time-dependent. Indeed I want to have an optimal solution for each time t.
Hence for each time t an optimal objective. I don’t know how to loop the solve statement over the time set t.
I had tried with the attached gams code and excel input data file but I have gotten errors.
Please help me.
opt_data.xlsx (68.2 KB)
opt_myopic_1.gms (8.07 KB)
Hi
It looks like you want to model a recursive model, where the values of R and Q for the next period are defined using the actual period.
You have to do the following to be able to run over t.
- You keep your original parameters but define new parameters for the model without a time index. E.g. you read the parameter E_L(t) from your excel sheet and define a model parameter E_Lm for the model. Same for all other parameters. In the loop, they are assigned the value for the actual period.
- You remove in your model definition all the indices t from the variables and use the model parameters mentioned above (e.g. E_Lm and not E_L(t)).
- You define R and Q as parameters and assign them values for the first period.
- You write your two first equations as assignments just after the solve in the loop and use the solution to get the values for R and Q for the next period.
* Remove R and Q from the variables and make them parameters
parameter R, Q;
* Initialize R and Q for the first period
R = ....;
Q = ....;
* Remove the time indices in all equations of the model
....
eq4.. x1 + x5 +beta_d_E*x9 =l= E_L;
....
eq12.. beta_c_E*(x2 +x6) -beta_d_E*x9 =l=Rmax - R;
...
* Loop over t
* Define the model parameters
parameter E_Lm, P_rerm, ....
loop(t,
* Assign the values to the model parameters
E_Lm = E_L(t);
P_rerm = P_rer(t);
...
* Solve your model
* Report your results using the time index
results(t, "X2") = X2.L:
* Assign the values for the next period for R and Q
R = R + beta_c_E*(x2.L + x6.L) - beta_d_E * x9.L;
Q = Q + beta_c_T*(QchST.L + sum(i,k1(i) * x11.L(i)))- sum(i, beta_d_T*x12.L(i));
);
I hope this helps
Cheers
Renger
Many thanks to you Ms. Renger
I integrated your recommendations.
the model works fine but there is a problem, taking R, and Q as parameters
permits GAMS to give them any value during the optimization process.
Yet R and Q as used as energy storage levels and can not take negative values.
I attached the model with your recommendations.
opt_myopic_3.gms (8.07 KB)
Please share another trick that enables me to consider R and Q as variables
thanks best regards.
Many thanks to you Ms. Renger
I integrated your recommendations.
the model works fine but there is a problem, taking R, and Q as parameters
allows GAMS to give them any value during the optimization process.
Yet R and Q as used as energy storage levels and can not take negative values.
I attached the model with your recommendations.
opt_myopic_1.gms (7.31 KB)
Please share another trick that enables me to consider R and Q as variables
thanks best regards.
Hi
You could introduce two positive variables Rn, Qn and add the following equations:
positive variables
Rn Reserve in next period,
Qn ....;
eqR..
Rn =E= R + beta_c_E*(x2 + x6) - beta_d_E * x9;
eqQ..
Qn =E= Q + beta_c_T*(QchST + sum(i,k1(i) * x11(i)))- sum(i, beta_d_T*x12(i));
After the solve, you assign R and Q
R = Rn.L;
Q = Qn.L;
cheers
Renger
Many thanks Ms Renger
the code works very well.