Equations with zero relations taking very long to build

Problems with modeling
Post Reply
pecenak21
User
User
Posts: 24
Joined: 5 years ago

Equations with zero relations taking very long to build

Post by pecenak21 »

Hello,

I have a large model, which is taking a long time to get through the model generation. Once it makes it past that, it is rather quick for the size of the model. To track the performance issue with model generation, I followed the steps outlined in https://www.gams.com/35/docs/UG_ExecErr ... cutionTime, which includes the use of the profile option. When doing this, I see the following summary:
image.png
What is bewildering me is how the longest parts are equations which I use $ conditionals on to reduce all the way to zero relations. You can see that in the screeenshot above, but also in the .lst
image.png
What does it mean for a 'NULL' equation to take nearly 5 minutes to build? Are there any further steps I can take to debug? How about steps to reduce this time?

Thansk,
Zack
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Equations with zero relations taking very long to build

Post by bussieck »

Zack,

In order for GAMS to decide if it needs to generate an equation or not it needs to evaluate the $() expression that you attached to the equation definition logic. Even if they all evaluate to false, so no equation gets generated, this evaluation can take a long time depending of how complex the $() expression is. In most cases there are simple ways to improve such a behavior, but without seeing the $() expression it is hard to give concrete suggestions. Users with a background in "regular" programming overload expressions often with ord and other "position" logic for set elements and repeat this logic at many places. It is much better to build a map once and use this. Again, more concrete suggestions may follow with more details from your side.

-Michael
pecenak21
User
User
Posts: 24
Joined: 5 years ago

Re: Equations with zero relations taking very long to build

Post by pecenak21 »

Thank you Michael,

This was the issue. I was experimenting with using the upper limit on variables as a conditional (i.e. $(myvariable.up>0)), instead of the proper approach which is to set it as a flag (map) and use that. I didn't realize the .up was being evaluated each time it was called. Once I changed that variable to a flag, it is insane how much time saving I am getting. The problem went from nearly 30 minutes of model generation to 30 seconds.

Thank you very much for the timely response, and hopefully this can help other modelers,
Zack
Post Reply