3

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

x*y + z + t - 10 = 0

有约束:

10 < x < 100

ETC..

我正在尝试使用 Choco 库来做这件事,但我有点迷茫。我找到了这段代码:

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

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

4

2 回答 2

2

我以前没有使用过这个库,但也许你应该简单地把你的方程当作一个约束?

于 2016-01-11T09:02:07.673 回答
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

于 2016-01-13T11:14:16.040 回答