9.9 Summing Vectors Over Index Values

Summations are used when you want to sum vector terms over some indexes. The summation consists of the keyword SUM, the parentheses containing the list of indexes summed, and the summation formula.

Both variable and data vectors can be included in the summation formula. The vectors can be added and subtracted, and parentheses and other summations are allowed within the sum. This example shows how sums are used:

    MaxProd :  SUM(month : Production)  < 1200 ;

The above constraint means that sum of the Production variables for all months has to be less than 1200. The resulting constraint in the input file generated, is:

    MaxProd :  ProdJan + ProdFeb + ProdMar + ProdApr
             + ProdMay + ProdJun + ProdJul + ProdAug
             + ProdSep + ProdOct + ProdNov + ProdDec  <  1200 ;

Now assume that you have three products and want to limit the production for each. Then the constraint would be:

    MaxProd[product] : SUM(month: Production)  <  ProdCapacity ;

This summation generates three constraints, one for each product. The Production vector is now defined over the indexes product and month. The constraint for a given product contains the sum of the Production variables for all months, but with the product fixed.

The main rule when using sums is that all declared indexes of a vector term must be accounted for, either by the sum indexes, the constraint indexes, or by a fixed subscript.

When summing over a single vector, you can omit the list of index variables. MPL automatically uses the dimension of the vector when it expands the sum.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page