Jason,
Sorry for the late reply.
Seems that we are discussing two points
1. Slow execution of assignment
Let me try to give you some background. You use different data types for wind speed.
a) set w; This set contains different wind speeds in the form of a discrete set 0.0, 0.1, 0.2, 0.3, … Set elements are treated as strings (but if you know they have a numerical value, you can access it via .val)
b) parameter speed(i,j,k); This parameter also contains different wind speeds but as numerical values 0.0, 0.1, 0.2, 0.3, …
Since you already treat wind speeds as set elements, I wonder whether you actually need parameter speed. You could read the wind speeds as sets from the station*.txt files. The advantage is that this allows you to get rid of the comparison (abs(w.val-speed(i,j,k))<1e-6) in the assignment to power_output(i,j,k,t) and do sth. like
...
set speed(i,j,k,w)
...
power_output(i,j,k,t) = sum(speed(i,j,k,w), power_wind(t,w));
...
This is considerably faster.
2. reading enumerated files with identical filestem (station1.txt, station2.txt, …)
There are many ways to reduce the amount of code. The attached examples illustrate two alternatives. Note that your recent station.txt is slightly different to the on from post #1. I read only some of the columns of station*.txt and do not read generator*.txt but I guess you can adopt the examples as needed.
a) batinclude: Write a little GAMS script that takes the number of the file as argument and does the reading.
...
$onechoV > readStationData.gms
$call csv2gdx station%1.txt output=station%1.gdx id=speed fieldSep=semiColon index=1,2,3,5 useHeader=y storeZero=y
$ife errorlevel<>0 $abort problem with csv2gdx station%1
$gdxIn station%1.gdx
$load speed
$gdxIn
$offecho
$onMulti
$batinclude readStationData.gms 1
$batinclude readStationData.gms 2
...
$onecho … writes the file readStationData.gms which us subesequently (bat)included. The argument of the batinclude replaces the internal placeholder (%1). You can read more about that in the documentations
b) put_ultility: Write a script where in the script you loop over all the files that need to be read.
...
$onechoV > readStationData.gms
file load / loadGDX.inc /;
set f files / 1*%NBFILES%/;
loop(f,
put_utility 'exec' / 'csv2gdx station' f.tl:0 '.txt output=station' f.tl:0 '.gdx id=speed fieldSep=semiColon index=1,2,3,5 useHeader=y storeZero=y'
abort$(errorlevel<>0) 'probem running csv2gdx via put utility'
put load '$gdxin station' f.tl:0 '.gdx' /
'$load speed' /
'$gdxin' /;
);
putclose;
$offecho
$call gams readStationData.gms lo=%gams.lo% --NBFILES=5
$ife errorlevel<>0 $abort problem running readStationData.gms
$onMulti
$include loadGDX.inc
...
You pass the number of files to read (–NBFILES) as an argument to the script which loops over the txt files, creates the gdx files, and writes a list of gdxin instructions to include later. Note that you have to outsource this put_utility approach to a script because the put_utility command is carried out at execution time while you (probably) want the data to be available at compile time. The trick is to call the script at compile time via $call. You can read more about the two phases (compilation, execution) in the documentation: https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_TwoPass
I hope this helps!
Fred
jason.zip (772 KB)