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

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

Constrains the sum of the elements of Collection to satisfy the relation sum(Collection) Rel Sum.

Collection
  Collection of integers or (domain) variables.
RelOp
  One of the atom: #>, #>=, #<, #=<, #=, #\=
Sum
  (Domain) variable or integer (array notation accepted)

## Description

Constrains the sum of the elements in Collection to satisfy the relation sum(Collection) Rel Sum.

Rel can be one of #>, #>=, #<, #=<, #=, #\= (or equivalently, >, >=, <, =<, =, \=).

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(Collections,RelOp)` 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.

Domain consistency is different from bounds consistency only if Rel is #=.

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

## See Also

sum / 4