Sunday, January 27, 2013

GAMS sameas problem

I tried a construct that looks like the following code:

sets
   cell5m
   cell5m_spam
;

$gdxin d.gdx
$load cell5m cell5m_spam


set
cellmap(cell5m,cell5m_spam);
cellmap(cell5m,cell5m_spam)$sameas(cell5m,cell5m_spam) =
yes
;   (1)

Basically I take the intersection of the two sets and create a mapping between the two base sets. Unfortunately, the sets are big:

scalars
  n_cell5m
  n_cell5m_spam
;

n_cell5m =
card(cell5m);
n_cell5m_spam =
card
(cell5m_spam);

display
n_cell5m, n_cell5m_spam;

----     23 PARAMETER n_cell5m             =  2294094.000 
            PARAMETER n_cell5m_spam        =   806882.000 

as a result expression (1) takes an extraordinary long time to execute:

----     26 Assignment cellmap    2436.954  2437.032 SECS    383 Mb  806839

I believe the sameas function is just not properly implemented in GAMS. This performance is really not what one would expect.

Of course we can work around this:

sets
   cell5m(*)
   cell5m_spam(*)
;

$gdxin d.gdx
$load cell5m cell5m_spam


alias (*,u);
set
intersect(*);
intersect(u) = cell5m(u)*cell5m_spam(u);


set
cellmap(cell5m,cell5m_spam);
cellmap(cell5m(intersect),cell5m_spam(intersect)) =
yes
;

This now executes in much less than a second:

----     27 Assignment intersect     0.187     0.203 SECS    333 Mb  806839
----     33 Assignment cellmap       0.203     0.406 SECS    358 Mb  806839

Note that we had to change the declarations of the sets a little bit, in order to get this passed the domain checking of GAMS.

No comments:

Post a Comment