sum

OPL keyword to compute summations.

Purpose

OPL keyword to compute summations of a collection of related expressions.

context
Model files (.mod)

Syntax

AggregateExpression: "sum" '(' Qualifiers ')' Expression
                   | "min" '(' Qualifiers ')' Expression
                   | "max" '(' Qualifiers ')' Expression
                   | "prod" '(' Qualifiers ')' Expression

Description

Integer and float expressions can be constructed using aggregate operators for computing summations (sum), products (prod), minima (min), and maxima (max) of a collection of related expressions. Behavior on empty sets:

sum(empty set)=0

Example

int n = 10;
range Range = 0..n-1; 
dvar int s[Range]; 
subject to 
{ 
    
   sum(i in Range) s[i] == n; 
   sum(i in Range) s[i]*i == n; 
}