Hello,
I am writing because we are working on a program in GAMS and encountering issues related to execution speed.
In the attached folder, you will find three .gms files: the main file, “perSupportoGams,” calls the other two. Input and output files (.log and .list) are also included.
We are struggling to understand why some seemingly simple operations, such as assigning scalars to a parameter, take longer than expected, significantly slowing down the program when these operations are repeated many times over a large number of iterations.
We have implemented two versions of the code to demonstrate how some changes affect execution times. We are reaching out to ask for support in understanding the cause of these inefficiencies and finding ways to address the issue.
Program Description
The program simulates the random generation of failures in power generators over a time horizon defined in the input. Failure parameters (in the guastotot.csv file) are used to randomly determine, for each generator:
the time interval of the failure,
the percentage of degraded power (partial failure simulation).
This process is repeated for each generator and simulated within a Monte Carlo sample loop.
Additionally, standard output printing no longer works: instead of displaying output on the screen, the program creates a file named “con.” perSupportoGAMS.zip (1.6 MB)
The loop(AC, and loop(SAMPLES, only do one iteration. The loop loop(G_TO_AREA(NG,NAREE)$(G_TO_PAR_GU(NG,'MTTF')>0), does 271 iterations. The while(tini<nhours, does varying iterations 20-30. I programmed the we only do one iteration through loop(G_TO_AREA(NG,NAREE)$(G_TO_PAR_GU(NG,'MTTF')>0), (instead of 271) and then stop. I ran with profile=4 to see the profiling information of the inner most loop. With that I get:
So for every iteration of loop(G_TO_AREA(NG,NAREE)$(G_TO_PAR_GU(NG,'MTTF')>0), it takes about 1.8 seconds. So the estimate for the total will be around 271*1.8 ≈ 500 seconds. Overall the estimate was somewhat conservative, my machine this runs for 240 seconds.
The assignment statements that cost something are P_DEG(HOURS,NG) =1; (line 3108) and P_DEG(oreGuasto(HOURS), NG)=P_DEG_dummy; (line 3180). The latter one we do 20-30 times, So these make up all the time in your “algorithm”. The first statement assigns 8.5 million numbers. The second does the same in slices. This takes some time.
I don’t understand what you do in the part of the model but I am sure the speed can be improved but this requires careful analysis and some time.
The con issue is actually a Windows issue. With Windows 11, the console needs to be addressed properly as con: with older Windows versions con was sufficient. Just change the screen definition to file screen / 'con:' /;