0

How do I create a set to whose elements were added the first 4 letters of another set and the first 2 letters of the elements of another set? For example, I have 2 sets: one is composed of years and the other of quarters:

SET TY /2019`*`2040/;

`SET TQ /Q1`*`Q4/;

And I need another set that is the Cartesian product of both, but in a single value for each element:

SET T /2019Q1*2019Q4,2020Q1*2020Q4… 2040Q1*2040Q4/;

In Stata for example, I would do this:

Global year “2019 2020 2021 … 2040 “

Global quarter “Q1 Q2 Q3 Q4”

Foreach y of global year {

Foreach q of global quarter{

Global T = ‘y’ ‘q’

…
}}

How can I did this in GAMS?

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25

1 Answers1

0

If you really need this new one dimensional set, that has no logical relation to TY and TQ, you could do it like this:

SET TY /2019*2040/;
SET TQ /Q1*Q4/;

Set T(*);  

$onEmbeddedCode Python:
t = []
for ty in gams.get('TY'):
   for tq in gams.get('TQ'):
       t.append(ty + tq)
gams.set('T',t)
$offEmbeddedCode T

display T;

However, I do not know your use case of course, but maybe something like this could make more sense for you:

SET TY /2019*2040/;
SET TQ /Q1*Q4/;

Set T(TY,TQ) /#TY.#TQ/;  
display T;
Lutz
  • 2,197
  • 1
  • 10
  • 12