I have a question related to the dependencies of a set
As a ‘toy problem’, lets say I have the sets
SETS:
country /c1…c5/
material/m1…m3/
Parameter:
tariff(country, material)
The parameter table looks like this
The tariff principally depends of the country, but there is a few exceptions where the tariff will depend on the material too.
Is there a way to tell GAMS “given this country, for all materials the tariff is x”.
keep in mind the actual problem have a lot more depending sets, I can work arround this problem by generating all the posible combinations but it becomes a very large sheet of data to generate everytime.
Inside your table you can write m1*m3 to refer to all set-elements, this way the parameter will have the same value for all materials for the specific country.
Which comes down to the same as: ’ tariff(“c1”,materials) = 10; ’ which will also result in the same tariff (10) for all materials for country c1.
You can also declare a subset of the set “country” which holds the countries for which all materials have the same tariff (see code below).
Regards,
GFA
sets
country /c1*c4/
material /m1*m3/
;
set CountriesWithAllMaterials(country)/c1,c2/ ;
parameter tariff(country,material);
tariff(country,material)
$CountriesWithAllMaterials(country) = 10;
display tariff;
Here’s another way you could do this. The use of implicit set definition for my allm set isn’t strictly necessary but it’s a useful feature - it’s a solid way to create a superset of the materials that also include ‘ALL’.
* use implicit set definition so I only enter materials once
sets
cty 'country' / c1*c5 /
allm 'materials plus ALL marker'
mat(allm<) 'material'
mat / m1 * m3 /
$onMulti
allm / ALL /
$offMulti
;
parameter inTariff(cty,allm) /
c1.ALL 10
c2.ALL 7
c2.m2 12
c3.m1 3
c3.m2 4
c3.m3 3
c4.ALL 8
/;
parameter tariff(cty,mat);
* now selectively assign elements to tariff
* first, make the ALL assignment
tariff(cty,mat)$[inTariff(cty,'ALL')] = inTariff(cty,'ALL');
display 'after default/ALL assignment', tariff;
* finally make specific assignments if the data exists in inTariff
tariff(cty,mat)$[inTariff(cty,mat)] = inTariff(cty,mat);
display 'final tariff', tariff;