In reply to dave_59:
Hi Dave,
Sorry for the delay. And thanks for the quick response.
Here is the sample code…
// Types
typedef enum {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9} type_a;
typedef enum {B0, B1, B2, B3, B4, B5, B6, B7, B8, B9} type_b;
typedef enum {C0, C1, C2, C3, C4, C5, C6, C7, C8, C9} type_c;
// Single element
class myClass;
const type_a a;
const type_b b;
const type_c c;
// Some random variables based on contant fields
rand int ar;
rand int br;
rand int cr;
// Constraints linking constant fields with random variables
constraint dummy_constraint {
if (a == A0) ar == 'd10;
if (b == B1) ar == 'd13;
if (c == C2) ar == 'd20;
}
// Initializes constant fields
function new (type_a a, type_b b, type_c c);
this.a = a;
this.b = b;
this.c = c;
endfunction : new
// Show method
function void show;
$display (a.name, " ", b.name, " ", c.name);
endfunction : show
endclass : myClass
As you see, we can have 10^3 possible combinations for variables a, b & c together, but out of them very few are actually valid, (10 in our case) enumerated below.
// Container of queue
class db_manager;
const local myClass q[$];
local myClass tmp;
function new;
myClass q[$];
tmp = new(A0, B0, C0); q.push_back(tmp);
tmp = new(A1, B2, C1); q.push_back(tmp);
tmp = new(A2, B4, C3); q.push_back(tmp);
tmp = new(A3, B6, C5); q.push_back(tmp);
tmp = new(A4, B8, C7); q.push_back(tmp);
tmp = new(A5, B1, C9); q.push_back(tmp);
tmp = new(A6, B3, C2); q.push_back(tmp);
tmp = new(A7, B5, C4); q.push_back(tmp);
tmp = new(A8, B7, C6); q.push_back(tmp);
tmp = new(A9, B9, C8); q.push_back(tmp);
this.q = q;
endfunction
function show;
foreach (q[i]) q[i].show();
endfunction : show
endclass : db_manager
In my case, its about few thousand valid combinations in a pool of few million possible combinations.
On top of that, I will have few random variables like ‘ar, br & cr’, that depend on ‘a, b & c’, which will have more constraints.
Hence my requirement, to search the queue with given search criteria among constant fields, and then to randomize the random fields.
Please let me know if you need any further inputs.
This time I will respond soon.
Regards,
Krishna