However one limitation is that there is no constraint to ensure that there is at least one occurrence of each of 1,3 and 5.
Eg: One possible output is '{'h3, 'h3, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5}
I then tried using sum() constraint
// Instead of constraint 'element_value'
constraint element_value_using_sum {
arr.sum() with ( int'(item==1) ) + arr.sum() with ( int'(item==3) )
+ arr.sum() with ( int'(item==5) ) == arr.size() ;
}
However this too has the similar limitation as above
[Q1] Is it possible to constraint the elements within values 1,3 and 5 as well as constraint at least one occurrence of each value, using a single constraint expression ?
Q2] If I were to remove the constraint-guard ( if( q.size() != 0 ) ) , during the 1st call to randomize, would the constraint !( a inside { q } ) have any side-effects ( since the queue is empty ) ?
Thanks Dave, for the alternative solution to achieve ascending order elements
( another solution is using simple foreach ).
[Q1] Is it possible to constraint the elements within values 1,3 and 5 as well as constraint at least one occurrence of each value, using a single constraint expression ?
Using ā&&ā I could achieve it with a single constraint expression.
Would like to hear your thoughts on Q2.
constraint rand_cyclic { !( a inside { q } ); } // What if queue is empty ?
During the 1st call to randomize() is there any possible side-effect ? ( as the queue is empty during the 1st call to randomize() ) Does there essentially exist any constraint when the queue is empty ?