0

I have difficulties in reading data that I need from .gdx file. I have succeeded in loading file from Excel, but I get an error when I try to access index that I need:

Sets


 t time intervals       / t1*t12 /   [b] !! set definition[/b]
   i customers          / c1*c5 /
   r row labels         /r1*r97/
   c column labels     /c1,c2,c3,c4,c5/;

parameter p(r,c);  [b]!! reading the table from Excel[/b]
$CALL GDXXRW Curve.xlsx trace=3 par=p rng=Sheet1!a1:f97 rdim=1 cdim=1
$gdxin Curve.gdx
$load p
$gdxin

parameter h; [b] !! reading the scalar[/b]
$CALL GDXXRW load.xlsx trace=3 par=h rng=Sheet1!i2:i2 dim=0
$GDXIN load.gdx
$LOAD h
$GDXIN

cost .. z =e= sum(t, maxLoad -  sum(i, u(i,t)*cons(i)*clpu(t)*p(h,i)));
current_load(t) ..  sum(i, u(i,t)*cons(i)*clpu(t)*p(i,h)) =l= maxLoad;

Code has multiple errors, but the first one I have difficulties with is when reading p(h,i) (line that is bold). I need data from gdx that is in the h column that I read also from other gdx, and i-th row that is the same as i that I am using for other variables. I am not sure if the code that I have attached is enough, so sorry in advance if something is missing.

Sanja
  • 41
  • 7

2 Answers2

0

You define p(r ,c) as parameter. And h as an another parameter . p(h,I) is not meaningful. When you use parameter p , you must have index ( r,c). Not (h,I) .

Richard
  • 177
  • 1
  • 9
0

This was the issue. However I now know how to set desired indices that I want to read from. Following code solves the problem with indices:

Sets
   t time intervals       / t1*t12 /
   i customers          / c1*c5 /
   r row labels         /r1*r97/;

parameter p(r,i), h; 
$CALL GDXXRW Curve.xlsx trace=3 par=p rng=Sheet1!b1:g97 rdim=1 cdim=1 par=h rng=Sheet1!i2:i2 dim=0
$gdxin Curve.gdx
$load p h
$gdxin
display p, h;

cost .. z =e= sum(t, maxLoad -  sum((i,r)$[ord(r)=h], u(i,t)*cons(i)*clpu(t)*p(r,i)));

The key is in this ord() operator that assignes h value to the index r: (i,r)$[ord(r)=h]

Sanja
  • 41
  • 7