I have also tried not to use the soft constraint. It makes no difference.
When I replace the function call in the constraint with the actual expression which calculates the lem in the function, everything works correctly. len also prints correctly from the function.
Either the value returned is not the correct calculated value or the constraint does not record the correct value which is returned.
“Random variables used as function arguments shall establish an implicit variable ordering or priority. Constraints that include only variables with higher priority are solved before other, lower priority constraints. Random variables solved as part of a higher priority set of constraints become state variables to the remaining set of constraints.”
For example:
class B;
rand int x, y;
constraint C { x <= F(y); }
constraint D { y inside { 2, 4, 8 } ; }
endclass
Did you figure out what was wrong in your code?
Just curious.
There was not enough of the class given for me to determine if Ben’s reply was applicable in your case (since you said that the function, which would be solved first, did indeed print correct (non 1?) values).
Or perhaps I didn’t get Ben’s explanation.
I have a constraint like this:
constraint constraint_len {
soft len == calculate_len(x);
}
x is itself a local constrained random variable.
The function “calculate_len” seems to calculate the correct length and returns it, but “len” is always coming up to be a 1.
Any hints on what may be going wrong?
Please post more code to see what is real problem. You are using soft contraint, please make sure len variable aren’t being contrainted somewhere-else in child class.
I have a constraint like this:
constraint constraint_len {
soft len == calculate_len(x);
}
x is itself a local constrained random variable.
The function “calculate_len” seems to calculate the correct length and returns it, but “len” is always coming up to be a 1.
Any hints on what may be going wrong?
Please check with giving return value and return type for function calculate_len().
It will work!