Page 1 of 1
parameter with dynamic dependencies
Posted: Thu Aug 19, 2021 5:00 pm
by pitters
Hi
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
- Screenshot_1.png (5.29 KiB) Viewed 3486 times
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.
How would you approach this problem?
Thanks!
Re: parameter with dynamic dependencies
Posted: Thu Aug 19, 2021 10:27 pm
by GFA
Hi Pitters,
Somethings which might be useful:
- 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
Code: Select all
sets
country /c1*c4/
material /m1*m3/
;
set CountriesWithAllMaterials(country)/c1,c2/ ;
parameter tariff(country,material);
tariff(country,material)
$CountriesWithAllMaterials(country) = 10;
display tariff;
Re: parameter with dynamic dependencies
Posted: Fri Aug 20, 2021 3:21 pm
by pitters
Thanks GFA, good answer!
- 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.
If you need to import the tables from excel:
Code: Select all
$CALL GDXXRW.EXE i=test.xlsx o=tariff par=tariff rng=tariff!a2 Rdim=2
Do you know if GAMS has a keyword for importing " tariff("c1",materials) = 10 "
- Screenshot_2.png (3.41 KiB) Viewed 3441 times
material is not working hahah
Regards,
Pitters
Re: parameter with dynamic dependencies
Posted: Fri Aug 20, 2021 3:34 pm
by dirkse
Pitters,
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'.
Code: Select 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;
HTH,
-Steve