Speed up model generation time when using loop

Problems with modeling
Post Reply
feifan
User
User
Posts: 18
Joined: 5 years ago

Speed up model generation time when using loop

Post by feifan »

Hi, all,

I am using a loop function to calculate a model with adjustable parameters repeatedly.
In each iteration, I change a part of the parameters in the model and solve it again.

However, since my model is quite huge, it takes 5-6 seconds to implement model generation. In each iteration, GAMS has to generation model again and again. Therefore, most of the time was spent on model generation (model is solved fast).

So, my question is that, since I solve the same model with some different parameters, is there any methods that can be used to avoid or at least speed up the repetitive model generation in each iteration.

By the way, I have tried my best to reformulate the model to reduce the model generation time.

Thanks in advance.

Kind regard,
feifan
Fred
Posts: 373
Joined: 7 years ago

Re: Speed up model generation time when using loop

Post by Fred »

Hi,

if the model rim is always the same and you know all the parameters in advance (i.e. sceanrio 2 dose not depend on the solution of scenario 1 etc), GUSS might be what you are looking for: https://www.gams.com/latest/docs/S_GUSS.html
If you are willing to share your model (and data) to allow other users to reproduce what you are doing, eventually someone will also jump on it to analyze model generation time. Sometimes the vast amount of time is spent in the generation of a particular equation and once the bottleneck has been identified, model generation can be speeded up significantly.

Best,
Fred
feifan
User
User
Posts: 18
Joined: 5 years ago

Re: Speed up model generation time when using loop

Post by feifan »

Hi, Fred,

Thanks for your answers.

In my model, parameters are updated according to the solutions obtained in the last iteration. So, we do not know the parameters in advance.

I totally understand what you were referring to. I think the model generation time is acceptable to me because the model is quite huge. The problem is that GAMS has to generate the model again and agian in each iteration, which significantly increases the calculation time in total. Is there any good ideas to avoid this kind of repetitive model generation?


Kind regard,
feifan



Fred wrote: 5 years ago Hi,

if the model rim is always the same and you know all the parameters in advance (i.e. sceanrio 2 dose not depend on the solution of scenario 1 etc), GUSS might be what you are looking for: https://www.gams.com/latest/docs/S_GUSS.html
If you are willing to share your model (and data) to allow other users to reproduce what you are doing, eventually someone will also jump on it to analyze model generation time. Sometimes the vast amount of time is spent in the generation of a particular equation and once the bottleneck has been identified, model generation can be speeded up significantly.

Best,
Fred
Fred
Posts: 373
Joined: 7 years ago

Re: Speed up model generation time when using loop

Post by Fred »

Hi Feifan,

The GAMS OO API class GAMSModelInstance provides access to a model instance that can be modified and resolved without regenerating the model over and over. (see e.g. the transport 7 example from the Python API Tutorial: https://www.gams.com/latest/docs/API_PY ... HECKPPOINT).

In Combination with the GAMS Embedded Code Facility (https://www.gams.com/latest/docs/UG_EmbeddedCode.html), this could be used to do what you describe.

Example embmiex1 from the GAMS Model library illustrates how to get access to a model instance that can be modified and resolved without regenerating the model over and over again: https://www.gams.com/latest/gamslib_ml/ ... miex1.html
With --usesolverlog=1 on the command line you see the solver logs of the 3 different solves.
Note that this requires a recent GAMS version.

Even though this example does not exercise the ability, the combination of GAMSModelInstance and embedded code provides a way of defining the scenario n+1 based on the result (primal and dual) of the nth scenario.

I hope this helps!

Best,
Fred
Post Reply