this repo has no description
1include "arg_sort_int.mzn";
2include "arg_sort_float.mzn";
3include "analyse_all_different.mzn";
4
5/** @group globals.sort
6Returns the permutation \a p which causes \a x to be in sorted order hence
7\a x[\a p[\p i]] <= \a x[\a p[\p i+1]].
8
9The permutation is the stable sort hence \a x[\a p[\p i]] = \a x[\a p[\p i+1]] \(\rightarrow\) \a p[\p i] < \a p[\p i+1].
10*/
11function array[int] of var int: arg_sort(array[int] of var int:x) :: promise_total =
12 if length(x) = 0 then []
13 else
14 let { int: l = min(index_set(x));
15 int: u = max(index_set(x));
16 array[1..u-l+1] of var l..u: p;
17 constraint analyse_all_different(p);
18 constraint arg_sort_int(x,p); }
19 in p
20 endif;
21
22
23/** @group globals.sort
24Returns the permutation \a p which causes \a x to be in sorted order hence
25\a x[\a p[\p i]] <= \a x[\a p[\p i+1]].
26
27The permutation is the stable sort hence \a x[\a p[\p i]] = \a x[\a p[\p i+1]] \(\rightarrow\) \a p[\p i] < \a p[\p i+1].
28*/
29function array[int] of var int: arg_sort(array[int] of var float:x) :: promise_total =
30 if length(x) = 0 then []
31 else
32 let { int: l = min(index_set(x));
33 int: u = max(index_set(x));
34 array[1..u-l+1] of var l..u: p;
35 constraint analyse_all_different(p);
36 constraint arg_sort_float(x,p); }
37 in p
38 endif;
39
40/** @group globals.sort
41Constrains \a p to be the permutation which causes \a x to be in sorted order hence
42\a x[\a p[\p i]] <= \a x[\a p[\p i+1]].
43
44The permutation is the stable sort hence \a x[\a p[\p i]] = \a x[\a p[\p i+1]] \(\rightarrow\) \a p[\p i] < \a p[\p i+1].
45*/
46predicate arg_sort(array[int] of var int:x,
47 array[int] of var int:p) = fzn_arg_sort_int(x,p);
48
49/** @group globals.sort
50Constrains \a p to be the permutation which causes \a x to be in sorted order hence
51\a x[\a p[\p i]] <= \a x[\a p[\p i+1]].
52
53The permutation is the stable sort hence \a x[\a p[\p i]] = \a x[\a p[\p i+1]] \(\rightarrow\) \a p[\p i] < \a p[\p i+1].
54*/
55predicate arg_sort(array[int] of var float:x,
56 array[int] of var int:p) = arg_sort_float(x,p);