-
Notifications
You must be signed in to change notification settings - Fork 78
/
arg_min.mzn
47 lines (38 loc) · 1.73 KB
/
arg_min.mzn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** @group globals
Returns the index of the minimum value in the array \a x.
When breaking ties the least index is returned.
*/
function var int: arg_min(array[int] of var int: x) =
let { constraint length(x) > 0; } in arg_min_total(x);
/** @group globals
Returns the index of the minimum value in the array \a x.
When breaking ties the least index is returned.
*/
function var int: arg_min(array[int] of var float: x) =
let { constraint length(x) > 0; } in arg_min_total(x);
function var int: arg_min_total(array[int] of var int: x) :: promise_total =
if length(x) = 0 then 0 else
let { var min(index_set(x)) .. max(index_set(x)): i;
constraint minimum_arg_int(x, i); }
in i endif;
function var int: arg_min_total(array[int] of var float: x) :: promise_total =
if length(x) = 0 then 0 else
let { var min(index_set(x)) .. max(index_set(x)): i;
constraint minimum_arg_float(x, i); }
in i endif;
include "arg_min_int.mzn";
/** @group globals
Constrain \a i to be the index of the minimum value in the array \a x.
When breaking ties the least index is returned.
Assumption: |\a x| > 0
*/
predicate minimum_arg(array[int] of var int: x, var int: i) =
minimum_arg_int(x, i);
include "arg_min_float.mzn";
/** @group globals
Constrain \a i to be the index of the minimum value in the array \a x.
When breaking ties the least index is returned.
Assumption: |\a x| > 0
*/
predicate minimum_arg(array[int] of var float: x, var int: i) =
minimum_arg_float(x, i);