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.
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.
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:
(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:
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
(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.