解決set of Boolean equations,我與Constraint-Programming Solver
MiniZinc嘗試使用以下輸入:轉換布爾FlatZinc到CNF DIMACS
% Solve system of Brent's equations modulo 2
% Matrix dimensions
int: aRows = 3;
int: aCols = 3;
int: bCols = 3;
int: noOfProducts = 23;
% Dependent parameters
int: bRows = aCols;
int: cRows = aRows;
int: cCols = bCols;
set of int: products = 1..noOfProducts;
% Corefficients are stored in arrays
array[1..aRows, 1..aCols, products] of var bool: A;
array[1..bRows, 1..bCols, products] of var bool: B;
array[1..cRows, 1..cCols, products] of var bool: C;
constraint
forall(rowA in 1..aRows, colA in 1..aCols) (
forall(rowB in 1..bRows, colB in 1..bCols) (
forall (rowC in 1..cRows, colC in 1..cCols) (
xorall (k in products) (
A[rowA, colA, k] /\ B[rowB, colB, k] /\ C[rowC, colC, k]
) == ((rowA == rowC) /\ (colB == colC) /\ (colA == rowB))
)
)
);
solve satisfy;
% Output solution as table of variable value assignments
output
["\nSolution for <" ++ show(aRows) ++ ", " ++ show(aCols) ++
", " ++ show(bCols) ++ "> " ++ show(noOfProducts) ++ " products:"] ++
["\nF" ++ show(100*rowA+10*colA+k) ++ " = " ++
show(bool2int(A[rowA, colA, k])) |
rowA in 1..aRows, colA in 1..aCols, k in products] ++
["\nG" ++ show(100*rowB+10*colB+k) ++ " = " ++
show(bool2int(B[rowB, colB, k])) |
rowB in 1..bRows, colB in 1..bCols, k in products] ++
["\nD" ++ show(100*rowC+10*colC+k) ++ " = " ++
show(bool2int(C[rowC, colC, k])) |
rowC in 1..cRows, colC in 1..cCols, k in products];
MiniZinc沒有找到小參數(rows=cols=2, products=7)
一個解決方案,但沒有走到盡頭略有增加。 我想喂生成的FlatZinc模型到SAT solver像Cryptominisat,Lingeling或Clasp。我希望這些工具可能會勝過現有的MiniZinc後端。
我的問題:
是否有任何可用的工具,以一個純粹的布爾FlatZinc模型轉換爲CNF (DIMACS)?
我能做些什麼來取代xorall()
謂詞,因爲一些MiniZinc後端似乎不支持它?
非常感謝這些真正深刻的提示。我擔心你的解決方案時間短是由於建模錯誤造成的。'((rowA == rowC)/ \(colB == colC)/ \(colA == rowB))''應該可能轉化爲'bool2int((rowA == rowC)/ \(colB == colC)/ \ colA == rowB))' –
感謝糾正,阿克塞爾。它在答案中改變了。我會看看是否有一些FlatZinc求解器更快。 – hakank
經過測試的新版本和MiniCSP仍然相當快:3s。 – hakank