Randomization result with and without (solve x before y)

You are correct in quoting the fact that the solve x before y constraint has no effect on the set of available solutions, it only affects the distribution of values chosen. The way the constraint solver effectively works is that is constructs the entire set of solutions involving all variables first, then randomly picks one of those solutions, with each solution having uniform probability of being picked.

Using pkt_constraint1 as an example, there are the following solution sets

SHORT, 0
SHORT, 1
SHORT, 2
SHORT, 3
SHORT, 4
MED, 5
MED, 6
MED, 7
MED, 8
MED, 9
LONG,10
LONG,11

LONG,4294967294
LONG,4294967295

So there are 4294967295 possible solutions, but only 5 of them have kind==SHORT and 5 have lind=MED. So the probability of picking a value for kind other than LONG is 10/4294967295 , a very slim chance.

What solve kind before len pkt_constraint2 does do is instead of picking one of the 4294967295 solutions randomly, it will pick a value for kind uniformly out of the 3 possible values from the solution set, and then pick a value for len uniformly from the remaining valid values. So the probability of picking (SHORT, 0) is now 1/(3*5) = 1/15.
This constraint should really be thought of as a “choose x before y” directive rather than a constraint.

3 Likes