You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing the following example using mzn2fzn will trigger a segfault caused by a stack overflow.
function var int:
ilog2( var int: x ) =
let { constraint x > 0 } in
if x > 1 then
1 + ilog2(x div 2)
else
0
endif
;
var 1..256: x;
var int: y;
constraint( y == ilog2(x) );
solve ::int_search( [x, y], first_fail, indomain_random, complete ) satisfy;
Unfortunately this is the “expected” behaviour here. You can’t do recursion through a variable argument in MiniZinc, since the if condition cannot be evaluated at compile time. MiniZinc should fail with a better error message though, I’ll see if we can implement some check there.
You can often simulate a var function by turning a par function into an array lookup like this:
function int: ilog2(int: x) =
if x > 1 then 1 + ilog2(x div 2)
else 0 endif;
var 1..256: x;
var int: y;
constraint y = [ilog2(i) | i in dom(x)][x];
solve ::int_search( [x, y], first_fail, indomain_random, complete ) satisfy;
output ["x = \(x), y=\(y)\n"];
Thanks, I ended up writing a very very long conditional instead as I need it to work on a large domain. If performance becomes an issue I'll revise the domain and change it to the lookup table you describe.
Parsing the following example using mzn2fzn will trigger a segfault caused by a stack overflow.
Stack trace (with increased stack size):
The text was updated successfully, but these errors were encountered: