Help translating dynamic set statement from GNU mathprog

Problems with modeling
Post Reply
en2ec1
User
User
Posts: 8
Joined: 2 years ago

Help translating dynamic set statement from GNU mathprog

Post by en2ec1 »

I'm trying to translate a model written in GNU mathprog. Most of it is pretty straightforward, but there are some dynamic set declarations and operations that are puzzling me.

This is an example of a statement for a dynamic set in GNU mathprog that I'm struggling to translate into GAMS:

set MODExTECHNOLOGYperEMISSION{e in EMISSION} within MODE_OF_OPERATION cross TECHNOLOGY
:= {m in MODE_OF_OPERATION, t in TECHNOLOGY : exists{r in REGION, y in YEAR} EmissionActivityRatio[r,t,e,m,y] <> 0};

For some explanation: EmissionActivityRatio(r,t,e,m,y) is a parameter.
Static sets are: REGTION, TECHNOLOGY, EMISSION, MODE_OF_OPERATION, YEAR

Then later in the code, this set is used like this in a constraint:
s.t. E5_DiscountedEmissionsPenaltyByTechnology{r in REGION, t in TECHNOLOGY, y in YEAR}: sum{e in EMISSION, l in TIMESLICE, (m,tt) in MODExTECHNOLOGYperEMISSION[e]: t=tt} EmissionActivityRatio[r,t,e,m,y]*RateOfActivity[r,l,t,m,y]*YearSplit[l,y]*EmissionsPenalty[r,e,y]/DiscountFactorMid[r,y] = DiscountedTechnologyEmissionsPenalty[r,t,y];

tt is an alias of t and TECHNOLOGY. TIMESLICE is another set. RateOfActivity[r,l,t,m,y] and DiscountedTechnologyEmissionsPenalty[r,t,y] are variables. Yearsplit[l,y], EmissionsPenalty[r,e,y] and DiscountFactorMid[r,y] are parameters.

If anyone can help with equivalent GAMS statements for the set statement and constraint equation above, I would be really grateful.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Help translating dynamic set statement from GNU mathprog

Post by bussieck »

I would do it as follows in GAMS:

Code: Select all

set e EMISSION /e1*e2/
    m MODE_OF_OPERATION /m1*m2/
    t TECHNOLOGY /t1*t2/
    r REGION /r1*r2/
    y YEAR /y1*y2 /
    l TIMESLICE /l1*l2/;  
    
Parameter
    EmissionActivityRatio[r,t,e,m,y]
    YearSplit[l,y]
    EmissionsPenalty[r,e,y]
    DiscountFactorMid[r,y]
    DiscountedTechnologyEmissionsPenalty[r,t,y];
    
* Fill sparsely
EmissionActivityRatio[r,t,e,m,y]$(uniform(0,1)<0.5) = uniform(1,10);

set MODExTECHNOLOGYperEMISSION(e,m,t);
MODExTECHNOLOGYperEMISSION(e,m,t) = sum((r,y)$EmissionActivityRatio[r,t,e,m,y],1);

* Fill
YearSplit[l,y]                              = uniform(0.1,1);
EmissionsPenalty[r,e,y]                     = uniform(0.1,1);
DiscountFactorMid[r,y]                      = uniform(0.1,1);
* Take care that the equation does not become infeasible
DiscountedTechnologyEmissionsPenalty[r,t,y]$sum(MODExTECHNOLOGYperEMISSION(e,m,t),EmissionActivityRatio[r,t,e,m,y]) = uniform(0,1);

positive variable RateOfActivity[r,l,t,m,y];

equation E5_DiscountedEmissionsPenaltyByTechnology[r,t,y];
E5_DiscountedEmissionsPenaltyByTechnology[r,t,y]..
  sum((l,MODExTECHNOLOGYperEMISSION(e,m,t)),
    EmissionActivityRatio[r,t,e,m,y]*RateOfActivity[r,l,t,m,y]*YearSplit[l,y]*EmissionsPenalty[r,e,y]
    /DiscountFactorMid[r,y]) =e= DiscountedTechnologyEmissionsPenalty[r,t,y];

variable obj;
equation dummyobj;
dummyobj.. obj =e= sum((r,t,y,l,MODExTECHNOLOGYperEMISSION(e,m,t)), RateOfActivity[r,l,t,m,y]);

model dummy /all/;
solve dummy min obj us lp;
The AMPL/GNU mathprog set valued set MODExTECHNOLOGYperEMISSION is translated as a GAMS set/table with three indices. If you "fix" e, you get the corresponding m and t. The advantage of a relational table data structure as in GAMS is that you can index the set/table based on the situation. In your example equation, you index with t not with e and hence you don't need "dummy" conditions like t=tt as in AMPL/GNU mathprog. In other situations the set valued formulation looks probably nicer. It's a matter of taste and what you are used to.

I am curious about the background for the translation. If you can share some information that would be nice.

-Michael
Post Reply