用约束求解多变量方程 - Choco

时间:2016-01-11 08:59:33

标签: java equation-solving choco

我想用这样的离散值求解非线性多变量方程:

10 < x < 100

有约束:

    // 1. Create a Solver
    Solver solver = new Solver("my first problem");
    // 2. Create variables through the variable factory
    IntVar x = VariableFactory.bounded("X", 0, 5, solver);
    IntVar y = VariableFactory.bounded("Y", 0, 5, solver);
    // 3. Create and post constraints by using constraint factories
    solver.post(IntConstraintFactory.arithm(x, "+", y, "<", 5));
    // 4. Define the search strategy
    solver.set(IntStrategyFactory.lexico_LB(x, y));
    // 5. Launch the resolution process
    solver.findSolution();
    //6. Print search statistics
    Chatterbox.printStatistics(solver);

等。

我正在尝试使用Choco库,但我有点失落。 我找到了这段代码:

:before

但我不明白我在哪里放置方程式。

2 个答案:

答案 0 :(得分:2)

之前我没有使用过这个库,但也许您应该简单地将等式视为约束?

答案 1 :(得分:1)

是的,更确切地说,你应该将方程式分解为几个约束条件:

10 < x < 100

成为

solver.post(ICF.arithm(x,">",10));
solver.post(ICF.arithm(x,"<",100));

x*y + z + t - 10 = 0

变为

// x*y = a 
IntVar a = VF.bounded("x*y",-25,25,solver);
solver.post(ICF.times(x,y,a); 
// a+z+t=10
IntVar cst = VF.fixed(10,solver);
solver.post(ICF.sum(new IntVar[]{a,z,t},cst)); 

最佳,

联系我们以获取有关Choco Solver的更多支持:www.cosling.com