[英]How to produce a reified `array_int_maximum` in Flatzinc output?
[英]Convert Boolean FlatZinc to CNF DIMACS
為了解決一組布爾方程 ,我正在使用以下輸入試驗Constraint-Programming Solver
MiniZinc :
% 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模型輸入到像Cryptominisat , Lingeling或Clasp這樣的SAT求解器中 。 我希望這些工具可能勝過現有的MiniZinc后端。
我的問題:
有沒有可用於將純布爾FlatZinc模型轉換為CNF(DIMACS)的工具 ?
我可以做些什么來替換xorall()
謂詞,因為一些MiniZinc后端似乎不支持它?
我不知道有任何工具可以將FlatZinc文件轉換為CNF(DIMACS)文件。 (MiniZinc發行版有一個將flatzinc轉換為XCSP格式的程序。也許有一個XCSP到CNF的工具?)
但是,有一些基於SAT /靈感的解算器可能更好,例如minicsp,fzn2smt。 問題是它們 - 正如你所提到的 - 不支持相當新的xorall()函數。
此外,使用帶標簽的搜索可能是一個好主意,即這樣的事情(請注意bool_search)
solve :: bool_search(
[A[i,j,k] | i in 1..aRows, j in 1..aCols, k in products],
first_fail,
indomain_min,
complete)
satisfy;
另外,我建議您測試轉換為基於0..1的模型,這些解算器可以和其他解決方案一起進行測試。
這是我的轉換模型,我剛剛將var bool更改為var 0..1並用sum()和bool2int()替換xorall()[我希望我轉換正確。]更新:我已更改為版本阿克塞爾建議。
% 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 0..1: A; % hakank: change to 0..1
array[1..bRows, 1..bCols, products] of var 0..1: B;
array[1..cRows, 1..cCols, products] of var 0..1: 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) (
% hakank: changed
sum (k in products) (
bool2int(A[rowA, colA, k]=1/\ B[rowB, colB, k]=1 /\ C[rowC, colC, k]=1)
) ==
%% bool2int(rowA == rowC)+ bool2int(colB == colC) + bool2int(colA == rowB)
bool2int((rowA == rowC)/\(colB == colC)/\(colA == rowB))
)
)
);
solve :: int_search(
[A[i,j,k] | i in 1..aRows, j in 1..aCols, k in products] ++
[B[i,j,k] | i in 1..aRows, j in 1..aCols, k in products] ++
[C[i,j,k] | i in 1..aRows, j in 1..aCols, k in products]
,
first_fail,
indomain_min,
complete)
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(A[rowA, colA, k]) |
rowA in 1..aRows, colA in 1..aCols, k in products] ++
["\nG" ++ show(100*rowB+10*colB+k) ++ " = " ++
show(B[rowB, colB, k]) |
rowB in 1..bRows, colB in 1..bCols, k in products] ++
["\nD" ++ show(100*rowC+10*colC+k) ++ " = " ++
show(C[rowC, colC, k]) |
rowC in 1..cRows, colC in 1..cCols, k in products];
這是模型: http : //www.hakank.org/minizinc/akemper1_2.mzn 。
[更新:這些時間適用於較早的,錯誤的模型。]模型中的問題實例由minicsp在3s(包括展平),5s中的Opturion CPX求解器,6s中的fzn2smt解決(第一解)。 並且可以使用標簽等進一步調整模型。
提到的解決方案的鏈接:
Opturion CPX: http : //www.opturion.com/cpx.html
MiniCSP: http : //www.inra.fr/mia/T/katsirelos/minicsp.html
fzn2smt: http ://ima.udg.edu/Recerca/ESLIP/fzn2smt/index.html
另請參閱我的MiniZinc頁面以獲取更長的FlatZinc求解器列表: http : //www.hakank.org/minizinc/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.