Skip to content

Commit d34425b

Browse files
committed
Add support for Boolean argmin/argmax to FlatZinc, and perform offset calculation natively rather than through MiniZinc constraints
1 parent daaaa67 commit d34425b

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

changelog.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ Date: 2019-??-??
6868
[DESCRIPTION]
6969
Let's see.
7070

71+
[ENTRY]
72+
Module: flatzinc
73+
What: new
74+
Rank: minor
75+
[DESCRIPTION]
76+
Support minimum_arg_bool and maximum_arg_bool constraints.
77+
78+
[ENTRY]
79+
Module: flatzinc
80+
What: change
81+
Rank: minor
82+
[DESCRIPTION]
83+
Use native offset calculation instead of additional constraints
84+
for argmin/argmax constraints.
85+
7186
[ENTRY]
7287
Module: int
7388
What: new
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
predicate gecode_maximum_arg_bool_offset(array[int] of var bool: x, int: offset, var int: i);
2+
3+
predicate maximum_arg_bool(array[int] of var bool: x, var int: i) =
4+
gecode_maximum_arg_bool_offset(x,min(index_set(x)),i);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
predicate gecode_maximum_arg_int(array[int] of var int: x, var int: i);
1+
predicate gecode_maximum_arg_int_offset(array[int] of var int: x, int: offset, var int: i);
22

33
predicate maximum_arg_int(array[int] of var int: x, var int: i) =
4-
gecode_maximum_arg_int(x,(i-min(index_set(x)))::domain);
4+
gecode_maximum_arg_int_offset(x,min(index_set(x)),i);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
predicate gecode_minimum_arg_bool_offset(array[int] of var bool: x, int: offset, var int: i);
2+
3+
predicate minimum_arg_bool(array[int] of var bool: x, var int: i) =
4+
gecode_minimum_arg_bool_offset(x,min(index_set(x)),i);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
predicate gecode_minimum_arg_int(array[int] of var int: x, var int: i);
1+
predicate gecode_minimum_arg_int_offset(array[int] of var int: x, int: offset, var int: i);
22

33
predicate minimum_arg_int(array[int] of var int: x, var int: i) =
4-
gecode_minimum_arg_int(x,(i-min(index_set(x)))::domain);
4+
gecode_minimum_arg_int_offset(x,min(index_set(x)),i);

gecode/flatzinc/registry.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,26 @@ namespace Gecode { namespace FlatZinc {
10221022

10231023
void p_minimum_arg(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
10241024
IntVarArgs iv = s.arg2intvarargs(ce[0]);
1025-
argmin(s, iv, s.arg2IntVar(ce[1]), true, s.ann2ipl(ann));
1025+
int offset = ce[1]->getInt();
1026+
argmin(s, iv, offset, s.arg2IntVar(ce[2]), true, s.ann2ipl(ann));
10261027
}
10271028

10281029
void p_maximum_arg(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
10291030
IntVarArgs iv = s.arg2intvarargs(ce[0]);
1030-
argmax(s, iv, s.arg2IntVar(ce[1]), true, s.ann2ipl(ann));
1031+
int offset = ce[1]->getInt();
1032+
argmax(s, iv, offset, s.arg2IntVar(ce[2]), true, s.ann2ipl(ann));
1033+
}
1034+
1035+
void p_minimum_arg_bool(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
1036+
BoolVarArgs bv = s.arg2boolvarargs(ce[0]);
1037+
int offset = ce[1]->getInt();
1038+
argmin(s, bv, offset, s.arg2IntVar(ce[2]), true, s.ann2ipl(ann));
1039+
}
1040+
1041+
void p_maximum_arg_bool(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
1042+
BoolVarArgs bv = s.arg2boolvarargs(ce[0]);
1043+
int offset = ce[1]->getInt();
1044+
argmax(s, bv, offset, s.arg2IntVar(ce[2]), true, s.ann2ipl(ann));
10311045
}
10321046

10331047
void p_regular(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
@@ -1562,8 +1576,10 @@ namespace Gecode { namespace FlatZinc {
15621576
&p_global_cardinality_low_up_closed);
15631577
registry().add("array_int_minimum", &p_minimum);
15641578
registry().add("array_int_maximum", &p_maximum);
1565-
registry().add("gecode_minimum_arg_int", &p_minimum_arg);
1566-
registry().add("gecode_maximum_arg_int", &p_maximum_arg);
1579+
registry().add("gecode_minimum_arg_int_offset", &p_minimum_arg);
1580+
registry().add("gecode_maximum_arg_int_offset", &p_maximum_arg);
1581+
registry().add("gecode_minimum_arg_bool_offset", &p_minimum_arg_bool);
1582+
registry().add("gecode_maximum_arg_bool_offset", &p_maximum_arg_bool);
15671583
registry().add("array_int_maximum", &p_maximum);
15681584
registry().add("gecode_regular", &p_regular);
15691585
registry().add("sort", &p_sort);

0 commit comments

Comments
 (0)