Hello all,
Tried with this approach but the generated array doesn’t have the bits connected to each other.
Can someone help with how we can enforce the constraint of the set bits to be connected to each other in either adjacent row, col or diagonal elements.
Also, not sure if the additional constraints for the row=0,col=0 row= N-1 and col= N-1 cases are needed or can be further optimized.
class abc#(int N=9);
rand bit arr\[N\]\[N\];
rand int row_sum\[N\];
constraint sum_arr_c {
//constraints for total number of set bits
foreach(arr[i]) {
arr[i].sum() with (int'(item)) == row_sum[i];
}
row_sum.sum() with (int'(item)) == 9;
//constraints for the set bits to be adjacent col,row,or diagonal
foreach(arr[i,j]) {
if(arr[i][j]) {
if((i>0) & (j>0) & (i< N-2) & (j<N-2)) {
(arr[i+1][j] ==1) ||(arr[i+1][j+1] ==1) ||(arr[i+1][j-1] ==1) ||
(arr[i-1][j] ==1) ||(arr[i-1][j+1] ==1) ||(arr[i-1][j-1] ==1) ||
(arr[i][j+1] ==1) ||(arr[i][j-1] ==1);
}
}
}
/*if(i==0) {
if(arr[i][j]) {
(arr[i+1][j] ==1) ||(arr[i+1][j+1] ==1) ||(arr[i+1][j-1] ==1) || (arr[i][j+1] ==1) ||(arr[i][j-1] ==1);
}
}
if(i==N-1) {
if(arr[i][j]) {
(arr[i-1][j] ==1) ||(arr[i-1][j+1] ==1) ||(arr[i-1][j-1] ==1) || (arr[i][j+1] ==1) ||(arr[i][j-1] ==1);
}
}
if(j==0) {
if(arr[i][j]) {
(arr[i+1][j] ==1) ||(arr[i+1][j+1] ==1) ||
(arr[i-1][j] ==1) ||(arr[i-1][j+1] ==1) ||
(arr[i][j+1] ==1) ;
}
}
if(j==N-1) {
if(arr[i][j]) {
(arr[i+1][j] ==1) ||(arr[i+1][j-1] ==1) ||
(arr[i-1][j] ==1) ||(arr[i-1][j-1] ==1) ||
(arr[i][j-1] ==1) ;
}
}*/
}
endclass
module tb();
abc abc_i;
initial begin
abc_i = new();
abc_i.randomize();
foreach(abc_i.arr\[i\])
$display(“%p”,abc_i.arr\[i\]);
end
endmodule