javachoco

sum multiple variables in one constraint with choco


I am using choco to solve a CSP , and one of my constraints is that the sum of all my 5 variables is less than 10 . for a sum of two variables we can use the function arithm

model.arithm(x1,"+",x2,"<",10).post();

but this method can't accept more variables so is there a way add this constraint ?


Solution

  • Would the sum constraint not work for you?

    model.sum(new IntVar[]{x1, x2, x3, x4, x5}, "<", 10).post()