How to accelerate variable multiplication calculation.

Problems with modeling
Post Reply
ZhengyuanZhai
User
User
Posts: 1
Joined: 9 months ago

How to accelerate variable multiplication calculation.

Post by ZhengyuanZhai »

Hello, everyone.
My model takes a lot of time to calculate the product of variables. How can I speed up this process?
Below is the code section that is causing the issue.

Code: Select all

bdef..     benefit =e=sum((t,j),dema(t,j)*(dWind(t,j)+dSolar(t,j)+dFire(t,j))+demb(t,j)
                          *sum(i$ij(t,i,j),(dWind.l(t,j)+dFire.l(t,j)+dSolar.l(t,j)-xWind.l(t,i,j)-xSolar.l(t,i,j)-xFire.l(t,i,j)+xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))*(xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))))
The index 't' represents 730 hours.
image.png
I am using the CPLEX model, and it will take about one minute at the point shown in the graph attachment. Since my model needs to undergo many iterations, this time is quite long for me.
I have located the issue to the product terms of variables:

Code: Select all

(dWind.l(t,j)+dFire.l(t,j)+dSolar.l(t,j)-xWind.l(t,i,j)-xSolar.l(t,i,j)-xFire.l(t,i,j)+xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))*(xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))
If I rewrite it as:

Code: Select all

power((xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j)),2)
,(omitting the rest of the variables for testing purposes) then the process will be very fast, and it won't take more than a few seconds to complete.
However, if I expand the equation as

Code: Select all

(xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))*(xWind(t,i,j)+xSolar(t,i,j)+xFire(t,i,j))
, then the time extends to several tens of seconds. Therefore, I am quite certain that the issue arises from the assignment and calculation of the product terms.
Is there any way to speed up this process? I would greatly appreciate any assistance or suggestions on how to improve its efficiency. Thank you very much for your help.
User avatar
bussieck
Moderator
Moderator
Posts: 1043
Joined: 7 years ago

Re: How to accelerate variable multiplication calculation.

Post by bussieck »

The steps that takes long is the extraction of the Q matrix from the non-linear instructions. There are basically two algorithms to do this and we default to the one (ThreePass) that is is fast in most cases. You might benefit from using the other algorithm (DoubleForward). We even have a "concurrent" option. See https://www.gams.com/latest/docs/S_CPLE ... extractalg for details. The option qextractalg has been added in GAMS 36, before you only could get ThreePass. Looks like that you need to update to use this.

-Michael
Post Reply