I have a 2d grid where certain cell values produce different scores, and I want to maximize the score by assigning values to cells. Is it possible to trace each grid the solver tried during the solve? Below is a snippet of the model just to demonstrate the idea.
int: i_count;
int: e_count;
set of 1..3: ROW;
set of 1..3: COL;
enum CELL = { U, I, E };
array[ROW,COL] of var CELL: grid;
constraint sum(r in ROW, c in COL)(grid[r, c] = I) <= i_count;
constraint sum(r in ROW, c in COL)(grid[r, c] = E) <= e_count;
var int: assignment_gain = sum(r in ROW, c in COL)(
let {var CELL: cell = grid[r,c]} in (cell = I) * I_SCORE + (cell = E) * E_SCORE
);
solve maximize assignment_gain;
output
["Max assignment_gain: \(assignment_gain), with below grid:\n"] ++
["\(grid[r,c])" ++ if c = n then "\n" else "" endif
| r in ROW, c in COL];
I tried putting trace
into the assignment_gain
statement like below, but didn't work, the output sample is:
grid[1,1]=X_INTRODUCED_0_, grid[1,2]=X_INTRODUCED_1_, ...
var int: assignment_gain = sum(r in ROW, c in COL)(
let {var CELL: cell = trace("grid[\(r),\(c)]=\(grid[r,c]), ", grid[r,c])} in (cell = I) * I_SCORE + (cell = E) * E_SCORE
);