簡體   English   中英

為什么 Choco-solver 找不到解決方案?

[英]Why doesn't Choco-solver find a solution?

我正在學習使用Choco-solver 我發現它無法找到一個非常簡單的問題的解決方案,這意味着我一定誤解了一些東西......

我將我的代碼簡化為:

    Model model = new Model("Minimum");
    IntVar x = model.intVar("x", 1, 9, false);
    IntVar y = model.intVar("y", 1, 9, false);
    IntVar z = model.intVar("z", -1000, 1000, false);

    z.eq(x.add(y.mul(2))).post();

    Solver solver = model.getSolver();
    solver.showStatistics();
    solver.showSolutions();
    solver.findSolution();

因此,三個 integer 變量和一個約束說z = x + 2y Choco-solver 響應Complete search - No solution

如果我將約束的內部部分從y.mul(2)更改為y.mul(1) (x = 1, y = 1, z = 2) 或y.add(2) 2),我發現我得到了正確的解決方案y.add(2) (x = 1, y = 1, z = 4)。 我什至可以將其設置為y.mul(-2) (x = 1 y = 9 z = -17),但如果我使用mul的 integer 大於 1,則約束似乎無法解決。

這里發生了什么?

這確實是 Choco Solver 4.10.7 中的一個錯誤。 此錯誤已得到修復: https://github.com/chocoteam/choco-solver/issues/841

如果您想使用固定版本,我邀請您從 GitHub 下載代碼並使用 Maven 進行編譯。

關於你的約束,我建議你發布一個算術約束如下: model.arithm(x, "+", y.mul(2).intVar(), "=", z).post(); . 這樣,您就避免了一個與“x+2*y”相對應的中間變量,您強制它等於 z。 在這樣一個小例子中並不重要,但它可能導致 memory 在依賴 ArExpression(用於算術表達式)時出現更大的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM