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.

4

1 回答 1

0

您必须将方程分解为子方程和附加变量。这可以在使用表达式时由 Choco-solver 自动完成。

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();

或者,您可以自己声明其他变量和子方程:

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();
于 2020-07-03T15:46:23.567 回答