0

I have a two-dimensional array in gams, which i'd like to convert into a one-dimensional array.

I.e. I have

set i /i1*i100/ 
set j /j1*j100/
parameter array(i,j)

And now I'd like something like:

set n /n1*n10000/
parameter one_dim_array(n) 

And all elements of the above array should become elements of one_dim_array, by going over all rows and all columns and writing out the values.

I tried:

parameter index /0/
loop(i,
loop(j,
one_dim_array(n%index%) = array(i,j);
index = index + 1;
)) 

However, GAMS doesn't seem to understand this n%index% notation and returns an error that it's not a set. Any way to circumvent this?

Thanks a lot!

nonick
  • 3
  • 3
  • By the way, i tried every combination of "n%index", with and without quotes and both doesn't seem to work – nonick Aug 23 '16 at 13:19

1 Answers1

0

You could build up a mapping between n and i,j using the matching operator (http://www.gams.com/help/index.jsp?topic=%2Fgams.doc%2Fuserguides%2Fmccarl%2Fdefining_a_tuple_with_the_matc.htm), which can be used for the assignment like here:

set i /i1*i100/
    j /j1*j100/
    n /n1*n10000/
    nijMap(n,i,j) /#n:(#i.#j)/;

parameter array(i,j)
          one_dim_array(n);

array(i,j)       = uniform(0,1);
one_dim_array(n) = sum(nijMap(n,i,j), array(i,j));

I hope that helps! Best, Lutz

Lutz
  • 2,197
  • 1
  • 10
  • 12