0

I'm new to chocosolver, and i want to add an arithmetic constraint to my model. The probleme is that the constraint contains 6 Invar variables. Here is the constraint: ((A1*B1)+(A2*B2)) / (B1+B2) = Const; With A1, A2, B1, B2 are Intvar variables. The arithm() method does not work here, because it takes only 3 Invars as parameters.

Thank you.

1 Answers1

0

You have to decompose your equation into sub-equations and additional variables. This can be done automatically by Choco-solver when expressions are used.

Model model = new Model();
IntVar A1 = model.intVar(1, 10);
IntVar A2 = model.intVar(1, 10);
IntVar B1 = model.intVar(1, 10);
IntVar B2 = model.intVar(1, 10);
((A1.mul(B1)).add(A2.mul(B2))).div((B1.add(B2))).eq(10);
model.getSolver().solve();

Alternatively, you can declare the additional variables and sub-equations by yourself:

Model model = new Model();
IntVar A1 = model.intVar(1, 10);
IntVar A2 = model.intVar(1, 10);
IntVar B1 = model.intVar(1, 10);
IntVar B2 = model.intVar(1, 10);
IntVar C1 = model.intVar(2, 20);
model.arithm(A1, "*", B1, "=", C1).post();
IntVar C2 = model.intVar(2, 20);
model.arithm(A2, "*", B2, "=", C2).post();
IntVar C3 = model.intVar(2,20);
model.arithm(C1, "+", C2, "=", C3).post();
IntVar C4 = model.intVar(2,20);
model.arithm(B1, "+", B2, "=", C4).post();
model.arithm(C3, "/", C4, "=", 10).post();
model.getSolver().solve();
model.getSolver().printShortStatistics();
cprudhom
  • 111
  • 4