Hi all,
I have a predefined array of struts (150 elements), and based on the array I should get another array (or queue) as a result of randomization. Newly created one should be the same type, but should contain less elements, and elements should be picked up from the original array.
Here is simplified pseudocode:
// type
typedef struct {string name;
int param_1;
int param_2;
} traffic_t;
// predefined array
traffic_t trafic[] = '{
'{name_1, num_11, num_12},
'{name_2, num_21, num_22},
'{name_3, num_31, num_32},
'{name_4, num_41, num_42},
//...
'{name_150, num_1501, num_1502}
};
Based on the array I should generate its reduced version, with following constraints:
- it is not said how many elements reduced array should have, and it is should be randomly chosen
- sum of all param_1 fields of newly created array should be == SUM_OF_PARAM_1
- sum of all param_2 fields of newly created array should be <= SUM_OF_PARAM_2
- the same element can appear multiple times in new array
As an example, as a result of randomization new array can contain following elements, if constraints are satisfied:
new_array[] = '{
'{name_3, num_31, num_32},
'{name_19, num_191, num_192},
'{name_3, num_31, num_32},
'{name_120, num_120, num_120}};
I have problem to set proper constraints. I tried with:
rand traffic_t new_array[$];
constraint c1 {
new_array.sum(item) with (int'(item.param_1)) == PARAM_1_RATE;
}
constraint c2 {
new_array.sum(item) with (int'(item.param_2)) <= PARAM_2_RATE;
}
but it doesnt work, because all simulators I tried have tendency to start picking up elements from the beginning, instead of picking up them randomly from original array. In pseudocode I’m getting something like this:
new_array[] = '{
'{name_1, num_11, num_12},
'{name_2, num_21, num_22},
'{name_3, num_31, num_32},
'{name_4, num_41, num_42}};
Does anybody understand why it happens?
Any idea how to set constraints properly?
Thank you
Marko