this repo has no description
1% This file contains redefinitions of standard builtins for version 2.1.1
2% that can be overridden by solvers.
3
4/***
5 @groupdef flatzinc.twooneone FlatZinc builtins added in MiniZinc 2.1.1.
6
7 These functions and predicates define built-in operations of the MiniZinc language
8 that have been added in MiniZinc 2.1.1. Solvers that support these natively need
9 to include a file called redefinitions-2.1.1.mzn in their solver library that
10 redefines these predicates as builtins.
11
12*/
13
14/** @group flatzinc.twooneone Returns variable constrained to be equal to the minimum of the set \a s.
15 An alternative implementation can be found in the comments of the source code.
16*/
17
18function var $$E: min(var set of $$E: s) =
19 let { var min(ub(s)) .. max(ub(s)): m =
20 min([ e + (max(ub(s))+1-e)*(1 - (e in s)) | e in ub(s) ]) } in m;
21
22%% The following can be used as an alternative if the solver supports
23%% a FlatZinc builtin set_min:
24
25% predicate set_min(var set of int: s, var int: m);
26%
27% function var $$E: min(var set of $$E: s) =
28% if mzn_in_root_context(s) then min_t(s) else
29% let { constraint card(s) > 0 } in min_mt(s) endif;
30%
31% function var $$E: min_t(var set of $$E: s) ::promise_total =
32% let {
33% var min(ub(s))..max(ub(s)): ms ::is_defined_var;
34% constraint card(s) > 0;
35% constraint set_min(s,ms) ::defines_var(ms);
36% } in ms;
37%
38% function var $$E: min_mt(var set of $$E: s) ::promise_total =
39% let {
40% var set of ub(s) union {1}: x;
41% var bool: b = card(s) > 0;
42% constraint b -> x=s;
43% constraint b \/ 1 in x;
44% } in min_t(x);
45
46/** @group flatzinc.twooneone Returns variable constrained to be equal to the maximum of the set \a s.
47 An alternative implementation can be found in the comments of the source code.
48*/
49function var $$E: max(var set of $$E: s) =
50 let { var min(ub(s)) .. max(ub(s)): m =
51 max([ e + (min(ub(s))-1-e)*(1 - (e in s)) | e in ub(s) ]) } in m;
52
53%% The following can be used as an alternative if the solver supports
54%% a FlatZinc builtin set_max:
55
56% predicate set_max(var set of int: s, var int: m);
57%
58% function var $$E: max(var set of $$E: s) =
59% if mzn_in_root_context(s) then max_t(s) else
60% let { constraint card(s) > 0 } in max_mt(s) endif;
61%
62% function var $$E: max_t(var set of $$E: s) ::promise_total =
63% let {
64% var min(ub(s))..max(ub(s)): ms ::is_defined_var;
65% constraint card(s) > 0;
66% constraint set_max(s,ms) ::defines_var(ms);
67% } in ms;
68%
69% function var $$E: max_mt(var set of $$E: s) ::promise_total =
70% let {
71% var set of ub(s) union {1}: x;
72% var bool: b = card(s) > 0;
73% constraint b -> x=s;
74% constraint b \/ 1 in x;
75% } in max_t(x);