Hi,
I am trying to solve below problem.
Need to generate the 2D array with below constraints
- each element can take either 0 or 1
- there would be N(say=2) elements which are not equivalent to it’s 4 neighbors. (top,bottom,left,right)
I am able to generate the 2D array with above constraints except N elements. Instead, I see the result for all the valid elements.
class test;
rand bit a[5][5];
constraint c1 {
foreach(a[i,j]){
i>0 -> a[i][j] != a[i-1][j];
i<3 -> a[i][j] != a[i+1][j];
j>0 -> a[i][j] != a[i][j-1];
j<3 -> a[i][j] != a[i][j+1];
}
}
endclass
module tb;
test t_h;
initial begin
t_h=new;
t_h.randomize;
foreach(t_h.a[i,])
$display("%p",t_h.a[i]);
end
endmodule
current o/p:
'{'h1, 'h0, 'h1, 'h0, 'h1}
'{'h0, 'h1, 'h0, 'h1, 'h0}
'{'h1, 'h0, 'h1, 'h0, 'h1}
'{'h0, 'h1, 'h0, 'h1, 'h0}
'{'h1, 'h0, 'h1, 'h0, 'h1}
expected o/p: where N=2
'{'h1, 'h0, 'h1, 'h0, 'h1}
'{'h0, 'h1, 'h0, 'h0, 'h0}
'{'h1, 'h0, 'h0, 'h0, 'h1}
'{'h0, 'h0, 'h0, 'h1, 'h0}
'{'h1, 'h0, 'h1, 'h0, 'h1}
EDITED:
- fixed the expected output.
- Rule does not apply for the edges.