I’m trying to solve Einstein’s riddle using system verilog constraints
Here I see that all the constraints I have written in einsten_constraints & einsten_constraint_problem are being followed but randc declaration in einsten_constraints isn’t being followed its repeating because only member elements are treated as randc.
typedef enum int { red, green, white, yellow, blue } color_e;
...
class einsten_constraints;
randc color_e color;
...
constraint c1 ..
..
function void display();
..
endclass
class einsten_constraint_problem;
rand einsten_constraints ex[5];
function new();
...
constraint c4 { foreach(ex[i])
if(i>0)
(ex[i].color == color_e'(white)) <-> (ex[i-1].color == color_e'(green));
}
function void display();
..
endclass
program automatic top;
einsten_constraint_problem ex_super;
initial
begin
ex_super = new();
if(ex_super.randomize())
begin
$display("randomization succesful");
...
end
end
endprogram
If i try to use below code in einsten_constraint_problem then its randomizing second time & constraints declared in einsten_constraint_problem wont be followed.
If i dont want to use 2 foreach loops and check all possible ways for uniqueness, is there a way to solve this using randc
....
einsten_constraints ex[5];
.....
function void pre_randomize();
foreach(ex[i])
begin
if(!(ex_c.randomize()))
begin
ex[i] = ex_c ;
end
end
endfunction
...