Sudoku
OptiMax Sample of Sudoku Application
TITLE
Sudoku;
INDEX
row := 1..9;
coln := row;
num := 1..9;
box := 1..9;
DATA
FixedValues[row,coln] := DATAFILE("sudoku.dat");
BoxAssign[row,coln] := (
1, 1, 1, 2, 2, 2, 3, 3, 3,
1, 1, 1, 2, 2, 2, 3, 3, 3,
1, 1, 1, 2, 2, 2, 3, 3, 3,
4, 4, 4, 5, 5, 5, 6, 6, 6,
4, 4, 4, 5, 5, 5, 6, 6, 6,
4, 4, 4, 5, 5, 5, 6, 6, 6,
7, 7, 7, 8, 8, 8, 9, 9, 9,
7, 7, 7, 8, 8, 8, 9, 9, 9,
7, 7, 7, 8, 8, 8, 9, 9, 9);
INDEX
BoxComp[row,coln,box] WHERE (BoxAssign = box);
BINARY VARIABLES
Assign[row,coln,num];
MODEL
MAX TotalAssign = SUM(row,coln,num: Assign);
SUBJECT TO
SingleCell[row,coln]: SUM(num: Assign) = 1;
SingleRow[row,num]: SUM(coln: Assign) = 1;
SingleCol[coln,num]: SUM(row: Assign) = 1;
SingleBox[box,num]: SUM(row,coln IN BoxComp: Assign) = 1;
FixValue[row,coln,num] WHERE (FixedValues[row,coln] = num):
num*Assign = FixedValues;
END