Hello all,
so far I have the following code, which specifies the number of grid points:
$if not set gridpoints $set gridpoints 23
Set
g 'grid points' / g0*g%gridpoints% /
Now I would like to specify the number of grid points via Excel. The parameter is then read from the Excel file. I have already tried:
Parameter num_gridpoints
Set
g 'grid points' / g0*g%num_gridpoints% /
But this approach didn’t work. I hope somebody can help me
You cannot use parameter to define a set. I am not sure if this is the best way, but you can define a subset of a big set and assign it using the parameter that you read form excel as follows:
parameter set_size /5/;
set
univ /i1*i10000/
i(univ)
;
i(univ)$(ord(univ) <= set_size) = yes;
display i;
Thank you for your approach! It works now
If you get the parameter (or better the scalar) at compile time then there is a way. Since you get your values from Excel, I guess you do at some stage:
Scalar num_gridpoints;
$gdxIn fromExcel.gdx
$load num_gridpoints
...
$gdxIn
Now you can turn the value of scalar num_gridpoints at compile time into a compile time variable and use that in your grid definition:
$eval NUM_GRIDPOINTS num_gridpoints
Set
g 'grid points' / g0*g%NUM_GRIDPOINTS% /
...
$gdxIn
Important this does not work with scalar calculated (at execution time). You can do some limited calculation at compile time with the $eval command, you can also use some functions, e.g. card, so if you have a 2-dim grid and need 1-dim set representing all points this also works:
$if not set XMAX $set XMAX 9
$if not set YMAX $set YMAX 9
Set
x 'x-axis' / x0*x%XMAX% /
y 'y-axis' / y0*y%YMAX% /
g(x,y) 'grid points' / #x.#y /;
$eval PMAX card(x)*card(y)-1
Set p / p0*p%PMAX% /
xypmap(x,y,p) / #x.#y:#p /;
...
-Michael
Ah great! Thanks for your solution This works for my problem a little better than Atharv’s solution.
Thank you both!