You'd impose the preference order by adding elements to your Objective Function.
Let's say you have variables of the type
choose[row][col][digit]
If choose[2][3][8] = 1 it means that the square (2,3) has the value 8.
The four corners are:
1,1; 1,9;
9,1; 9,9
Essentially, you need to add the following to your existing objective function.
9 x choose[1][1][5] + 8 x choose[1][1][7] + 7 x choose[1][1][4] + ... + 2 x choose[1][1][9] + 1 x choose[1][1][1]
9 x choose[1][9][5] + 8 x choose[1][9][7] + 7 x choose[1][9][4] + ... + 2 x choose[1][9][9] + 1 x choose[1][9][1]
9 x choose[9][1][5] + 8 x choose[9][1][7] + 7 x choose[9][1][4] + ... + 2 x choose[9][1][9] + 1 x choose[9][1][1]
9 x choose[9][9][5] + 8 x choose[9][9][7] + 7 x choose[9][9][4] + ... + 2 x choose[9][1][9] + 1 x choose[9][9][1]
In CPLEX
// Preference order: 5 > 7 > 4 > 6 > 8 > 2 > 3 > 9 > 1
int[] preferenceOrder;
preferenceOrder[1] = 9;
preferenceOrder[2] = 8;
preferenceOrder[8] = 2;
preferenceOrder[9] = 1;
cplex.addMaximize(cplex.scalProd(preferenceOrder, choose));
Why this works?
The CPLEX Solver tries to maximize the value of the obj function. All else being equal, it will first try to make choose[1][1][5]
to be 1, and will next try to make it 7 and so on.