Write constraint for the below requirements :
a. The queue size will be 15. Randomize a queue such that it exactly has four 7 in it.
b. No 7’s should be at the consecutive next to each other
class queue_7;rand bit [3:0] queue[$];
constraint queue_size_c {queue.size() == 15;}
constraint queue_element_c {foreach(queue[i]){if(i >0 && queue[i-1] == 7)queue[i] !=7;}queue.sum with(int’(item ==7)) == 4;}
function void post_randomize();$display(“queue %p”,queue);endfunction
endclass
instead of using array in built function i was thinking to use function
function int unsigned count(bit[3:0] array[$]);
foreach(array[i])
if(array[i] == 7)
count++;
endfunction
constraint queue_element_c {foreach(queue[i]) {if(i >0 && queue[i-1] == 7)
queue[i] !=7;}
count(queue) == 4;}
solver is failing to solve this but in built function it is resolving. Imn trying to understand behind the scene