Hi,
I want to constrain a dynamic array in a certain range, AND, the later elements should be greater than the previous one. I do not know how to constrain the incrementing part. The incremental value is not a fixed value. I cannot use ts[i] >ts[i-1]
rand int ts ;
constraint pyld {
foreach (ts[i]) ts[i] inside {[0: 1024]};
}
thanks
The easiest thing would be to sort the array in post_randomize()
function void post_randomize()
ts.sort();
endfunction
But if you have other constraints that depend on having the array in the correct order, you will have to put your constraint within the foreach
constraint pyld {
foreach (ts[i]) {
ts[i] inside {[0: 1024]};
i>0 -> ts[i] >ts[i-1];
}
In reply to dave_59:
Hi Dave,
Thanks for your suggestion, do you know where I can find those build in functions such as sort()
After I take a look on other topics in the forum, below is my implementation, it seems to work.
foreach (ts[i])
foreach (ts[j])
if (i<j) ts[i] <ts[j];
In reply to zhangjintmru:
The sort() method is defined in section 7.12.2 Array ordering methods of the LRM. You can get a copy here.
Although your implementation works, it has unnecessary constraints. If you have ts[0] < ts[1] AND ts[1] < ts[2], then it follows that ts[0] < ts[2]
In reply to dave_59:
Hi Dave,
It looks like those unnecessary constraints make the run slower, with your suggested one, it runs a lot faster.
Thanks