parameter with dynamic dependencies

Problems with syntax of GAMS
Post Reply
pitters
User
User
Posts: 9
Joined: 3 months ago

parameter with dynamic dependencies

Post by pitters » 1 month ago

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
Screenshot_1.png (5.29 KiB) Viewed 1110 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!

GFA
User
User
Posts: 34
Joined: 3 years ago

Re: parameter with dynamic dependencies

Post by GFA » 1 month ago

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;

pitters
User
User
Posts: 9
Joined: 3 months ago

Re: parameter with dynamic dependencies

Post by pitters » 1 month ago

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
Screenshot_2.png (3.41 KiB) Viewed 1065 times
material is not working hahah

Regards,
Pitters

User avatar
dirkse
Moderator
Moderator
Posts: 165
Joined: 5 years ago
Location: Fairfax, VA

Re: parameter with dynamic dependencies

Post by dirkse » 1 month ago

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

Post Reply