When I run this constraint in the simulator, I see this line is
s1 -> e1[1]==1 && e1[2]==1 && e1[3]==1 && e1[4]==1 && e1[5]==1 && e1[6]==1 && e1[7]==1;
ignored. Why?
class TransactionIn ;
//-------------------The random variables
rand bit e1[30];
rand bit s1,s2;
//--------------------------------------
constraint totall{
s1 dist {0:/30, 1:/70};
s2 == !s1;
s1 -> e1[1]==1 && e1[2]==1 && e1[3]==1 && e1[4]==1 && e1[5]==1 && e1[6]==1 && e1[7]==1;
e1[1]==0;
}
endclass:TransactionIn
module tb;
TransactionIn a;
initial begin
a = new();
repeat(20)
begin
assert(a.randomize());
$display("%p", a.e1);
en
end
endmodule
output:
'{0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}
'{1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0}
'{1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1}
'{1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1}
'{1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1}
'{0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0}
'{0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1}
'{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1,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 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0}
'{1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0}
In reply to Moein75:
In 4th condition you have provided e1[1] == 0
Whereas in 3rd condition you have provided if s1 == 1 then e1[1] == 1
So it will consider 4th condition and generate e1[1] = 0 and accordingly it will generate s1 =0 and s2 =1
That’s why 3rd condition is ignored…
you can remove 4th condition in the constraint and check again
In reply to Naresh Kumar Koppala:
Hi Sir,
I have a few doubts about this.
First, how come it is getting us any answer? There is a clear conflict in the constraint. So when the value of s1 is 1, we should get an error or at least a warning.
The second one is regarding the usage of dist. According to that, the appearance of s1 having value 1 should be frequent.
How does everything actually work?
In reply to Shubhabrata:
It is not a conflict. Section 18.5.3 says
Absent any other constraints, the probability that the expression matches any value in the list is proportional to its specified weight. If there are constraints on some expressions that cause the distribution weights on these expressions to be not satisfiable, implementations are only required to satisfy the constraints. An exception to this rule is a weight of zero, which is treated as a constraint.
Note that the next revision of the LRM has clarified this paragraph to say
Distribution weights can be used to cause selected corner cases to occur more frequently than they would otherwise. However, nonzero distribution weights do not change the solution space and, therefore, cannot cause the solver to fail. If there are constraints that cause the distribution weights on some expressions to be unsatisfiable, implementations are only required to satisfy the constraints. The exceptions to this rule are values not specified by the distribution and values specified with a total weight of zero, both of which shall be treated as a constraint that the expression not have such values.
In reply to dave_59:
Thank you so much. Understood the concept.