4.2.1. Global constraints¶
These constraints represent high-level modelling abstractions, for which many solvers implement special, efficient inference algorithms.
4.2.1.2. Lexicographic constraints¶
Require adjacent rows and adjacent columns in the array x
to be
lexicographically ordered. Adjacent rows and adjacent columns may be equal.
Requires that the array x
is strictly lexicographically greater than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically greater than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically greater than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically greater than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically greater than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically greater than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically greater than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically greater than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically less than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically less than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically less than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is strictly lexicographically less than
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically less than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically less than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically less than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that the array x
is lexicographically less than or equal to
array y
. Compares them from first to last element, regardless of indices.
Requires that i
precedes i
+1 in the array x
for all positive i
.
Requires that i
appears in a set in array x
before i
+1 for all positive i
Require adjacent rows and adjacent columns in the array x
to be
lexicographically ordered. Adjacent rows and adjacent columns cannot be equal.
Requires that s
precede t
in the array x
.
Precedence means that if any element of x
is equal to t
, then another element of x
with a lower index is equal
to s
.
Requires that s
precede t
in the array x
.
Precedence means that if an element of x
contains t
but not s
, then another element of x
with lower index contains
s
but not t
.
Requires that c
[ i
] precedes c
[ i
+1] in the array x
.
Precedence means that if any element of x
is equal to c
[ i
+1], then another element of x
with a lower index is equal
to c
[ i
].
Requires that c
[ i
] precedes c
[ i
+1] in the array x
.
Precedence means that if an element of x
contains c
[ i
+1] but not c
[ i
], then another element of x
with lower index contains
c
[ i
] but not c
[ i
+1].
4.2.1.3. Sorting constraints¶
Returns the permutation p
which causes x
to be in sorted order hence
x
[ p
[ i
]] <= x
[ p
[ i
+1]].
The permutation is the stable sort hence x
[ p
[ i
]] = x
[ p
[ i
+1]] \(\rightarrow\) p
[ i
] < p
[ i
+1].
Returns the permutation p
which causes x
to be in sorted order hence
x
[ p
[ i
]] <= x
[ p
[ i
+1]].
The permutation is the stable sort hence x
[ p
[ i
]] = x
[ p
[ i
+1]] \(\rightarrow\) p
[ i
] < p
[ i
+1].
Constrains p
to be the permutation which causes x
to be in sorted order hence
x
[ p
[ i
]] <= x
[ p
[ i
+1]].
The permutation is the stable sort hence x
[ p
[ i
]] = x
[ p
[ i
+1]] \(\rightarrow\) p
[ i
] < p
[ i
+1].
Constrains p
to be the permutation which causes x
to be in sorted order hence
x
[ p
[ i
]] <= x
[ p
[ i
+1]].
The permutation is the stable sort hence x
[ p
[ i
]] = x
[ p
[ i
+1]] \(\rightarrow\) p
[ i
] < p
[ i
+1].
Requires that the array x
is in decreasing order (duplicates are allowed).
Requires that the array x
is in decreasing order (duplicates are allowed).
Requires that the array x
is in decreasing order (duplicates are allowed).
Requires that the array x
is in decreasing order (duplicates are allowed).
Requires that the array x
is in increasing order (duplicates are allowed).
Requires that the array x
is in increasing order (duplicates are allowed).
Requires that the array x
is in increasing order (duplicates are allowed).
Requires that the array x
is in increasing order (duplicates are allowed).
Requires that the multiset of values in x
are the same as the
multiset of values in y
but y
is in sorted order.
Return a multiset of values that is the same as the
multiset of values in x
but in sorted order.
4.2.1.4. Channeling constraints¶
Requires that array of int variables x
and array of set variables y
are related such that ( x
[ i
] = j
) \(\leftrightarrow\) ( i
in y
[ j
]).
Constrains two arrays of int variables, f
and invf
, to represent
inverse functions. All the values in each array must be within the index
set of the other array.
Given a function f
represented as an array, return the inverse function.
Given a function f
represented as an array, return the inverse function.
If the i
th variable of the collection X
is assigned to j
and if j
is in the index set of Y
then the j
th variable of the collection Y
is assigned to i
.
Conversely, if the j
th variable of the collection Y
is assigned to i
and if i
is in the index set of X
then the i
th variable of the collection X
is assigned to j
.
Constrains two arrays of set of int variables, f
and invf
, so that
a j
in f[ i
] iff i
in invf[ j
]. All the values in each array’s sets
must be within the index set of the other array.
Constrain the array of Booleans b
to be a representation of the set s
:
i
in s
\(\leftrightarrow\) b
[ i
].
The index set of b
must be a superset of the possible values of s
.
4.2.1.5. Counting constraints¶
These constraints count and restrict how many times certain values occur
in an array of variables. MiniZinc will automatically generate the basic counting
constraints below from expressions such as count(i in x)(i=c) <= d
, so you
can write models in this much more readable style instead of using these
predicates. However, if your model
contains multiple counting constraints over the same array, constraints
like distribute
or global_cardinality
below may be useful.
Requires exactly n
variables in x
to take one of the values in v
.
Returns the number of variables in x
that take one of the values in v
.
Requires at least n
variables in x
to take the value v
.
Requires at most n
variables in x
to take the value v
.
Requires that each pair of sets in s
overlap in at most one element.
Constrains c
to be the number of occurrences of y
in x
.
Returns the number of occurrences of y
in x
.
Constrains c
to be the number of occurrences of y
in x
.
Constrains c
to be the number of occurrences of y
in x
.
Returns the number of occurrences of y
in x
.
Constrains c
to be greater than or equal to the number of occurrences
of y
in x
.
Constrains c
to be greater than or equal to the number of occurrences
of y
in x
.
Constrains c
to be strictly greater than the number of occurrences
of y
in x
.
Constrains c
to be strictly greater than the number of occurrences
of y
in x
.
Constrains c
to be less than or equal to the number of occurrences
of y
in x
.
Constrains c
to be less than or equal to the number of occurrences
of y
in x
.
Constrains c
to be strictly less than the number of occurrences
of y
in x
.
Constrains c
to be strictly less than the number of occurrences
of y
in x
.
Constrains c
to be not equal to the number of occurrences
of y
in x
.
Constrains c
to be not equal to the number of occurrences
of y
in x
.
Requires that card
[ i
] is the number of occurrences of value
[ i
] in
base
. The values in value
need not be distinct.
Returns an array of the number of occurrences of value
[ i
] in
base
. The values in value
need not be distinct.
Requires exactly n
variables in x
to take the value v
.
Requires that the number of occurrences of cover
[ i
] in x
is counts
[ i
].
Returns the number of occurrences of cover
[ i
] in x
.
Requires that the number of occurrences of i
in x
is counts
[ i
].
The elements of x
must take their values from cover
.
Returns an array with number of occurrences of i
in x
.
The elements of x
must take their values from cover
.
Requires that for all i
, the value cover
[ i
] appears at least lbound
[ i
]
and at most ubound
[ i
] times in the array x
.
Requires that for all i
, the value cover
[ i
] appears at least lbound
[ i
]
and at most ubound
[ i
] times in the array x
.
The elements of x
must take their values from cover
.
4.2.1.6. Packing constraints¶
Requires that each item i
with weight w
[ i
], be put into bin
[ i
] such
that the sum of the weights of the items in each bin does not exceed the
capacity c
.
Assumptions:
forall
i
,w
[i
] >=0c
>=0
Requires that each item i
with weight w
[ i
], be put into bin
[ i
] such
that the sum of the weights of the items in each bin b
does not exceed the
capacity c
[ b
].
Assumptions:
forall
i
,w
[i
] >=0forall
b
,c
[b
] >=0
Requires that each item i
with weight w
[ i
], be put into bin
[ i
] such
that the sum of the weights of the items in each bin b
is equal to
load
[ b
].
Assumptions:
forall
i
,w
[i
] >=0
Returns the load of each bin resulting from packing each item i
with
weight w
[ i
] into bin
[ i
], where the load is defined as
the sum of the weights of the items in each bin.
Assumptions:
forall
i
,w
[i
] >=0
Constrains rectangles i
, given by their origins ( x
[ i
], y
[ i
])
and sizes ( dx
[ i
], dy
[ i
]), to be non-overlapping. Zero-width
rectangles can still not overlap with any other rectangle.
Constrains k
-dimensional boxes to be non-overlapping. For each box i
and dimension j
, box_posn
[ i
, j
] is the base position of the box
in dimension j
, and box_size
[ i
, j
] is the size in that dimension.
Boxes whose size is 0 in any dimension still cannot overlap with any other box.
Constrains rectangles i
, given by their origins ( x
[ i
], y
[ i
])
and sizes ( dx
[ i
], dy
[ i
]), to be non-overlapping. Zero-width
rectangles can be packed anywhere.
Constrains k
-dimensional boxes to be non-overlapping. For each box i
and dimension j
, box_posn
[ i
, j
] is the base position of the box
in dimension j
, and box_size
[ i
, j
] is the size in that dimension.
Boxes whose size is 0 in at least one dimension can be packed anywhere.
A global non-overlap constraint for k
dimensional objects. It enforces that no two objects overlap.
Parameters:
k
: the number of dimensionsrect_size
: the size of each box ink
dimensionsrect_offset
: the offset of each box from the base position ink
dimensionsshape
: the set of rectangles defining thei
-th shape.x
: the base position of each object.x
[i
,j
] is the position of objecti
in. dimensionj
.kind
: the shape used by each object.
A global non-overlap constraint for k
dimensional objects. It enforces that no two objects overlap, and that all objects fit within a global k
dimensional bounding box.
Parameters:
k
: the number of dimensionsrect_size
: the size of each box ink
dimensionsrect_offset
: the offset of each box from the base position ink
dimensionsshape
: the set of rectangles defining thei
-th shape.x
: the base position of each object.x
[i
,j
] is the position of objecti
in dimensionj
.kind
: the shape used by each object.l
: is an array of lower bounds,l
[i
] is the minimum bounding box for all objects in dimensioni
.u
: is an array of upper bounds,u
[i
] is the maximum bounding box for all objects in dimensioni
.
A global non-overlap constraint for 2
dimensional objects. It enforces that no two objects overlap
and zero-length objects do not appear in the middle of other objects.
Parameters:
x1
: first coordinate of each objectw2
: width in first dimension for each objectx2
: second coordinate of each objectw2
: width in second dimension for each object
A global non-overlap constraint for k
dimensional objects. It enforces that no two objects overlap, and that all objects fit within a global k
dimensional bounding box. In addition, it enforces that the bounding box is the smallest one containing all objects, i.e., each of the 2k
boundaries is touched by at least by one object.
Parameters:
k
: the number of dimensionsrect_size
: the size of each box ink
dimensionsrect_offset
: the offset of each box from the base position ink
dimensionsshape
: the set of rectangles defining thei
-th shape.x
: the base position of each object.x
[i
,j
] is the position of objecti
in dimensionj
.kind
: the shape used by each object.l
: is an array of lower bounds,l
[i
] is the minimum bounding box for all objects in dimensioni
.u
: is an array of upper bounds,u
[i
] is the maximum bounding box for all objects in dimensioni
.
Requires that items are packed in a knapsack with certain weight and profit restrictions.
Assumptions:
Weights
w
and profitsp
must be non-negativew
,p
andx
must have the same index sets
Parameters:
w
: weight of each type of itemp
: profit of each type of itemx
: number of items of each type that are packedW
: sum of sizes of all items in the knapsackP
: sum of profits of all items in the knapsack
4.2.1.7. Scheduling constraints¶
Alternative constraint for optional tasks. Task ( s0
, d0
) spans the
optional tasks ( s
[ i
], d
[ i
]) in the array arguments
and at most one can occur
Requires that a set of tasks given by start times s
, durations d
, and
resource requirements r
, never require more than a global resource bound
b
at any one time.
Assumptions:
forall
i
,d
[i
] >= 0 andr
[i
] >= 0
Requires that a set of tasks given by start times s
, durations d
, and
resource requirements r
, never require more than a global resource bound
b
at any one time. Start times are optional variables, so
that absent tasks do not need to be scheduled.
Assumptions:
forall
i
,d
[i
] >= 0 andr
[i
] >= 0
Requires that a set of tasks given by start times s
and durations d
do not overlap in time. Tasks with duration 0 can be scheduled at any time,
even in the middle of other tasks.
Assumptions:
forall
i
,d
[i
] >= 0
Requires that a set of tasks given by start times s
and durations d
do not overlap in time. Tasks with duration 0 can be scheduled at any time,
even in the middle of other tasks. Start times are optional variables, so
that absent tasks do not need to be scheduled.
Assumptions:
forall
i
,d
[i
] >= 0
Requires that a set of tasks given by start times s
and durations d
do not overlap in time. Tasks with duration 0 CANNOT be scheduled at any time,
but only when no other task is running.
Assumptions:
forall
i
,d
[i
] >= 0
Requires that a set of tasks given by start times s
and durations d
do not overlap in time. Tasks with duration 0 CANNOT be scheduled at any time,
but only when no other task is running. Start times are optional variables, so
that absent tasks do not need to be scheduled.
Assumptions:
forall
i
,d
[i
] >= 0
Span constraint for optional tasks. Task ( s0
, d0
) spans the optional
tasks ( s
[ i
], d
[ i
]) in the array arguments.
4.2.1.8. Graph constraints¶
Constrains the subgraph ns
and es
of a given directed graph to be a path from s
to t
of weight K
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the cost of the path
Constrains the subgraph ns
and es
of a given directed graph to be a path from s
to t
of weight K
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edgew
: the weight of each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the cost of the path
Constrains the subgraph ns
and es
of a given undirected graph to be a path from s
to t
of weight K
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the cost of the path
Constrains the subgraph ns
and es
of a given undirected graph to be a path from s
to t
of weight K
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edgew
: the weight of each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the cost of the path
Constrains the subgraph ns
and es
of a given undirected graph to be connected.
Parameters:
from
: is the leaving node for each edgeto
: is the entering node for each edgens
: is a Boolean for each node whether it is in the subgraphes
: is a Boolean for each edge whether it is in the subgraph
Constrains the set of edges es
of a given directed graph to be a weighted spanning tree rooted at r
of weight W
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edger
: the root node (which may be variable)es
: a Boolean for each edge whether it is in the subgraphK
: the weight of the tree
Constrains the subgraph ns
and es
of a given directed graph to be a DAG.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edgens
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be connected.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edgens
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be a path from s
to t
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be a path from s
to t
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be reachable from r
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be reachable from r
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be a weighted spanning tree rooted at r
of weight W
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the weight of the tree
Constrains the subgraph ns
and es
of a given directed graph to be a tree rooted at r
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given directed graph to be at tree rooted at r
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be a path from s
to t
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be a path from s
to t
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edges
: the source node (which may be variable)t
: the dest node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be reachable from r
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be reachable from r
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the set of edges es
of a given undirected graph to be a weighted spanning tree of weight W
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edgens
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraphK
: the weight of the tree
Constrains that ns
and es
is a subgraph of a given directed graph.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgens
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains that ns
and es
is a subgraph of a given directed graph.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edgens
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be a tree rooted at r
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the subgraph ns
and es
of a given undirected graph to be at tree rooted at r
.
Parameters:
from
: the leaving node for each edgeto
: the entering node for each edger
: the root node (which may be variable)ns
: a Boolean for each node whether it is in the subgraphes
: a Boolean for each edge whether it is in the subgraph
Constrains the set of edges es
of a given undirected graph to be a weighted spanning tree of weight W
.
Parameters:
N
: the number of nodes in the given graphE
: the number of edges in the given graphfrom
: the leaving node 1..N
for each edgeto
: the entering node 1..N
for each edgew
: the weight of each edgees
: a Boolean for each edge whether it is in the subgraphK
: the weight of the tree
4.2.1.9. Extensional constraints (table, regular etc.)¶
Requires that x
defines a path in the cost MDD with total edge weight totalcost
.
Parameters:
N
: the number of nodes, the root node is node 1level
: the level of each node, the root is level 1, T is levellength
(x)+1E
: the number of edgesfrom
: the leaving node (1..N
)for each edgelabel
: the set of value of the x variable for each edgecost
: the cost for each edgeto
: the entering node for each edge, where 0 = T nodetotalcost
: the total cost of the path defined byx
The sequence of values in array x
(which must all be in the range 1.. S
)
is accepted by the DFA of Q
states with input 1.. S
and transition
function d
(which maps (1.. Q
, 1.. S
) -> 0.. Q
)) and initial state q0
(which must be in 1.. Q
) and accepting states F
(which all must be in
1.. Q
). We reserve state 0 to be an always failing state. Each edge has an associated cost c
,
and C
is the sum of costs taken on the accepting path for x
.
Requires that x
defines a path from root to true node T through the (deterministic) MDD defined by
The MDD must be deterministic, i.e., there cannot be two edges with the same label leaving the same node.
Parameters:
N
: the number of nodes, the root node is node 1level
: the level of each node, the root is level 1, T is levellength
(x)+1E
: the number of edgesfrom
: the leaving node (1..N
)for each edgelabel
: the set of values of thex
variable for each edgeto
: the entering node for each edge, where 0 = T node
Requires that x
defines a path from root to true node T through the (nondeterministic) MDD defined by
The MDD can be nondeterministic, i.e., there can be two edges with the same label leaving the same node.
Parameters:
N
: the number of nodes, the root node is node 1level
: the level of each node, the root is level 1, T is levellength
(x)+1E
: the number of edgesfrom
: the leaving node (1..N
)for each edgelabel
: the set of values of thex
variable for each edgeto
: the entering node for each edge, where 0 = T node
The sequence of values in array x
(which must all be in the range 1.. S
)
is accepted by the DFA of Q
states with input 1.. S
and transition
function d
(which maps (1.. Q
, 1.. S
) -> 0.. Q
)) and initial state q0
(which must be in 1.. Q
) and accepting states F
(which all must be in
1.. Q
). We reserve state 0 to be an always failing state.
The sequence of values in array x
(which must all be in the set S
)
is accepted by the DFA of Q
states with input S
and transition
function d
(which maps (1.. Q
, S
) -> 0.. Q
)) and initial state q0
(which must be in 1.. Q
) and accepting states F
(which all must be in
1.. Q
). We reserve state 0 to be an always failing state.
The sequence of values in array x
is accepted by the regular
expression r
. This constraint generates it’s DFA equivalent.
Regular expressions can use the following syntax:
Selection:
Concatenation: “12 34”, 12 followed by 34. (Characters are assumed to be the part of the same number unless split by syntax or whitespace.)
Union: “7|11”, a 7 or 11.
Groups: “7(6|8)”, a 7 followed by a 6 or an 8.
Wildcard: “.”, any value within the domain.
Classes: “[3-6 7]”, a 3,4,5,6, or 7.
Negated classes: “[^3 5]”, any value within the domain except for a 3 or a 5.
Quantifiers:
Asterisk: “12*”, 0 or more times a 12.
Question mark: “5?”, 0 or 1 times a 5. (optional)
Plus sign: “42+”, 1 or more time a 42.
Exact: “1{3}”, exactly 3 times a 1.
At least: “9{5,}”, 5 or more times a 9.
Between: “7{3,5}”, at least 3 times, but at most 5 times a 7.
Members of enumerated types can be used in place of any integer (e.g., “A B”, A followed by B). Enumerated identifiers still use whitespace for concatenation.
The sequence of values in array x
(which must all be in the range 1.. S
)
is accepted by the NFA of Q
states with input 1.. S
and transition
function d
(which maps (1.. Q
, 1.. S
) -> set of 1.. Q
)) and initial state q0
(which must be in 1.. Q
) and accepting states F
(which all must be in
1.. Q
).
The sequence of values in array x
(which must all be in the range S
)
is accepted by the NFA of Q
states with input S
and transition
function d
(which maps (1.. Q
, S
) -> set of 1.. Q
)) and initial state q0
(which must be in 1.. Q
) and accepting states F
(which all must be in
1.. Q
).
Represents the constraint x
in t
where we
consider each row in t
to be a tuple and t
as a set of tuples.
Represents the constraint x
in t
where we
consider each row in t
to be a tuple and t
as a set of tuples.
4.2.1.10. Machine learning constraints¶
predicate neural_net(array [int] of var float: inputs,
array [int] of int: input_ids,
array [int] of var float: outputs,
array [int] of int: output_ids,
array [int] of float: bias,
array [int] of float: edge_weight,
array [int] of int: edge_parent,
array [int] of int: first_edge,
NEURON_TYPE: neuron_type)
constrain the output layer of a neural net to take the value defined by the input layer.
the arguments are
inputs
: an array of float variables
input_ids
: array[int] of node
outputs
: an array of float variables
output_ids
: array[int] of node
bias
: array[node] of float
edge_weight
: array[edge] of float (dummy one at end!)
edge_parent
: array[edge] of neuron (start neuron for edge)
first_edge
: array[node] of 1..m+1
neuron_type
: { NT_RELU, NT_STEP, NT_LINEAR, NT_SOFTPLUS }
4.2.1.11. Deprecated constraints¶
Requires at least n
variables in x
to take the value v
.
This constraint is deprecated. Use count(i in x)(i=v) >= n instead.
Requires at most n
variables in x
to take the value v
.
This constraint is deprecated. Use count(i in x)(i=v) <= n instead.
Requires exactly n
variables in x
to take the value v
.
This constraint is deprecated. Use count(i in x)(i=v) = n instead.
4.2.1.12. Other declarations¶
Returns the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Returns the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Returns the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Returns the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Returns the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Returns the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Constrains the elements of x
to define a circuit where x
[ i
] = j
means
that j
is the successor of i
.
Requires that sets s1
and s2
do not intersect.
Constrains m
to be the maximum of the values in x
.
Assumptions: | x
| > 0.
Constrains m
to be the maximum of the values in x
.
Assumptions: | x
| > 0.
Constrain i
to be the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Constrain i
to be the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Constrain i
to be the index of the maximum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Requires that y
occurs in the array x
.
Requires that y
occurs in the array x
.
Requires that y
occurs in the array x
.
Requires that y
occurs in the array x
.
Requires that y
occurs in the set x
.
Constrains m
to be the minimum of the values in x
.
Assumptions: | x
| > 0.
Constrains m
to be the minimum of the values in x
.
Assumptions: | x
| > 0.
Constrain i
to be the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Constrain i
to be the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Constrain i
to be the index of the minimum value in the array x
.
When breaking ties the least index is returned.
Assumption: | x
| > 0
Defines a network flow constraint.
Parameters:
arc
: a directed arc of the flow network. Arci
connects nodearc
[i
,1] to nodearc
[i
,2].balance
: the difference between input and output flow for each node.flow
: the flow going through each arc.
Defines a network flow constraint with cost.
Parameters:
arc
: a directed arc of the flow network. Arci
connects nodearc
[i
,1] to nodearc
[i
,2].balance
: the difference between input and output flow for each node.weight
: the unit cost of the flow through the arc.flow
: the flow going through each arc.cost
: the overall cost of the flow.
Constrains the sets in array S
to partition the universe
.
Return a piecewise-linear interpolation
of the given point sequence as a function of x
Constrains y
( x
) to be a piecewise-linear interpolation of
the provided point sequence.
Requires that the image of function x
(represented as an array) on set
of values s
is t
. ub( s
) must be a subset of index_set( x
) otherwise an
assertion failure will occur.
Returns the image of function x
(represented as an array) on set
of values s
. ub( s
) must be a subset of index_set( x
) otherwise an
assertion failure will occur.
Requires that x
[ i
] in t
for all i
in s
Returns s
such that x
[ i
] in t
for all i
in s
Requires that in each subsequence vs
[ i
], …, vs
[ i
+ seq
- 1] the sum of the
values belongs to the interval [ low
, up
].
Constrains the elements of x
to define a subcircuit where x
[ i
] = j
means that j
is the successor of i
and x
[ i
] = i
means that i
is not in the circuit.
Requires that the sum of cs
[ i1
].. cs
[ iN
] equals s
,
where i1
.. iN
are the elements of the i
th set in sets
.
Nb: not called ‘sum’ as in the constraints catalog because ‘sum’ is a MiniZinc built-in function.
Requires that the sum of the weights ws
[ i1
].. ws
[ iN
] equals s
,
where vs
[ i1
].. vs
[ iN
] are the elements appearing in set x