Dear All, >> I have included the 3 full files to illustrate this. > >Umm, did you? :) > Sorry, my mail program does funny things, there attached in sent mail, but not the copy I bounced back to myself. I will try again! >I'll try to look into the rest anyway. > >Cheers, >Warwick Ok, I will be intrested to know if I have made a stupid mistake! Karen :- lib(ic). :- lib(ic_global). :- lib(ic_search). :- lib(lists). :- lib(ic_sbds). all_solutions(all_sym_funcs):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234c(Permutations, Node, N), s1243c(Permutations, Node, N), s1324c(Permutations, Node, N), s1342c(Permutations, Node, N), s1423c(Permutations, Node, N), s1432c(Permutations, Node, N), s2134c(Permutations, Node, N), s2143c(Permutations, Node, N), s2314c(Permutations, Node, N), s2341c(Permutations, Node, N), s2413c(Permutations, Node, N), s2431c(Permutations, Node, N), s3124c(Permutations, Node, N), s3142c(Permutations, Node, N), s3214c(Permutations, Node, N), s3241c(Permutations, Node, N), s3412c(Permutations, Node, N), s3421c(Permutations, Node, N), s4123c(Permutations, Node, N), s4132c(Permutations, Node, N), s4213c(Permutations, Node, N), s4231c(Permutations, Node, N), s4312c(Permutations, Node, N), s4321c(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N), s1234sc(Permutations, Node, N), s1243sc(Permutations, Node, N), s1324sc(Permutations, Node, N), s1342sc(Permutations, Node, N), s1423sc(Permutations, Node, N), s1432sc(Permutations, Node, N), s2134sc(Permutations, Node, N), s2143sc(Permutations, Node, N), s2314sc(Permutations, Node, N), s2341sc(Permutations, Node, N), s2413sc(Permutations, Node, N), s2431sc(Permutations, Node, N), s3124sc(Permutations, Node, N), s3142sc(Permutations, Node, N), s3214sc(Permutations, Node, N), s3241sc(Permutations, Node, N), s3412sc(Permutations, Node, N), s3421sc(Permutations, Node, N), s4123sc(Permutations, Node, N), s4132sc(Permutations, Node, N), s4213sc(Permutations, Node, N), s4231sc(Permutations, Node, N), s4312sc(Permutations, Node, N), s4321sc(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), make_display_matrix(Node,start), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln("Nodes:"), writeln(Node), writeln("Edges:"), writeln(Edge), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_symm):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint_less_symms):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s3214(Permutations, Node, N), s4231(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). model(Node, Edge, N):- dim(Node, [8]), Node[1..8] :: 0..16, dim(Edge, [32]), Edge[1..32] :: [-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], N is 16. constrain(Node, Edge):- Edge[1] #= Node[1]-Node[2], Edge[2] #= Node[2]-Node[1], Edge[3] #= Node[2]-Node[4], Edge[4] #= Node[4]-Node[2], Edge[5] #= Node[3]-Node[4], Edge[6] #= Node[4]-Node[3], Edge[7] #= Node[1]-Node[3], Edge[8] #= Node[3]-Node[1], Edge[9] #= Node[1]-Node[5], Edge[10] #= Node[5]-Node[1], Edge[11] #= Node[2]-Node[6], Edge[12] #= Node[6]-Node[2], Edge[13] #= Node[3]-Node[7], Edge[14] #= Node[7]-Node[3], Edge[15] #= Node[4]-Node[8], Edge[16] #= Node[8]-Node[4], Edge[17] #= Node[5]-Node[6], Edge[18] #= Node[6]-Node[5], Edge[19] #= Node[6]-Node[8], Edge[20] #= Node[8]-Node[6], Edge[21] #= Node[7]-Node[8], Edge[22] #= Node[8]-Node[7], Edge[23] #= Node[5]-Node[7], Edge[24] #= Node[7]-Node[5], Edge[25] #= Node[5]-Node[8], Edge[26] #= Node[8]-Node[5], Edge[27] #= Node[6]-Node[7], Edge[28] #= Node[7]-Node[6], Edge[29] #= Node[1]-Node[4], Edge[30] #= Node[4]-Node[1], Edge[31] #= Node[2]-Node[3], Edge[32] #= Node[3]-Node[2], flatten_matrix(Edge, EdgeList), flatten_matrix(Node, NodeList), ic_global:alldifferent(EdgeList), ic_global:alldifferent(NodeList). %predicate to create an array of all possible permuatations symmetrypermutations(Permutations) :- Permutations =[]([](1,2,3,4, 5,6,7,8), [](1,2,4,3, 5,6,8,7), [](1,3,2,4, 5,7,6,8), [](1,3,4,2, 5,7,8,6), [](1,4,2,3, 5,8,6,7), [](1,4,3,2, 5,8,7,6), [](2,1,3,4, 6,5,7,8), [](2,1,4,3, 6,5,8,7), [](2,3,1,4, 6,7,5,8), [](2,3,4,1, 6,7,8,5), [](2,4,1,3, 6,8,5,7), [](2,4,3,1, 6,8,7,5), [](3,1,2,4, 7,5,6,8), [](3,1,4,2, 7,5,8,6), [](3,2,1,4, 7,6,5,8), [](3,2,4,1, 7,6,8,5), [](3,4,1,2, 7,8,5,6), [](3,4,2,1, 7,8,6,5), [](4,1,2,3, 8,5,6,7), [](4,1,3,2, 8,5,7,6), [](4,2,1,3, 8,6,5,7), [](4,2,3,1, 8,6,7,5), [](4,3,1,2, 8,7,5,6), [](4,3,2,1, 8,7,6,5), [](5,6,7,8, 1,2,3,4), [](5,6,8,7, 1,2,4,3), [](5,7,6,8, 1,3,2,4), [](5,7,8,6, 1,3,4,2), [](5,8,6,7, 1,4,2,3), [](5,8,7,6, 1,4,3,2), [](6,5,7,8, 2,1,3,4), [](6,5,8,7, 2,1,4,3), [](6,7,5,8, 2,3,1,4), [](6,7,8,5, 2,3,4,1), [](6,8,5,7, 2,4,1,3), [](6,8,7,5, 2,4,3,1), [](7,5,6,8, 3,1,2,4), [](7,5,8,6, 3,1,4,2), [](7,6,5,8, 3,2,1,4), [](7,6,8,5, 3,2,4,1), [](7,8,5,6, 3,4,1,2), [](7,8,6,5, 3,4,2,1), [](8,5,6,7, 4,1,2,3), [](8,5,7,6, 4,1,3,2), [](8,6,5,7, 4,2,1,3), [](8,6,7,5, 4,2,3,1), [](8,7,5,6, 4,3,1,2), [](8,7,6,5, 4,3,2,1)). %****** Symmetry Functions ****** %Permuting values s1243(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is Value. s1324(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is Value. s1342(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is Value. s1423(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is Value. s1432(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is Value. s2134(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is Value. s2143(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is Value. s2314(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is Value. s2341(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is Value. s2413(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is Value. s2431(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is Value. s3124(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is Value. s3142(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is Value. s3214(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is Value. s3241(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is Value. s3412(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is Value. s3421(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is Value. s4123(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is Value. s4132(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is Value. s4213(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is Value. s4231(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is Value. s4312(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is Value. s4321(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is Value. %Permutations * Complementing values s1234c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[1, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is N-Value. %permutations * swapping squares s1234s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is Value. s1243s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is Value. s1324s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is Value. s1342s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is Value. s1423s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is Value. s1432s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is Value. s2134s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is Value. s2143s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is Value. s2314s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is Value. s2341s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is Value. s2413s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is Value. s2431s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is Value. s3124s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is Value. s3142s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is Value. s3214s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is Value. s3241s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is Value. s3412s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is Value. s3421s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is Value. s4123s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is Value. s4132s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is Value. s4213s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is Value. s4231s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is Value. s4312s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is Value. s4321s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is Value. %permutaions * swapping squares * compliment s1234sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is N-Value. %Search procedure for sbds on a 1D matrix %AllVars: Input, Variables to be seached on (the board) symlabelingmatrix(AllVars) :- ( fromto(AllVars, Vars, VarsRem, []) do delete(Var, Vars, VarsRem, 0, input_order), count_backtracks, sbds_indomain(Var) ). %Replacement for indomain/1 which takes SBDS into account. %Var: Input, Variable to operate on sbds_indomain(Var) :- nonvar(Var). sbds_indomain(Var) :- var(Var), get_bounds(Var, Lo, _Hi), sbds_try(Var, Lo), sbds_indomain(Var). %prints a matrix with a line per row %M: Matrix to be printed prettyprint_matrix(M) :- foreacharg(X, M) do writeln(X). %predicates used to count the number of backtracks :- local variable(backtracks), variable(deep_fail). init_backtracks :- setval(backtracks,0). get_backtracks(B) :- getval(backtracks,B). count_backtracks :- setval(deep_fail,false). count_backtracks :- getval(deep_fail,false), % may fail setval(deep_fail,true), incval(backtracks), fail. % Flatten a matrix into a list of its elements. flatten_matrix(M, List) :- flatten_matrix(M, List, []). flatten_matrix(M, List, Tail) :- compound(M), !, M =.. [_ | Elems], ( foreach(Elem, Elems), fromto(List, List1, Tail1, Tail) do flatten_matrix(Elem, List1, Tail1) ). flatten_matrix(X, [X | Tail], Tail). :- lib(ic). :- lib(ic_global). :- lib(ic_search). :- lib(lists). :- lib(ic_sbds). all_solutions(all_sym_funcs):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234c(Permutations, Node, N), s1243c(Permutations, Node, N), s1324c(Permutations, Node, N), s1342c(Permutations, Node, N), s1423c(Permutations, Node, N), s1432c(Permutations, Node, N), s2134c(Permutations, Node, N), s2143c(Permutations, Node, N), s2314c(Permutations, Node, N), s2341c(Permutations, Node, N), s2413c(Permutations, Node, N), s2431c(Permutations, Node, N), s3124c(Permutations, Node, N), s3142c(Permutations, Node, N), s3214c(Permutations, Node, N), s3241c(Permutations, Node, N), s3412c(Permutations, Node, N), s3421c(Permutations, Node, N), s4123c(Permutations, Node, N), s4132c(Permutations, Node, N), s4213c(Permutations, Node, N), s4231c(Permutations, Node, N), s4312c(Permutations, Node, N), s4321c(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N), s1234sc(Permutations, Node, N), s1243sc(Permutations, Node, N), s1324sc(Permutations, Node, N), s1342sc(Permutations, Node, N), s1423sc(Permutations, Node, N), s1432sc(Permutations, Node, N), s2134sc(Permutations, Node, N), s2143sc(Permutations, Node, N), s2314sc(Permutations, Node, N), s2341sc(Permutations, Node, N), s2413sc(Permutations, Node, N), s2431sc(Permutations, Node, N), s3124sc(Permutations, Node, N), s3142sc(Permutations, Node, N), s3214sc(Permutations, Node, N), s3241sc(Permutations, Node, N), s3412sc(Permutations, Node, N), s3421sc(Permutations, Node, N), s4123sc(Permutations, Node, N), s4132sc(Permutations, Node, N), s4213sc(Permutations, Node, N), s4231sc(Permutations, Node, N), s4312sc(Permutations, Node, N), s4321sc(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), make_display_matrix(Node,start), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln("Nodes:"), writeln(Node), writeln("Edges:"), writeln(Edge), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_symm):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint_less_symms):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s3214(Permutations, Node, N), s4231(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). model(Node, Edge, N):- dim(Node, [8]), Node[1..8] :: 0..16, dim(Edge, [32]), Edge[1..32] :: [0..15,17..32], N is 16. constrain(Node, Edge):- Edge[1] #= Node[1]-Node[2]+16, Edge[2] #= Node[2]-Node[1]+16, Edge[3] #= Node[2]-Node[4]+16, Edge[4] #= Node[4]-Node[2]+16, Edge[5] #= Node[3]-Node[4]+16, Edge[6] #= Node[4]-Node[3]+16, Edge[7] #= Node[1]-Node[3]+16, Edge[8] #= Node[3]-Node[1]+16, Edge[9] #= Node[1]-Node[5]+16, Edge[10] #= Node[5]-Node[1]+16, Edge[11] #= Node[2]-Node[6]+16, Edge[12] #= Node[6]-Node[2]+16, Edge[13] #= Node[3]-Node[7]+16, Edge[14] #= Node[7]-Node[3]+16, Edge[15] #= Node[4]-Node[8]+16, Edge[16] #= Node[8]-Node[4]+16, Edge[17] #= Node[5]-Node[6]+16, Edge[18] #= Node[6]-Node[5]+16, Edge[19] #= Node[6]-Node[8]+16, Edge[20] #= Node[8]-Node[6]+16, Edge[21] #= Node[7]-Node[8]+16, Edge[22] #= Node[8]-Node[7]+16, Edge[23] #= Node[5]-Node[7]+16, Edge[24] #= Node[7]-Node[5]+16, Edge[25] #= Node[5]-Node[8]+16, Edge[26] #= Node[8]-Node[5]+16, Edge[27] #= Node[6]-Node[7]+16, Edge[28] #= Node[7]-Node[6]+16, Edge[29] #= Node[1]-Node[4]+16, Edge[30] #= Node[4]-Node[1]+16, Edge[31] #= Node[2]-Node[3]+16, Edge[32] #= Node[3]-Node[2]+16, flatten_matrix(Edge, EdgeList), flatten_matrix(Node, NodeList), ic_global:alldifferent(EdgeList), ic_global:alldifferent(NodeList). %predicate to create an array of all possible permuatations symmetrypermutations(Permutations) :- Permutations =[]([](1,2,3,4, 5,6,7,8), [](1,2,4,3, 5,6,8,7), [](1,3,2,4, 5,7,6,8), [](1,3,4,2, 5,7,8,6), [](1,4,2,3, 5,8,6,7), [](1,4,3,2, 5,8,7,6), [](2,1,3,4, 6,5,7,8), [](2,1,4,3, 6,5,8,7), [](2,3,1,4, 6,7,5,8), [](2,3,4,1, 6,7,8,5), [](2,4,1,3, 6,8,5,7), [](2,4,3,1, 6,8,7,5), [](3,1,2,4, 7,5,6,8), [](3,1,4,2, 7,5,8,6), [](3,2,1,4, 7,6,5,8), [](3,2,4,1, 7,6,8,5), [](3,4,1,2, 7,8,5,6), [](3,4,2,1, 7,8,6,5), [](4,1,2,3, 8,5,6,7), [](4,1,3,2, 8,5,7,6), [](4,2,1,3, 8,6,5,7), [](4,2,3,1, 8,6,7,5), [](4,3,1,2, 8,7,5,6), [](4,3,2,1, 8,7,6,5), [](5,6,7,8, 1,2,3,4), [](5,6,8,7, 1,2,4,3), [](5,7,6,8, 1,3,2,4), [](5,7,8,6, 1,3,4,2), [](5,8,6,7, 1,4,2,3), [](5,8,7,6, 1,4,3,2), [](6,5,7,8, 2,1,3,4), [](6,5,8,7, 2,1,4,3), [](6,7,5,8, 2,3,1,4), [](6,7,8,5, 2,3,4,1), [](6,8,5,7, 2,4,1,3), [](6,8,7,5, 2,4,3,1), [](7,5,6,8, 3,1,2,4), [](7,5,8,6, 3,1,4,2), [](7,6,5,8, 3,2,1,4), [](7,6,8,5, 3,2,4,1), [](7,8,5,6, 3,4,1,2), [](7,8,6,5, 3,4,2,1), [](8,5,6,7, 4,1,2,3), [](8,5,7,6, 4,1,3,2), [](8,6,5,7, 4,2,1,3), [](8,6,7,5, 4,2,3,1), [](8,7,5,6, 4,3,1,2), [](8,7,6,5, 4,3,2,1)). %****** Symmetry Functions ****** %Permuting values s1243(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is Value. s1324(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is Value. s1342(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is Value. s1423(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is Value. s1432(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is Value. s2134(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is Value. s2143(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is Value. s2314(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is Value. s2341(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is Value. s2413(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is Value. s2431(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is Value. s3124(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is Value. s3142(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is Value. s3214(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is Value. s3241(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is Value. s3412(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is Value. s3421(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is Value. s4123(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is Value. s4132(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is Value. s4213(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is Value. s4231(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is Value. s4312(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is Value. s4321(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is Value. %Permutations * Complementing values s1234c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[1, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is N-Value. %permutations * swapping squares s1234s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is Value. s1243s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is Value. s1324s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is Value. s1342s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is Value. s1423s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is Value. s1432s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is Value. s2134s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is Value. s2143s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is Value. s2314s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is Value. s2341s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is Value. s2413s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is Value. s2431s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is Value. s3124s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is Value. s3142s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is Value. s3214s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is Value. s3241s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is Value. s3412s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is Value. s3421s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is Value. s4123s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is Value. s4132s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is Value. s4213s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is Value. s4231s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is Value. s4312s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is Value. s4321s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is Value. %permutaions * swapping squares * compliment s1234sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is N-Value. %Search procedure for sbds on a 1D matrix %AllVars: Input, Variables to be seached on (the board) symlabelingmatrix(AllVars) :- ( fromto(AllVars, Vars, VarsRem, []) do delete(Var, Vars, VarsRem, 0, input_order), count_backtracks, sbds_indomain(Var) ). %Replacement for indomain/1 which takes SBDS into account. %Var: Input, Variable to operate on sbds_indomain(Var) :- nonvar(Var). sbds_indomain(Var) :- var(Var), get_bounds(Var, Lo, _Hi), sbds_try(Var, Lo), sbds_indomain(Var). %prints a matrix with a line per row %M: Matrix to be printed prettyprint_matrix(M) :- foreacharg(X, M) do writeln(X). %predicates used to count the number of backtracks :- local variable(backtracks), variable(deep_fail). init_backtracks :- setval(backtracks,0). get_backtracks(B) :- getval(backtracks,B). count_backtracks :- setval(deep_fail,false). count_backtracks :- getval(deep_fail,false), % may fail setval(deep_fail,true), incval(backtracks), fail. % Flatten a matrix into a list of its elements. flatten_matrix(M, List) :- flatten_matrix(M, List, []). flatten_matrix(M, List, Tail) :- compound(M), !, M =.. [_ | Elems], ( foreach(Elem, Elems), fromto(List, List1, Tail1, Tail) do flatten_matrix(Elem, List1, Tail1) ). flatten_matrix(X, [X | Tail], Tail). :- lib(ic). :- lib(ic_global). :- lib(ic_search). :- lib(lists). :- lib(ic_sbds). all_solutions(all_sym_funcs):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234c(Permutations, Node, N), s1243c(Permutations, Node, N), s1324c(Permutations, Node, N), s1342c(Permutations, Node, N), s1423c(Permutations, Node, N), s1432c(Permutations, Node, N), s2134c(Permutations, Node, N), s2143c(Permutations, Node, N), s2314c(Permutations, Node, N), s2341c(Permutations, Node, N), s2413c(Permutations, Node, N), s2431c(Permutations, Node, N), s3124c(Permutations, Node, N), s3142c(Permutations, Node, N), s3214c(Permutations, Node, N), s3241c(Permutations, Node, N), s3412c(Permutations, Node, N), s3421c(Permutations, Node, N), s4123c(Permutations, Node, N), s4132c(Permutations, Node, N), s4213c(Permutations, Node, N), s4231c(Permutations, Node, N), s4312c(Permutations, Node, N), s4321c(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N), s1234sc(Permutations, Node, N), s1243sc(Permutations, Node, N), s1324sc(Permutations, Node, N), s1342sc(Permutations, Node, N), s1423sc(Permutations, Node, N), s1432sc(Permutations, Node, N), s2134sc(Permutations, Node, N), s2143sc(Permutations, Node, N), s2314sc(Permutations, Node, N), s2341sc(Permutations, Node, N), s2413sc(Permutations, Node, N), s2431sc(Permutations, Node, N), s3124sc(Permutations, Node, N), s3142sc(Permutations, Node, N), s3214sc(Permutations, Node, N), s3241sc(Permutations, Node, N), s3412sc(Permutations, Node, N), s3421sc(Permutations, Node, N), s4123sc(Permutations, Node, N), s4132sc(Permutations, Node, N), s4213sc(Permutations, Node, N), s4231sc(Permutations, Node, N), s4312sc(Permutations, Node, N), s4321sc(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), make_display_matrix(Node,start), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln("Nodes:"), writeln(Node), writeln("Edges:"), writeln(Edge), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_symm):- model(Node, Edge, N), constrain(Node, Edge), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N), s1234s(Permutations, Node, N), s1243s(Permutations, Node, N), s1324s(Permutations, Node, N), s1342s(Permutations, Node, N), s1423s(Permutations, Node, N), s1432s(Permutations, Node, N), s2134s(Permutations, Node, N), s2143s(Permutations, Node, N), s2314s(Permutations, Node, N), s2341s(Permutations, Node, N), s2413s(Permutations, Node, N), s2431s(Permutations, Node, N), s3124s(Permutations, Node, N), s3142s(Permutations, Node, N), s3214s(Permutations, Node, N), s3241s(Permutations, Node, N), s3412s(Permutations, Node, N), s3421s(Permutations, Node, N), s4123s(Permutations, Node, N), s4132s(Permutations, Node, N), s4213s(Permutations, Node, N), s4231s(Permutations, Node, N), s4312s(Permutations, Node, N), s4321s(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1342(Permutations, Node, N), s1423(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s2143(Permutations, Node, N), s2314(Permutations, Node, N), s2341(Permutations, Node, N), s2413(Permutations, Node, N), s2431(Permutations, Node, N), s3124(Permutations, Node, N), s3142(Permutations, Node, N), s3214(Permutations, Node, N), s3241(Permutations, Node, N), s3412(Permutations, Node, N), s3421(Permutations, Node, N), s4123(Permutations, Node, N), s4132(Permutations, Node, N), s4213(Permutations, Node, N), s4231(Permutations, Node, N), s4312(Permutations, Node, N), s4321(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). all_solutions(no_complement_plus_constraint_less_symms):- model(Node, Edge, N), constrain(Node, Edge), ((Node[1] #= 0) or (Node[2] #= 0) or (Node[3] #= 0) or (Node[4] #= 0)), symmetrypermutations(Permutations), Syms = [ s1243(Permutations, Node, N), s1324(Permutations, Node, N), s1432(Permutations, Node, N), s2134(Permutations, Node, N), s3214(Permutations, Node, N), s4231(Permutations, Node, N) ], sbds_initialise(Node, Syms, #=, []), setval(solutions, 0), flatten_matrix(Node, NodeList), statistics(times, [T0|_]), ( init_backtracks, symlabelingmatrix(NodeList), getval(solutions, S), Sol is (S + 1), printf("\nSolution %d \n", [Sol]), writeln(Node), incval(solutions), fail ; true ), get_backtracks(B), statistics(times, [T1|_]), T is T1-T0, getval(solutions, S), printf("\nFound %d solutions for graph in %w s with %d backtracks\n", [S,T,B]). model(Node, Edge, N):- dim(Node, [8]), Node[1..8] :: 0..16, dim(Edge, [32]), Edge[1..32] :: [-16..-1, 1..16], N is 16. constrain(Node, Edge):- Edge[1] #= Node[1]-Node[2], Edge[2] #= Node[2]-Node[1], Edge[3] #= Node[2]-Node[4], Edge[4] #= Node[4]-Node[2], Edge[5] #= Node[3]-Node[4], Edge[6] #= Node[4]-Node[3], Edge[7] #= Node[1]-Node[3], Edge[8] #= Node[3]-Node[1], Edge[9] #= Node[1]-Node[5], Edge[10] #= Node[5]-Node[1], Edge[11] #= Node[2]-Node[6], Edge[12] #= Node[6]-Node[2], Edge[13] #= Node[3]-Node[7], Edge[14] #= Node[7]-Node[3], Edge[15] #= Node[4]-Node[8], Edge[16] #= Node[8]-Node[4], Edge[17] #= Node[5]-Node[6], Edge[18] #= Node[6]-Node[5], Edge[19] #= Node[6]-Node[8], Edge[20] #= Node[8]-Node[6], Edge[21] #= Node[7]-Node[8], Edge[22] #= Node[8]-Node[7], Edge[23] #= Node[5]-Node[7], Edge[24] #= Node[7]-Node[5], Edge[25] #= Node[5]-Node[8], Edge[26] #= Node[8]-Node[5], Edge[27] #= Node[6]-Node[7], Edge[28] #= Node[7]-Node[6], Edge[29] #= Node[1]-Node[4], Edge[30] #= Node[4]-Node[1], Edge[31] #= Node[2]-Node[3], Edge[32] #= Node[3]-Node[2], flatten_matrix(Edge, EdgeList), flatten_matrix(Node, NodeList), ic_global:alldifferent(EdgeList), ic_global:alldifferent(NodeList). %predicate to create an array of all possible permuatations symmetrypermutations(Permutations) :- Permutations =[]([](1,2,3,4, 5,6,7,8), [](1,2,4,3, 5,6,8,7), [](1,3,2,4, 5,7,6,8), [](1,3,4,2, 5,7,8,6), [](1,4,2,3, 5,8,6,7), [](1,4,3,2, 5,8,7,6), [](2,1,3,4, 6,5,7,8), [](2,1,4,3, 6,5,8,7), [](2,3,1,4, 6,7,5,8), [](2,3,4,1, 6,7,8,5), [](2,4,1,3, 6,8,5,7), [](2,4,3,1, 6,8,7,5), [](3,1,2,4, 7,5,6,8), [](3,1,4,2, 7,5,8,6), [](3,2,1,4, 7,6,5,8), [](3,2,4,1, 7,6,8,5), [](3,4,1,2, 7,8,5,6), [](3,4,2,1, 7,8,6,5), [](4,1,2,3, 8,5,6,7), [](4,1,3,2, 8,5,7,6), [](4,2,1,3, 8,6,5,7), [](4,2,3,1, 8,6,7,5), [](4,3,1,2, 8,7,5,6), [](4,3,2,1, 8,7,6,5), [](5,6,7,8, 1,2,3,4), [](5,6,8,7, 1,2,4,3), [](5,7,6,8, 1,3,2,4), [](5,7,8,6, 1,3,4,2), [](5,8,6,7, 1,4,2,3), [](5,8,7,6, 1,4,3,2), [](6,5,7,8, 2,1,3,4), [](6,5,8,7, 2,1,4,3), [](6,7,5,8, 2,3,1,4), [](6,7,8,5, 2,3,4,1), [](6,8,5,7, 2,4,1,3), [](6,8,7,5, 2,4,3,1), [](7,5,6,8, 3,1,2,4), [](7,5,8,6, 3,1,4,2), [](7,6,5,8, 3,2,1,4), [](7,6,8,5, 3,2,4,1), [](7,8,5,6, 3,4,1,2), [](7,8,6,5, 3,4,2,1), [](8,5,6,7, 4,1,2,3), [](8,5,7,6, 4,1,3,2), [](8,6,5,7, 4,2,1,3), [](8,6,7,5, 4,2,3,1), [](8,7,5,6, 4,3,1,2), [](8,7,6,5, 4,3,2,1)). %****** Symmetry Functions ****** %Permuting values s1243(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is Value. s1324(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is Value. s1342(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is Value. s1423(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is Value. s1432(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is Value. s2134(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is Value. s2143(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is Value. s2314(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is Value. s2341(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is Value. s2413(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is Value. s2431(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is Value. s3124(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is Value. s3142(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is Value. s3214(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is Value. s3241(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is Value. s3412(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is Value. s3421(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is Value. s4123(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is Value. s4132(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is Value. s4213(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is Value. s4231(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is Value. s4312(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is Value. s4321(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is Value. %Permutations * Complementing values s1234c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[1, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[2, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[3, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[4, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[5, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[6, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[7, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[8, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[9, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[10, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[11, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[12, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[13, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[14, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[15, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[16, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[17, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[18, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[19, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[20, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[21, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[22, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[23, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321c(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[24, Index], SymVar is Node[SymIndex], SymValue is N-Value. %permutations * swapping squares s1234s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is Value. s1243s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is Value. s1324s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is Value. s1342s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is Value. s1423s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is Value. s1432s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is Value. s2134s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is Value. s2143s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is Value. s2314s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is Value. s2341s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is Value. s2413s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is Value. s2431s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is Value. s3124s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is Value. s3142s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is Value. s3214s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is Value. s3241s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is Value. s3412s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is Value. s3421s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is Value. s4123s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is Value. s4132s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is Value. s4213s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is Value. s4231s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is Value. s4312s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is Value. s4321s(Permutations, Node, _N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is Value. %permutaions * swapping squares * compliment s1234sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[25, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1243sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[26, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1324sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[27, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1342sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[28, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1423sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[29, Index], SymVar is Node[SymIndex], SymValue is N-Value. s1432sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[30, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2134sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[31, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2143sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[32, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2314sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[33, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2341sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[34, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2413sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[35, Index], SymVar is Node[SymIndex], SymValue is N-Value. s2431sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[36, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3124sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[37, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3142sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[38, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3214sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[39, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3241sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[40, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3412sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[41, Index], SymVar is Node[SymIndex], SymValue is N-Value. s3421sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[42, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4123sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[43, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4132sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[44, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4213sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[45, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4231sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[46, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4312sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[47, Index], SymVar is Node[SymIndex], SymValue is N-Value. s4321sc(Permutations, Node, N, Index, Value, SymVar, SymValue) :- SymIndex is Permutations[48, Index], SymVar is Node[SymIndex], SymValue is N-Value. %Search procedure for sbds on a 1D matrix %AllVars: Input, Variables to be seached on (the board) symlabelingmatrix(AllVars) :- ( fromto(AllVars, Vars, VarsRem, []) do delete(Var, Vars, VarsRem, 0, input_order), count_backtracks, sbds_indomain(Var) ). %Replacement for indomain/1 which takes SBDS into account. %Var: Input, Variable to operate on sbds_indomain(Var) :- nonvar(Var). sbds_indomain(Var) :- var(Var), get_bounds(Var, Lo, _Hi), sbds_try(Var, Lo), sbds_indomain(Var). %prints a matrix with a line per row %M: Matrix to be printed prettyprint_matrix(M) :- foreacharg(X, M) do writeln(X). %predicates used to count the number of backtracks :- local variable(backtracks), variable(deep_fail). init_backtracks :- setval(backtracks,0). get_backtracks(B) :- getval(backtracks,B). count_backtracks :- setval(deep_fail,false). count_backtracks :- getval(deep_fail,false), % may fail setval(deep_fail,true), incval(backtracks), fail. % Flatten a matrix into a list of its elements. flatten_matrix(M, List) :- flatten_matrix(M, List, []). flatten_matrix(M, List, Tail) :- compound(M), !, M =.. [_ | Elems], ( foreach(Elem, Elems), fromto(List, List1, Tail1, Tail) do flatten_matrix(Elem, List1, Tail1) ). flatten_matrix(X, [X | Tail], Tail).Received on Fri Nov 22 10:51:32 2002
This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:19 PM GMT GMT