# Global Constraints Reference¶

class Numberjack.AllDiff(vars, type=None)

All-different constraint on a list of Expression, enforces that each takes a different value.

Parameters: vars – the variables or expressions which must take different values. This should be a VarArray or list with at least two items.

Note

Can only be used as a top-level constraint, not reified.

class Numberjack.AllDiffExcept0(vs)

All-different except zero constraint on a list of Expression, enforces that each takes a different value, except those which take the value 0.

Parameters: vs – the variables or expressions which must take different values. This should be a VarArray or list with at least two items.

Note

Can only be used as a top-level constraint, not reified.

class Numberjack.Sum(vars, coefs=None)

Sum expression with linear coefficients. Numberjack will detect inline sum expressions to extract the sum expression. For example, the following three statements are equivalent however the last one requires the least amount of overhead by Numberjack.

2*a + b + 0.5*c + 3*d == e
Sum([2*a, b, 0.5*c, 3*d]) == e
Sum([a,b,c,d], [2, 1, 0.5, 3]) == e


Note

Cannot be used as a top-level constraint, but can be used as the objective funcion.

Parameters: vars – the variables to be summed. coefs – list of coefficients, which is [1,1,..,1] by default.
class Numberjack.Gcc(vars, cards)

The Global Cardinality Constraint limits the number of times that certain values can be used within a set of variables. For example, we might want the value 1 to occur at least once and at most twice, the value 2 to occur exactly twice, the value 3 at most four times, and so on.

Parameters: vars – the variables which are being constrained. This should be a VarArray or list with at least two items. cards (dict) – A dictionary mapping each constrained value to a two item tuple for the lower and upper bounds on the number of occurrences of that value.
X = VarArray(5, 1, 4)
cards = {1: (1, 2), 2: (2, 2), 3: (0, 3), 4: (1, 2)}
model = Model(Gcc(X,cards))


Note

Can only be used as a top-level constraint, not reified.

class Numberjack.LessLex(vars_1, vars_2)

Less-than lexicographic ordering constraint between two lists of expressions.

Parameters: vars_1 – the fist list of variables or expressions. vars_1 – the second list of variables or expressions.

Note

Can only be used as a top-level constraint, not reified.

class Numberjack.LeqLex(vars_1, vars_2)

Less-than-or-equal lexicographic ordering constraint between two lists of expressions.

Parameters: vars_1 – the fist list of variables or expressions. vars_1 – the second list of variables or expressions.

Note

Can only be used as a top-level constraint, not reified.

class Numberjack.Disjunction(vars)

Disjunction specifying that at least one of the sub-expressions should be true. This can be a top-level constraint or reified as a sub-expression.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items.
class Numberjack.Conjunction(vars)

Conjunction specifying that all the sub-expressions should be true. This should only be used as a reified sub-expression, otherwise, there is an implicity conjunction across all top-level constraints anyway.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items.

The following should be used as sub-expressions, not as top-level constraints.

class Numberjack.Max(vars)

The maximum value of a set of Variables.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items.

Note

Cannot be used as a top-level constraint, only as a sub-expression.

class Numberjack.Min(vars)

The minimum value of a set of Variables.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items.

Note

Cannot be used as a top-level constraint, only as a sub-expression.

class Numberjack.Element(vars, index)

Given an integer Variable e index and a VarArray e vars, Element is the Predicate holding the value of the variable at index index of the array vars.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items.
vars = VarArray(5, 1, 4)
index = Variable(0, 4)
elt1 = Element(vars, index)
elt2 = vars[index]


Note

Cannot be used as a top-level constraint, only as a sub-expression.

class Numberjack.Cardinality(vars, value)

Counts the number of expressions which have been assigned a specific value.

Parameters: vars – the variables or expressions. This should be a VarArray or list with at least two items. value (int) – the value for which the cardinality of is being counted.

Note

Cannot be used as a top-level constraint, only as a sub-expression.

#### Previous topic

Constraints Reference

#### Next topic

Scheduling Constraints