Constraints for dynamic array

Hello,

Is it possible to write a conditional constraint to fix the size of a dynamic array in the following way?

rand int array[];
     rand bit [3:0]burst;
     constraint C{ (burst== 3)-> array.size == 4;}

I am using questa 10.0b. I am getting the following error when I tried to randomize the object. Randomization is not being successful.

Illegal attempt to resize random dynamic array ‘#var1#.Hwdata’ to 593477299 elements. (SolveArrayResizeMax=2000)

I tried to execute the same snippet in edaplayground.com and I am not getting any error in randomization.

The LRM says that size of the array is randomized as soon as there is a constraint on array.size. It does not mention anything about the effect of an implication.

What you you want to happen to the array size if burst is not equal to 3?

In reply to dave_59:

I should add that an implication does not work like procedural code. The constraint on adder.size is part of the set of constraints, so it becomes a random variable. All constraints are evaluated in parallel to form a solution space, and then the solver randomly picks a single solution. Adding a solve before construct only changes how that solution gets picked.

In reply to dave_59:

Thanks dave…
Myself and Shanthi are working on the same code. It worked by including the condition which is missing (what happens if burst is not equal to 3)

In reply to shanthi:

Just to add some reference of constraints in arrays.
The next article can give you some hints.
http://blog.verificationgentleman.com/2014/07/the-not-so-comprehensive-guide-to.html

e.g. something you can do


rand int some_dynamic_array[];
rand int SECOND_dynamic_array  [];
rand logic size_5_15;//decide the size of the array

//constraint the value of the last element of array
constraint last_elem_c {
  some_dynamic_array[some_dynamic_array.size() - 1] == 5;
}

//constraint the SIZE, as you wanted of the array
constraint size {
  if (size_5_15) {
     some_dynamic_array.size() == 5;//size of 5 elements
  } else {
     some_dynamic_array.size() == 15;//size of 15 elements
  }
}

//Even you can now constraint another array with the values of the previous dynamic array
constraint second_array_can_have_repeated_values_of_first_array_and_val_twenty{
  SECOND_dynamic_array  inside  { some_dynamic_array , 20 };
//notice that in order to solve the SECOND array we need to first randomize the first ARRAY,therefore
  solve some_dynamic_array  before SECOND_dynamic_array;
}