Skip to content

Commit

Permalink
Fix translation of search annotations with multi-dimensional arrays a…
Browse files Browse the repository at this point in the history
…s arguments. Fixes #750.
  • Loading branch information
guidotack committed Nov 22, 2023
1 parent e733a8d commit 7f2db4c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Bug fixes:
of optional values (:bugref:`752`).
- Fix incorrect ``false`` values for ``has_output_item`` when running with
``--model-interface-only``
- Fix translation of search annotations with multi-dimensional arrays as arguments
(:bugref:`750`).

Changes:
^^^^^^^^
Expand Down
5 changes: 2 additions & 3 deletions share/minizinc/std/nosets.mzn
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,12 @@ predicate array_set_element(var int: x, array[int] of set of int: y, var set of
endif
);

annotation set_search(array[$X] of var set of int: x, ann: a1, ann: a2, ann: a3) =
annotation set_search(array[int] of var set of int: x, ann: a1, ann: a2, ann: a3) =
let {
array[int] of var set of int: xx = array1d(x);
ann: cc = if a2 == indomain_min then indomain_max
elseif a2 == indomain_max then indomain_min
else a2 endif;
} in seq_search([bool_search(set2bools(xx[i]), a1, cc, a3) | i in index_set(xx)]);
} in seq_search([bool_search(set2bools(x[i]), a1, cc, a3) | i in index_set(x)]);

annotation warm_start( array[int] of var set of int: x, array[int] of set of int: v ) =
warm_start_array( [
Expand Down
34 changes: 30 additions & 4 deletions share/minizinc/std/stdlib/stdlib_ann.mzn
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ annotation bounds;
/** @group stdlib.annotations.search Sequentially perform the searches specified in array \a s */
annotation seq_search(array[int] of ann: s);

annotation int_search(
array[int] of var int: x,
ann: select,
ann: choice,
ann: explore,
);
/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, value choice strategy \a choice, and exploration strategy
\a explore. If \a x is a multi-dimensional array, it is coerced to one-dimensional
Expand All @@ -183,7 +189,7 @@ annotation int_search(
ann: select,
ann: choice,
ann: explore,
);
) = int_search(array1d(x), select, choice, explore);

/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, and value choice strategy \a choice.
Expand Down Expand Up @@ -214,6 +220,13 @@ annotation int_search(array[$X] of var opt int: x, ann: select, ann: choice, ann
annotation int_search(array[$X] of var opt int: x, ann: select, ann: choice) =
int_search([if occurs(xi) then deopt(xi) else 0 endif | xi in x],select,choice);


annotation bool_search(
array[int] of var bool: x,
ann: select,
ann: choice,
ann: explore
);
/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, value choice strategy \a choice, and exploration strategy
\a explore.
Expand All @@ -225,7 +238,7 @@ annotation bool_search(
ann: select,
ann: choice,
ann: explore
);
) = bool_search(array1d(x), select, choice, explore);

/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, and value choice strategy \a choice.
Expand Down Expand Up @@ -257,6 +270,13 @@ annotation bool_search(array[$X] of var opt bool: x, ann: select, ann: choice, a
annotation bool_search(array[$X] of var opt bool: x, ann: select, ann: choice) =
bool_search([if occurs(xi) then deopt(xi) else false endif | xi in x],select,choice);

annotation float_search(
array[int] of var float: x,
float: prec,
ann: select,
ann: choice,
ann: explore
);
/** @group stdlib.annotations.search Specify search on variables \a x,
with precision \a prec, variable selection
strategy \a select, value choice strategy \a choice, and exploration strategy
Expand All @@ -270,7 +290,7 @@ annotation float_search(
ann: select,
ann: choice,
ann: explore
);
) = float_search(array1d(x), prec, select, choice, explore);

/** @group stdlib.annotations.search Specify search on variables \a x,
with precision \a prec, variable selection
Expand Down Expand Up @@ -306,6 +326,12 @@ annotation float_search(array[$X] of var opt float: x, float: prec, ann: select,
annotation float_search(array[$X] of var opt float: x, float: prec, ann: select, ann: choice) =
float_search([if occurs(xi) then deopt(xi) else 0.0 endif | xi in x],prec,select,choice);

annotation set_search(
array[int] of var set of int: x,
ann: select,
ann: choice,
ann: explore
);
/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, value choice strategy \a choice, and exploration strategy
\a explore.
Expand All @@ -317,7 +343,7 @@ annotation set_search(
ann: select,
ann: choice,
ann: explore
);
) = set_search(array1d(x), select, choice, explore);

/** @group stdlib.annotations.search Specify search on variables \a x, with variable selection
strategy \a select, and value choice strategy \a choice.
Expand Down

0 comments on commit 7f2db4c

Please sign in to comment.