Hello All,
I want to write constraint expression for a 2 Dimensional Bounded Queue or Dynamic Array.
For Ex: I have this:
int data[$:9][] ;
I want to constrain the first dimension to 9 and then constrain the 2nd dimension to be within 64.
Thanks,
PMD
In reply to pranesh_md:
What have you tried so far? You can constrain the size of a dynamic array with the size() function. I have not tried this with a bounded queue, or a slice of a 2D array.
A 2D array is really just an array of arrays. Use a foreach to walk through the queue elements and constrain the size of each of the dynamic arrays.
In reply to chrisspear:
Constraints treat queues, bounded queues and dynamic arrays all the same—it will not change the size of an array unless there is a constraint on the size() method of that particular dimension.
rand int data[$:9][] ;
constraint c_size_D1 { data.size() = 9; }
constraint c_size_D2 { foreach (data*) data[i].size() <= 64; }
As this is an array of arrays, the dynamic array size of each queue element could be different([i]irregular*). If you want this to be a regular array, you need to introduce another random variable for that size.
rand int data[$:9][] ;
rand int size_D2 ;
constraint c_size_D1 { data.size() = 9 ; }
constraint c_size_D2 { size_D2 <= 64 ;
foreach (data[i]) data[i].size() == size_D2 ; }
I was a bit confused since this is an Queue of Dynamic Array.
So had conflicting thoughts how to constrain it.
I have thought something like this …
define MAX_VALUE 9
define MAX_WIDTH 64
rand int data[$:9][] ;
constraint data_size { data.size() == `MAX_VALUES ;}
constraint data_values_c {
( foreach(data[i])
{ foreach(data[j])
{ data[i][j] == `MAX_WIDTH } ;
) ;
}
Need to try this approach.
In reply to pranesh_md:
Try multiple styles. This easily fits in a 30-line example. Print the resulting array with %p, or create a more elaborate function to make it pretty.