8
$\begingroup$

Trying to use minizinc builtins to do some basic validation of data inputs but I get a type error MiniZinc: type error: no function or predicate with this signature found: 'assert(var bool,string)' Is this because I'm using a predicate and not a function?

include "globals.mzn";
array[1..5] of int: x = 1..5;
constraint assert(increasing(x), "x is not increasing");
$\endgroup$
  • 1
    $\begingroup$ Maybe it's just because you are passing two arguments to assert. Check Predicate $\endgroup$ – EhsanK Oct 25 '19 at 18:19
  • $\begingroup$ Similar error. i think assert needs the first argument to be an expression that evaluates to a regular bool rather than a var bool. MiniZinc: type error: no function or predicate with this signature found: assert(var bool)'` $\endgroup$ – Eugene Oct 25 '19 at 20:16
6
$\begingroup$

assert requires a bool in the test part, and don't support var bool.

A suggestion is to rewrite the increasing constraint to a loop with single asserts with bool expressions. For example:

include "globals.mzn";
int: n = 5;

array[1..n] of 1..n: x = [5,4,3,1,2];

constraint forall(i in 1..n-1) (
   assert(x[i] <= x[i+1], "x is not increasing")
);

solve satisfy;

output[ "\(x)\n"];

This yield the following error:

MiniZinc: evaluation error: 
   /home/hakank/g12/me/assert_test.mzn:31:
   in call 'forall'
   in call 'forall'
   in array comprehension expression
   with i = 1
   /home/hakank/g12/me/assert_test.mzn:32:
   in call 'assert'
   in call 'assert'
   Assertion failed: x is not increasing

Update: Another way is to put the forall inside assert, i.e.

% ...
constraint
    assert(
       forall(i in 1..n-1) (
           assert(x[i] <= x[i+1], "x is not increasing")
       )
       , "x is not increasing"
     );
| improve this answer | |
$\endgroup$
  • $\begingroup$ Any reason you don’t do the forall inside the assert? Would that also result in var bool? $\endgroup$ – Eugene Oct 26 '19 at 1:14
  • $\begingroup$ Sorry, I forgot to answer your question. There are no reason that I prefer assert on each line more that I'm used to it. As you might have seen, I added the alternative approach. $\endgroup$ – hakank Oct 27 '19 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.