Constraint number of occurrences in dynamic array

Hi ,

i am trying to restrict the number of occurence of few values in my array?
somehow the constraint with arr.sum() with (item==3) = 3*4 ; does seems to be working. - sim hangs.
what i want to do is
restrict element 3 in array for say 4 times and not more than that.
Can someone help?
i also tried storing it in queue and restricting queue size but it says constraint inconsistency error.

In reply to Blitzz0418:

Assuming you meant to write
arr.sum() with (item==3) == 3*4
, that would be interpreted as there must be exactly 12 elements in arr the element value is 3.

Perhaps you can show some solutions values sets you are looking for.

In reply to dave_59:
sure.
i can have 2, 3, 4, 5 values in an array
i randomized that using
foreach arr[i] arr[i] inside {2,3,4,5}
now i want to have atleast N number of value as 2
for example,
arr can have 4 times 2, 3, 4, 5 value as an element.
what i want to do is restrict the count of 2, 3… to 4 times.
another condition is they should not be consecutive which is fine.
i can add another constraint saying
Arr[i] != Arr[i+1]
but i am not sure how to put constraint on occurrence of a value/or total number of count on how many times the value shall exists in array ?
does that makes sense ?

basically i want to have
Arr = {2,3,4,5,2,4,3,2,3,5,3,2,4,5,4,5,3,4} ; – here i want to limit 2,3,4,5 shall exists atleast 4 times it can be more than that(like 3 and 4 .

In reply to Blitzz0418:

That is a lot more information than your original post. Also, you are contradicting what you said first about not repeatingmore than 4 times, and then later you said repeated at least 4 times. I’m going to assume you meant at least 4 times which means there needs to be a constraint in the minimum size of the array to be 16. You probably should set an upper bound to the array size as well.

class A;
  int N = 4;
  int values[] = {2, 3, 4, 5};
  rand int arr[];
  constraint c {
     arr.size inside {[N*values.size() : 100]};
     foreach(arr[i]) arr[i] inside {values};
     foreach(values[i]) arr.sum() with (int'(item == values[i])) >= N;
  }
endclass

In reply to dave_59:

I tried the similar answer but seems it was giving out constraints inconsistency error for sone reason on edaplayground
let me try with the exact code you gave.
Thank you