0

我使用 choco 求解器 2.1.5 版,我想体验一下以最小化我的变量总和。我怎么能这样做?

4

1 回答 1

0

也许你从 sourceforge 下载了那个版本:在那里,我们建议访问 http://choco-solver.org,在那里我们可以下载更新的版本。

With the more recent version 4.10.7, released on Oct 11 2021, 
you may experiment with something like this:


    Model model = new Model();
            
    IntVar x = model.intVar("x", 3, 10, false);
    IntVar y = model.intVar("y", 2, 20, false);
    IntVar sum = model.intVar("sum", 1, 50, false);
    
    model.arithm(x, "+", y, "=", sum).post();
            
    Solver solver = model.getSolver();  
    model.setObjective(Model.MINIMIZE, sum);
    
    while (solver.solve()) {
        System.out.println(" x = " + x.getValue());
        System.out.println(" y = " + y.getValue());
        System.out.println(" sum = " + sum.getValue());
    } 


It will print:

    x = 3
    y = 2
    sum = 5
于 2021-12-15T20:53:06.060 回答