In multi-state problems (like colored nonograms or multi-skill scheduling), cells/slots of one state can act as separators for runs of another state.
The Anti-Pattern: Requiring every non-empty cell to belong to a run. This over-constrains the model and causes false UNSAT results because it forbids the 'separator' cells.
The Correct Pattern: Focus ONLY on enforcing the properties of the runs themselves (position, length, color) and let the solver determine the separators naturally.
- Generate Run Positions: Use choice rules to pick starting positions for runs.
- Enforce Run Consistency: Constrain cells within the run to match the required color/state.
- Enforce Ordering: Ensure runs appear in the correct sequence.
- Enforce Separation for Identical States: Only require gaps between runs of the same color/state. Different states/colors are allowed to be adjacent.
Multi-Color Nonogram Pattern:
% 1. Define possible starting positions
{ row_run_pos(R, RunIdx, StartCol) : possible_start(StartCol) } 1 :- row_clue(R, RunIdx, _, _).
% 2. Cells within run must match run's color
:- row_run_pos(R, RunIdx, Start), row_clue(R, RunIdx, ReqColor, Len),
col(C), C >= Start, C < Start + Len,
cell(R, C, ActualColor), ActualColor != ReqColor.
% 3. Runs must appear in order
:- row_run_pos(R, I1, C1), row_run_pos(R, I2, C2),
row_clue(R, I1, _, L1), I2 = I1 + 1, C2 < C1 + L1.
% 4. Runs of SAME color must be separated
:- row_run_pos(R, I1, C1), row_run_pos(R, I2, C2),
row_clue(R, I1, SameColor, L1), row_clue(R, I2, SameColor, _),
I1 < I2, C2 < C1 + L1 + 1.
% Runs of SAME color must be separated (different colors can touch)
:- row_run_pos(R, I1, C1), row_run_pos(R, I2, C2),
row_clue(R, I1, SameColor, L1), row_clue(R, I2, SameColor, _),
I1 < I2, C2 < C1 + L1 + 1.