/* Here we create the constraints for the "backward diagonals" where
 * we move along the first row.
 *   ie. x_1,j + the sum of x_1+m,j-m <= 1 for all j=1,...,n.
 */
double[][] rowBackwardConstraintsMatrix = new double[n][n*n];
for (int row = 0; row < n; row++) {
    for (int column = row; column < n*row + 1; column += (n-1)) {
        rowBackwardConstraintsMatrix[row][column] = 1;
    }
}

for (double[] row : rowBackwardConstraintsMatrix) {
    lp.addConstraint(new LinearSmallerThanEqualsConstraint(row, 1, ""));
}