8

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");
hakank
  • 934
  • 6
  • 15
Eugene
  • 183
  • 5
  • 1
    Maybe it's just because you are passing two arguments to assert. Check Predicate – EhsanK Oct 25 '19 at 18:19
  • 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)'` – Eugene Oct 25 '19 at 20:16

1 Answers1

6

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"
     );
hakank
  • 934
  • 6
  • 15
  • Any reason you don’t do the forall inside the assert? Would that also result in var bool? – Eugene Oct 26 '19 at 01:14
  • 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. – hakank Oct 27 '19 at 17:35