Hi All,
There exist 2 arrays :: array1 of size 5 and array2 of size 100.
Intention is to write a constraint such that all 5 elements of array1 exist within array2 such that they don’t occupy consecutive indexes in array2.
I am trying a solution using a helper array of size 5 whose elements are valid indexes in array2 with the constraint that elements of the helper array are not consecutive values.
The constraint for the helper array is that no elements have a difference of 1.
Eg: helper_array1 = '{ 0 , 5 , 1 , 10 , 7 } would be illegal as index 0 and 2 have elements with a difference of 1
I tried using array reduction or() ::
class C;
rand bit[3:0] val[];
constraint SIZE { val.size() == 5 ; }
constraint VAL {
foreach(val[i])
{
val.or() with ( (item.index != i ) ? ( ( item > val[i] ) ? int'( item - val[i] ) : int'( val[i] - item ) ) : 0 ) > 1 ;
}
}
constraint UNIQ { unique { val } ; }
endclass
C c1 = new();
initial begin
repeat(10) begin
if( c1.randomize() )
$display("Success with %0p",c1);
end
end
However I do see indexes with elements having a difference of 1, any suggestions where I am falling short ?