Fixed bugs in affinity constraints.