Constraint involving queues and arrays

The code is like below -

module test();
 
class temp;
  int array[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,8};
  rand int q1[$];
  rand int q2[$];
  rand int q3[$];
  
  constraint c1 {
    q1.size == 5;
    q2.size == 5;
    q3.size == 5;
    
    foreach (q1[i]) {
      q1[i] inside {array};
      q2[i] inside {array};
      q3[i] inside {array};
    }
      
    unique {q1,q2};
    unique {q2,q3};
    unique {q3};
  }

endclass
  
initial
begin
      temp t = new();
      t.randomize();
      $display ("%p\n %p\n %p\n", t.q1, t.q2, t.q3);
      $finish;
end
 
endmodule

The current output looks like so -

'{10, 6, 11, 1, 13}
'{4, 2, 5, 3, 12}
'{11, 13, 10, 14, 8}

q1, q2 and q3 are all required to contains elements from array. No element should be shared across q1,q2,q3 unless the element is repeated in the array itself in which case it is fine.
I got as far as getting 2/3 queues unique but q3 would always have elements from q1 or q2. How can I constrain q3 to be '{7, 8, 8, 9, 14} which is all the remaining elements of array not in both q1 and q2.

EDIT: I could do it in post_randomize but is there a way through constraints

In reply to kernalmode1:
What you want is to pick elements of a list, and its the index into the list that needs to be unique. You can extrapolate this to get your three q’s.

module test();
 
class temp;
   int array[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,8};
   rand int idx[15];
   rand int q[15];
   
   constraint c1 {
      foreach (q[i]) {
	 idx[i] inside {[0:14]};
	 q[i] == array[idx[i]];
      }
      unique {idx};
   }
endclass
   initial
     begin
	static temp t = new();
	assert(t.randomize());
	$display ("%p\n %p ", t.idx, t.q);
	$finish;
     end
   
endmodule

In reply to dave_59:

Thank you Dave. Really appreciate you opening my thoughts to this approach.

In reply to kernalmode1:

The code is like below -

module test();
class temp;
int array[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,8};
rand int q1[$];
rand int q2[$];
rand int q3[$];
constraint c1 {
q1.size == 5;
q2.size == 5;
q3.size == 5;
foreach (q1[i]) {
q1[i] inside {array};
q2[i] inside {array};
q3[i] inside {array};
}
unique {q1,q2};
unique {q2,q3};
unique {q3};
}
endclass
initial
begin
temp t = new();
t.randomize();
$display ("%p\n %p\n %p\n", t.q1, t.q2, t.q3);
$finish;
end
endmodule

The current output looks like so -
'{10, 6, 11, 1, 13}
'{4, 2, 5, 3, 12}
'{11, 13, 10, 14, 8}
q1, q2 and q3 are all required to contains elements from array. No element should be shared across q1,q2,q3 unless the element is repeated in the array itself in which case it is fine.
I got as far as getting 2/3 queues unique but q3 would always have elements from q1 or q2. How can I constrain q3 to be '{7, 8, 8, 9, 14} which is all the remaining elements of array not in both q1 and q2.
EDIT: I could do it in post_randomize but is there a way through constraints

Hi, Would you be able to show how you got the 3rd queue to be unique elements in post_randomize?

Thanks.

In reply to kernalmode1:

How you can do that using post randomize can u explain please.

In reply to Yash_wanth12345:

class temp;
  int array[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,8};
  int q1[$];
  int q2[$];
  int q3[$];
function void post_randomize();
   array.shuffle();
   q1 = array[0:4];
   q2 = array[5:9];
   q3 = array[10:14];
endfunction
endclass

In reply to dave_59:

Based on Random_Variables_as_index , isn’t the following Syntax Illegal as per LRM ?? ::


  q[i] == array[idx[i]] ;  

Is there an alternate solution ( without post_randomize() ) ??

In reply to ABD_91:

It’s all legal syntax. The current LRM has a semantic restriction not allowing a random index selecting parts of a random variable. In the example above, array is a state variable and i is an iterative loop variable.

In reply to dave_59:

Hi Dave,

Can you please explain why you took 2 separate arrays as shown below.
rand int idx[15];
rand int q[15];

Can you also please explain what this means : q[i] == array[idx[i]];
Thanks in advance.

I am unable to understand why unique{q3} is not working in the above code.

In reply to sk7799:

idx array will have unique values from 0-14 and then this unique values are used to index into the array to assign it to queues.
idx[i] - will have unique value
array[idx[i]] - in turn will have unique value