/* Global constraint inverse_except_0 in Picat. Note: This constraint is not in the Global Constraint Catalogue. It is inspired by the following: Nicolas Beldiceanu Global Constraints: Graph-Based Representation, page 76. """ Almost a Bijection. You want to match two sequences of genes (so that you minimise Sequence 1 Sequence 1 Sequence 2 A1 = 2 B1 = 3 1 2 3 4 5 6 7 8 9 A2 = 4 B2 = 1 A3 = 1 B3 = 4 A4 = 3 B4 = 2 A5 = 8 B5 = 0 A6 = 6 B6 = 6 A7 = 7 B7 = 7 A8 = 0 B8 = 5 1 2 3 4 5 6 7 8 9 10 11 12 A9 =10 B9 = 0 B10= 9 B11= 0 Sequence 2 B12= 0 Dual model Question: How do you link these two sets of variables ? The standard channelling constraint (inverse) is not working ! Which leads to inverse_within_range (inverse+dummy value) """ Cf inverse_within_range.pi This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N1 = 9, N2 = 12, X1 = new_list(N1), X1 :: 0..12, X2 = new_list(N2), X2 :: 0..12, % 1 2 3 4 5 6 7 8 9 X1 = [2,4,1,3,8,6,7,0,10], % % 10 11 12 % X2 = [3,1,4,2,0,6,7,5, 0, 9, 0, 0], % X2 = [3,1,4,2,0,6,7,5, 0, 9, 0, 0], X2 = [_,_,4,2,0,6,7,5, 0, 9, 0, 0], inverse_except_0(X1, X2), Vars = X1 ++ X2, solve(Vars), println(x1=X1), println(x2=X2), nl, fail, nl. % % inverse_except_0(X1, X2) % % From MiniZinc globals.mzn inverse constraint, I just added the 0 clauses. % inverse_except_0(X1, X2) => all_different_except_0(X1), all_different_except_0(X2), foreach(I in 1..X1.len, J in 1..X2.len) X1[I] #= 0 #\/ X2[J] #= 0 #\/ ( X1[I] #<= X2.len #/\ X2[J] #<= X1.len #/\ (J #= X1[I] #<=> I #= X2[J]) ) end.