Given a NxN matrix, write a constraint to make sure only one row has 1 and only one col has 1. I think the first two constraints will unroll foreach such that all rows will have atleast one 1’s and all columns will have atleast one 1’s. Is this correct understanding?
The item1 & item2 constraints will unroll in such a way that arr[0][0] + arr[0][1] + … arr[3][3] == 2; This doesn’t guarantee that only one row will have 1 and only columns will have 1. How do we constriant for this case?
class test;
rand bit arr[3][3];
// you need to one in a row, one in a col.
constraint ab_c {
foreach (arr[i,j])
{
arr[i].sum(item) with (int'(item)) == 1;
arr.sum(item) with (int'(arr[item.index][i])) == 1;
}
arr.sum(item1) with (int'(item1.sum(item2) with (int'(item2)))) == 2;
}
endclass