Your idea is brilliant but i don't know how to assign parameters in loop from Excel.Renger wrote: ↑1 month agoAs far as I can see, your model has no lagged time variables or parameters, so the idea is that you will run for each t an optimization in a loop.
Because of the loop, you can't have an index in your equations (that is technically not possible).
THerefore you make them all without the time index.
For the parameters you can either use your parameter with the index t or you define them like I did and assign in the loop the value for the actual t
cgrum(u) = cgru(u,t);
In your equations you write cgrum(u) which will have the proper value assigned for each t in the loop.
Cheers
Renger
Loop for objective function

 User
 Posts: 21
 Joined: 2 months ago
Re: Loop for objective function
Re: Loop for objective function
Hi
You owe me a beer Cheers
Renger
You owe me a beer Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: Loop for objective function
I showed you how to save results based on t. After the loop you can send these parameters to Excel.
CHeers
Renger
CHeers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: Loop for objective function
Hi Renger!
Yes you are right. But when i try to send parameters to Excel, it only saves the values for last 't'.
[execute_unload "results.gdx"
execute 'gdxxrw.exe results.gdx var=z.L rng=z! var=X.L rng=X! var=Y.L rng=Y! var=Znew.L rng=Znew! var=zf rng=zf! var=Eexi rng=Eexi! var=Enew rng=Enew! var=Enf rng=Enf! var=c1 rng=c1! var=c2 rng=c2!';]
Re: Loop for objective function
Hi
If you want to report a variable within a loop (say MYVAR(i,j)), you define before the loop a parameter myresults(t,i,j,*) and then you assign within the loop the values of the variable to the parameter
Cheers
Renger
If you want to report a variable within a loop (say MYVAR(i,j)), you define before the loop a parameter myresults(t,i,j,*) and then you assign within the loop the values of the variable to the parameter
Code: Select all
parameter myresults(t,i,j,*);
loop(t,
solve your model
myresults(t,i,j,"MYVAR") = MYVAR.L(i,j);
);
display myresults;
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: Loop for objective function
Hi Renger,Renger wrote: ↑1 month agoHi
If you want to report a variable within a loop (say MYVAR(i,j)), you define before the loop a parameter myresults(t,i,j,*) and then you assign within the loop the values of the variable to the parameter
CheersCode: Select all
parameter myresults(t,i,j,*); loop(t, solve your model myresults(t,i,j,"MYVAR") = MYVAR.L(i,j); ); display myresults;
Renger
I need your help in writing a constraint involving sum over "t" but there is also loop over "t".
For example,
Constraint:
C1(i) .. sum(t, h(i,t)) =l= 1
Re: Loop for objective function
Hi
I assume that you want to sum up to the "t" of the loop. Then I would add an alias and use ord or .val:
otherwise just over tt without the $condition.
cheers
Renger
I assume that you want to sum up to the "t" of the loop. Then I would add an alias and use ord or .val:
Code: Select all
alias(t,tt);
sum(tt$(ord(tt) LE ord(t), ....);
cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: Loop for objective function
Thank you Renger. But i also want this constraint not to appear in loop. The way you recommended, this constraint appers for every "t" in loop. I want to get rid of that.Renger wrote: ↑1 month agoHi
I assume that you want to sum up to the "t" of the loop. Then I would add an alias and use ord or .val:otherwise just over tt without the $condition.Code: Select all
alias(t,tt); sum(tt$(ord(tt) LE ord(t), ....);
cheers
Renger
Re: Loop for objective function
Same procedure:
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist