I am trying to generate a dynamic array with elements in the below fashion
if N = 5, elements should be 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Solver is failing to find a solution. Can you help me figure out the issue?
class elements_generation;
parameter N = 5;
rand int dyn_array [];
function int calculate_size(int n);
int size;
for(int i = n; i > 0; i--) begin
size+=i;
end
return size;
endfunction : calculate_size
constraint c_dyn_array {dyn_array.size() == calculate_size(N);}
constraint c_inc_elements {foreach(dyn_array[i]){if(i>0) (dyn_array[i]==dyn_array[i-1]||(dyn_array[i]-dyn_array[i-1]==1));}}
constraint c_elements {foreach(dyn_array[i]) {dyn_array.sum() with (item == i) == i*i};}
endclass : elements_generation
module dyn_array_randomization;
initial begin
elements_generation e_g;
e_g = new();
e_g.randomize();
$display("dyn_array %0p", e_g.dyn_array);
end
endmodule : dyn_array_randomization