[ library(gfd) | Reference Manual | Alphabetic Index ]

<ConsistencyModule:> sum(+Collection,?Sum)

The sum (Collection) or scalar product (IntCollection*Collection) of the Collection elements is Sum
Collection or Coeffs*Collection
Collection: collection of N integers or (domain) variables. Coeffs: collection of N integers.
Sum
(Domain) variable or integer (array notation accepted)

Description

Constrains Sum to be the sum of the elements in Collection if the first argument is a collection of integers or domain variables.

Constrains Sum to be the scalar product of a collection of integers and a collection of integers or domain variables if the first argument is Coeffs*Collection. Coeffs and Collection must have the same number of elements, and the scalar product is the sum of the coefficients in Coeffs with the corresponding element in Collection.

Any input variables which are not already domain variable will be turn into domain variables with default bounds.

You may find it more convenient to embed sum(Vars) in a constraint expression.

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_bc for bounds consistency, and gfd_gac for domain (generalised arc) consistency.

This constraint is known as sum_ctr (with the = relation) in the global constraint catalog, and is implemented using Gecode's linear() constraint (with IRT_EQ relation).

See Also

sumlist / 2, sum / 2