I'm trying to model a puzzle in order to resolve it with the Choco solver.One of the constraint I'm coding is cyclical (it's triplet which follow themselves) like the following example:s.post(LogicalConstraintFactory.ifThen(    IntConstraintFactory.member(mvt[i], new int[]{1, 2, 3}),    IntConstraintFactory.not_member(mvt[i + 1], new int[]{1, 2, 3})));s.post(LogicalConstraintFactory.ifThen(    IntConstraintFactory.member(mvt[i], new int[]{4, 5, 6}),    IntConstraintFactory.not_member(mvt[i + 1], new int[]{4, 5, 6})));s.post(LogicalConstraintFactory.ifThen(    IntConstraintFactory.member(mvt[i], new int[]{7, 8, 9}),    IntConstraintFactory.not_member(mvt[i + 1], new int[]{7, 8, 9})));// and so one...I think that my library isn't very known so the mathematics equivalent is :if(foo[i] is in {1, 2, 3}) then    foo[i+1] shouldn't be in {1, 2, 3}if(foo[i] is in {4, 5, 6}) then    foo[i+1] shouldn't be in {4, 5, 6}...Any idea of how I can model this problem with modulo (to avoid writing each triplet)?
Code reduction possible with modulo operator?
java;optimization;mathematics
I'm not familiar with the choco solver, but would this solve your problem?s.post(IntConstraintFactory.not_member(mvt[i+1],    new int[] { (mvt[i]/3)*3 + 1, (mvt[i]/3)*3 + 2, (mvt[i]/3)*3 + 3}));Another option might be:s.post(LogicalConstraintFactory.not(  IntConstraintFactory.eucl_div(mvt[i+1]-1, 3, (int)(mvt[i]-1)/3)));From the documentation:/** * Ensures DIVIDEND / DIVISOR = RESULT, rounding towards 0 -- Euclidean division * * @param DIVIDEND dividend * @param DIVISOR  divisor * @param RESULT   result */