'Explicitly write the sum of bilinear or trilinear terms in GAMS?

I am working on writing a constraint in GAMS which involves a polynomial with the sum of 1st, 2nd, and 3rd order terms. Since there are 7 variables (from x('1') to x('7')), there are in total 119 terms (7 first-order terms, 28 second-order terms, and 84 third-order terms).

The first-order terms are easy to write out:

c('1')*x('1') + c('2')*x('2') ...

However, the second-order terms are more difficult to write:

c('8')*x('1')*x('1')+c('9')*x('1')*x('2') ... +c('14')*x('1')*x('7')+c('15')*x('2')*x('2') ... + c('35')*x('7')*x('7') 

The thrid order terms are just too many and too long:

c('36')*x('1')*x('1')*x('1') + c('37')*x('1')*x('1')*x('2') + ... + c('119')*x('7')*x('7')*x('7')

It is really challenging to write the equations manually. I was wondering if there is a way to use the 'sum' and conditional ($) operation to write out these 119 terms explicitly.

For instance,

Set 
i /1 * 7/
num /1 * 119/
;

Variable 
x(i)
func
;

Parameters
c(num)
;

Equation
Eq1;

Eq1.. func =e= c('1')*x('1') + c('2')*x('2') + {many terms in between} +  c('8')*x('1')*x('1')+c('9')*x('1')*x('2') + {many terms in between} +  c('36')*x('1')*x('1')*x('1') + c('37')*x('1')*x('1')*x('2') + {many terms in between} + c('119')*x('7')*x('7')*x('7')

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source