A Japanese Sum Sudoku is similar to a Sudoku in that you have to fill a 9x9 grid with the numbers 1-9 in each cell such that in each row, column, and sub-sudoku (3x3 square) each digit occurs exactly once. The catch is that each row and column is annotated with a sequence of numbers (or sometimes also question marks). You then have to color each cell either yellow or gray in such a way, that there are as many yellow connected segments as there are numbers for each row/column and the numbers in each yellow segment have to add up to the specified numbers. An example can be seen here:
https://www.youtube.com/watch?v=oCkWdcFxtFo
I tried to encode this problem in MiniZinc but found it very slow/scaling very badly. In fact, it's running for 12+ hours now for a single instance. I verified it works correctly by testing a smaller (4x4) instance which finishes correctly in 250ms.
I define the following variables:
% the grid plus annotation which are yellow
set of int: SIZE = 0..8;
array[SIZE, SIZE] of var 1..9: grid;
array[SIZE, SIZE] of var 0..1: is_yellow;
% for each yellow segment a start and end point
% e.g. the first segment in the upper (0th) line:
var 0..8: r0start1;
var 0..8: r0end1;
% ... same thing for other segments, rows and columns
and the following constraints:
% start comes before end
constraint r0start1 <= r0end1;
% between one end and the next start there is at least one space
constraint r0end1+1 < r0start2;
% ... same for other segments
% a cell is yellow iff its index lies in between some start-end pair
constraint (is_yellow[0,0]=1) <-> (((r0start1 <= 0 /\ 0 <= r0end1)) \/ ((r0start2 <= 0 /\ 0 <= r0end2)) \/ ((r0start3 <= 0 /\ 0 <= r0end3)));
% ... same for all cells, and the same constraint for columns
and lastly, the usual sudoku constraints via alldifferent.
Here, the question marks denote there has to be a yellow segment but its sum is left open.
What is the main bottleneck of this approach and how may I fix it?