Very cool. I see this post is trending now on Reddit-Programming: https://redd.it/5h1xgq There is a comment there mentioning MS-OML. Just for the sake of comparison i give their code that solves the problem. I wonder if we can learn anything form it.
Model
[
Parameters[Sets,I,J],
Parameters[Integers,d[I,J]],
Decisions[Integers[1,9],x[I,J]],
Constraints
[
FilteredForeach[{i,I},{j,J},d[i,j]>0,x[i,j]==d[i,j]],
Foreach
[{i,I},Unequal[Foreach[{j,J},x[i,j]]]],
Foreach
[{j,J},Unequal[Foreach[{i,I},x[i,j]]]],
Foreach
[{ib,3},
Foreach
[{jb,3},
Unequal[Foreach[{i,ib*3,ib*3+3},{j,jb*3,jb*3+3},x[i,j]
]
]
]
]
]
]