Experimentation on Gams

Hi I am trying to to a scenario analysis, and I have defined a set sc (1 to 45) which includes the multipliers for different scenarios and I would like to create either a loop or a while (or whatever is appropriate) statement which only considers the value of sc at each iteration. For instance,

My Objective Function

obj… z =e= sum(p$(ord(p) GT 1), sum(i,sum(q$types(i,q) , sum(sc,invcostm(sc,q))*(cinv(q,p))

(I could not write the objective function without summation of sc), So I wanted to change the sc’s value at each iteration as a scalar value.


\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Le mardi 30 septembre 2014 17:46:44 UTC+2, Akgun a écrit :

Hi I am trying to to a scenario analysis, and I have defined a set sc (1 to 45) which includes the multipliers for different scenarios and I would like to create either a loop or a while (or whatever is appropriate) statement which only considers the value of sc at each iteration. For instance,

My Objective Function

obj… z =e= sum(p$(ord(p) GT 1), sum(i,sum(q$types(i,q) , sum(sc,invcostm(sc,q))*(cinv(q,p))

(I could not write the objective function without summation of sc), So I wanted to change the sc’s value at each iteration as a scalar value.



Hi Agkun,

I would do it this way.
Create an empty dynamic subset of your initial scenario set :

SET SUB_SCEN(sc) ;
sub_scen(sc) = no ;

In your objective statement, write it using the subset only :

obj… z =e= sum(p$(ord(p) GT 1), sum(i,sum(q$types(i,q) , sum(SUB_SCEN,invcostm(SUB_SCEN,q))*(cinv(q,p))

We will try to guarantee that, at solve time, only one relevant element is active in the subset.
Finally, here comes the trick : encapsulate your “solve” statement in a loop on the scenario set, which will be your “iteration” set :

loop(sc,

  • activate the current scenario in the subset
    SUB_SCEN(sc) = yes ;
  • solve whatever you need to solve
    solve …
  • don’t forget to de-activate the current scenario in subset
    SUB_SCEN(sc) = no ;
  • end of the loop – switch to next scenario
    );

Hope this helps.
cheers
dax




\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Thanks a lot Dax, i really appreciate for your help.


On Wednesday, October 1, 2014 2:40:16 AM UTC-5, dax wrote:



Le mardi 30 septembre 2014 17:46:44 UTC+2, Akgun a écrit :

Hi I am trying to to a scenario analysis, and I have defined a set sc (1 to 45) which includes the multipliers for different scenarios and I would like to create either a loop or a while (or whatever is appropriate) statement which only considers the value of sc at each iteration. For instance,

My Objective Function

obj… z =e= sum(p$(ord(p) GT 1), sum(i,sum(q$types(i,q) , sum(sc,invcostm(sc,q))*(cinv(q,p))

(I could not write the objective function without summation of sc), So I wanted to change the sc’s value at each iteration as a scalar value.



Hi Agkun,

I would do it this way.
Create an empty dynamic subset of your initial scenario set :

SET SUB_SCEN(sc) ;
sub_scen(sc) = no ;

In your objective statement, write it using the subset only :

obj… z =e= sum(p$(ord(p) GT 1), sum(i,sum(q$types(i,q) , sum(SUB_SCEN,invcostm(SUB_SCEN,q))*(cinv(q,p))

We will try to guarantee that, at solve time, only one relevant element is active in the subset.
Finally, here comes the trick : encapsulate your “solve” statement in a loop on the scenario set, which will be your “iteration” set :

loop(sc,

  • activate the current scenario in the subset
    SUB_SCEN(sc) = yes ;
  • solve whatever you need to solve
    solve …
  • don’t forget to de-activate the current scenario in subset
    SUB_SCEN(sc) = no ;
  • end of the loop – switch to next scenario
    );

Hope this helps.
cheers
dax




\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.