Combinatorial Explorations in Su-Doku

Su-Doku, a popular combinatorial puzzle, provides an excellent testbench for heuristic explorations. Several interesting questions arise from its deceptively simple set of rules. How many distinct Su-Doku grids are there? How to find a solution to a …

Authors: Jean-Marie Chauvet

Com binatorial explorations in Su-Doku jmc Octob er 23, 2018 Abstract Su-Doku , a p opular co mbinatorial pu zzle, provides an excellen t test- b enc h for heuristic explorations. Several i nteresting questions arise from its deceptively simple set of ru les. How man y distinct Su-Doku grids are there? How to find a solution to a Su-Doku p uzzle? Is there a uniqu e solution to a given Su-Doku p uzzle? What is a goo d estimation of a puzzle’s difficulty? What is the minim um puzzle size ( the number of “giv ens”)? This pap er explores ho w these qu estions are rela ted t o the w ell-known alldifferen t constraint which emerges in a wide v ariet y of Constraint Sat- isfaction Problems (CSP) and compares v arious algorithmic approaches based on differen t formulatio ns of Su -Doku. 1 Su-Doku as a CSP Su-Doku grids and puzzles. Su-Doku is a well-known lo gic-based num ber placement puzzle. The ob jective is to fill a 9x9 sq uare gr id so that each line, each column or file, and each of the nine 3 x3 blo cks contains exclus iv ely the digits 1 to 9, only once each. A puzzle is a partially completed gr id. This definition is readily gener alized to lar ger gr ids. Let us consider M n = { 1 . . . n } the set of digits 1 to n , a Su-Do k u o f s ize n is a n 2 × n 2 grid which is to be filled so that each of the n 2 lines, each of the n 2 columns and each of the the n 2 blo c ks contains the digits 1 to n only one time each. The deceptively simple definition actually hides lar ge combinatorial pro b- lems, even for small v alues of n . This is, for insta nce, reflected in the num ber of suc h Su-Doku grids as ca lc ulated by F elgenhauer and Jarv is [6]: Size Num ber 1 1 2 288 3 6,670,9 03,752,0 21,072,936,960 T able 1. This is sequence A1077 39 in the Online Encyclop e dia of Inte ger Se quenc es . The n umber of grids in the familiar siz e -3 Su-Doku is alr eady mind-b oggling! 1 Constrain t Satisfaction Problem. The r ules o f Su-Doku can b e cast in terms of constra in ts that a solution s ho uld comply with to b e v alid. A constraint satisfaction problem (CSP ) is a triple ( X, D , C ), where X is a sequence of n v aria bles x 1 , x 2 , . . . x n , D is a sequence of n finite domains D 1 , D 2 , . . . D n , wher e D i is the se t of p ossible v alues for v a riable x i , and C a finite s et o f c o nstraints betw een v ar iables. A c onstraint C o n a subsequence of v ar iables x i 1 , x i 2 , . . . x i m is simply a subset o f the cartesia n pro duct D i 1 × D i 2 . . . D i m , which express e s the allow ed combination of v ar iable v alues. Constraints ar e often expres sed as equations that v ariables m ust satisfy . General CSP Expressio n for Su-Doku. As will b e see n in later sections, there are several wa ys to ex pr ess a Su- Do ku puzzle a s a concr ete CSP . In somewhat abstra ct ter ms, the C SP formulation would state four gr oups of con- straints: i. Each of the n 4 cells contains a unique v a lue fro m the set M n 2 ii. Each of the n 2 lines of the grid contains all v alues from the set M n 2 iii. E ach of the n 2 files of the grid contains all v alues from the set M n 2 iv. Ea c h of the n 2 blo c ks of the grid contains all v a lues fro m the s et M n 2 where each of n 4 v aria bles x 1 , . . . , x n 4 would represe nt a gr id cell. The initial “ g iv ens” of a Su-Doku puzzle restr ict the a ctual sets from which the ab ov e constra in ts allow v alues to b e as signed to these v ariables. In the conv ent ional Su-Doku puzzle, there are 81 v ar iables and 81 + 3 × 9 = 108 such general constraints. 1.1 Constrain t propagation v. Searc h Alternating propagation and searc h . When nothing m uch is known ab out the co nstraints of a CSP , the genera l pro cedure to find a solution, o r to show that no ne exists, alternates pr op agation a nd se ar ch . Each constra in t is a s so- ciated with a propagation pr ocedur e which tries to shrink the domains of the constraint v ariables by removing v a lues that are certa inly not part of a solution. This pro cedure uses firs t the loc a lly av aila ble information, i.e. information pro - vided by the constraint itself. When suc h a v alue is excluded from a v ar ia ble’s domain, this info r mation is also provided to all other propag ation pro cedures asso ciated with constr ain ts that shar e the same v ariable. This externally pro- vided information might then tr ig ger a propagation pro cedure of a constraint which w as lo cally consistent, which in turns might exclude other v alues, provid- ing a gain this new information to o ther constr a in t pro cedures. The casca de of propaga tion pr ocedur e calls s tops, how ever, after so me time, in a state o f globa l stability where all of the CSP constra in ts ar e lo cally consistent tog ether. The globally stable state may or may not b e a solution (or a fa ilur e) to the CSP . If not, a search pro cedure splits the cur ren t pr oblem into at least t wo 2 CSPs, usually b y as signing a v alue to a v a riable from its cur ren t domain. Mor e generally this is done by dividing the current D i domain of a v a r iable x i int o k disjo in t subsets ( k > 2) the unio n of which is D i and considering the k CSP subproblems. The pr opagation phase is rep eated for each subproblem, thus recursively creating a s earch tree with the orig inal pr o blem at its ro ot and the solutions or failures at its leav es. It is indeed a search pr ocedur e since the c ho ice of the domain to split, a nd hence of whic h v aria ble to propaga te, and how to split it may b e based o n heuristics o r rules of thum b sp ecific to the problem at hand. Human Problem-So lving i n Su-Doku puzzles. It is generally acknowl- edged that the alternating propag ation and search pro cedures are effectively used by human so lv ers when tackling Su-Doku puzzle s . All tutor ia ls, b o o ks, W eb sites a nd other br oadly av aila ble Su-Doku instr uc tio nal materia l s tart by highlighting that the first s teps to b e ta k en tow ards a solution inv olve propaga - tion of the givens, simply by ticking off for each of them its v alue from the other cells in the same line, file and blo c k. Should this leave exa ctly one po ssible v alue for a nother ce ll, mark it and propa gate in turn to this cell’s line, file a nd blo c k un til no more propa gation is p ossible. A t this step, there a r e litter ally tens of heuristics with inv en tive names such as “Fish”, “XY-Wing” o r “XY-Chain”, ranging fro m the simple check to the complex pattern, to cho ose fro m in o rder to p erform the sear c h pha se. Numer- ous Su-Doku W eb sites offer catalo gs of patterns to lo ok for in a partially solved puzzles, a nd ea c h h uman solver develops his or her own individual catalog as exp erience grows. There is no recog nized standard, howev er, for ev aluating the complexity of such heuris tics. Hence ther e is no simple way of comparing Su- Do ku puzzles difficulties, as so me search heuristics may b e considered simple by some and complex by others . While the num b er of g iv ens, which are in fac t star ting po in ts for the propa gation procedur es, is cer tainly an indication of the difficult y level, it is not a complete indicator o f the actual complexity . Even s o -called minimal puzzles wher e for n = 3 there ar e 1 7 givens, mig h t prov e ea sy to solve if the initial pro pagation g oes far tow ards the so lution, leaving only few empty cells for search. (The fact that a n = 3 Su-Doku puzzle needs a t least 17 givens in or der to have a unique solution is still, at the time of this writing, a conjecture.) 1.2 A Simple Propagation-Searc h Algorithm In this section we pres en t a very simple implementation of the alternated propaga tion- search phases to solve Su-Doku puzzles a s CSP . This is for illustrative purp ose and b y no means the only w ay to implemen t propagation and searc h, or to strike a ba lance b etw een pr opagation a nd sea rc h in CSP so lutions. Some of the ideas here are inspired by [15], and, for la c k o f a b etter name, we simply call this algorithm the PS-1-2 algor ithm. 3 Propagation. With ea c h cell in the gr id, the algor ithm maintains an arr a y of the v alid v alues whic h ca n be used for this cell, its so-called domain that the propaga tion pha se seeks to reduce a s m uch as p ossible provided the constra in ts. Initially for a n o rder Su-Dok u puzzle, all domains D i,j are the same set M n 2 of the first n 2 int eger s . Propag ation resolves into itera ting four sepa r ate steps: − A v alue v is ass igned to a cell, thus reducing D i,j to { v } − The newly assigned v alue v is deleted fro m the domains of cells lying in the same line, file a nd block than the initial cell: D i,k , D k,j and D B ( i,j )= B ( p, q ) are therefore reduced to D i,k \{ v } , D k,j \{ v } and D B ( i,j )= B ( p, q ) \{ v } re- sp ectiv ely . (Here i , j range ov er 1 . . . n 2 , and so do k , p and q ; the so me- what infor mal notation B ( i, j ) denotes the blo ck, in the rang e 1 . . . n 2 , containing the i, j cell.) − Another reduction step is taken, leveraging the duality o f co nstraints in the particular Su- Doku CSP formulation. As each line, file or blo ck may only contain one occur ence of any num b er 1 . . . n 2 , each of the num b er ha s to be a ssigned to a unique cell within a line, file o r blo ck. So if a v alue v app ears only once in all D i,j of a g iv en line, file or blo ck, the pro cess reduces this singled out D i,j to { v } . − After this reduction step, so me do ma ins D i,j may happ en to b e empty , in which cas e the puzzle ha s no solution - we’ll say that the propag a tion is blo cke d - or to b e reduced to a s ingleton { w } . I f all domains are singletons, the puzzle is solve d . If only some o f the domains ar e s ingletons, the algorithm r e iter ates these steps assigning the singletons’ v alues to the corres p onding cells. The iteration is stopp ed when no further reductio n happ ens in step 4 of the ab o ve pro pagation pro cess . Reductions are done in any order as it do es not impact the final r esult after the system rea c hes a quiescent state. The “1 ” in the algorithm name comes from the choice of r e ducing domains o n a sing le constraint type (and its dual): the unicity of v alues for CSP v aria bles. Data represen tation. In order to low er the computation cos ts, the domains for each of the n 2 v aria bles r epresenting the puzzle cells a r e implemented as p acke d arr ays in C. Reduction then b ecomes a logic a l op eration on a bit ar - rays. Step 3 of the previo us pro pagation pr oces s requires the doma ins to b e transp osed: for ea ch line, file and blo ck, n 2 new bit arrays a re computed, the i-th of whic h is made of bits i of the n 2 domain bit arrays. Binary Searc h. After the propagatio n phase we ma y end in a blocked, so lv ed or yet indeterminate state. Again we choo se here a simple sear ch pro cedure for the ne x t steps towards a so lution in the indeterminate case. Namely w e lo ok for domains reduced to 4 simple pair s { v , w } and we op erate a binary depth-first search, first reducing to { v } and then, if no solution is found after recurs iv e pro pagation and sea rch, reducing to { w } and propaga ting/searching again. Note that if a t the end of each of the propag ation phase w e do indeed find pair domains, this pro cess will certainly termina te either finding a solution o r proving, after enumeration, that no so lution exis t for this puzzle . The “2” in the name of the algorithm derives from the fact that we only consider pair domains in the search phase. The PS-1-2 algor ithm is only one in a s c o pe of alg orithms which we will in- vestigate further in the following se c tions and which were develop ed to so lv e a particular type o f constra in t, called al ldi ffer ent in the CSP literature. It s o happ ens that the CSP for m ulation of Su-Do k u us es only inter-related alldiffer- ent constraints th us offering a p erfect case study for co m binatorial analyses o f the v a rious appro ac hes to the g eneral solution o f alldifferent constraints. E v en more so, we will see that Su-Doku constraints a re a s pecial fo r m of alldifferent constraints, i.e p ermutation constr ain ts, w hich sp ecific pr oper ties will sugg est a completely different a pproach to Su-Doku puzzle r e present ation and so lution explored in the second section of this pap er. 1.3 Exp erimen t s and Results A C Impleme n tation. T he PS-1-2 algor ithm was implemented in C under Cygwin for exp erimentation purp o ses. The core o f the implemen tation is a r - ticulated a round tw o functions: a propag ation a nd reduction function called solveS tep , a nd a recur siv e depth-fir st search function called pairR educe . int solveS tep( int main_ step ){ int step, i, flag, main_f lag = 1; while( main_f lag ){ // Local rules and propag ation main loop flag = 1; step =1; // 1. Prop agate given s while( flag ){ flag = propag ate(); step++ ; } main_s tep += step ; // 2. Redu ces lines , cols and blo cks // Rem.: flag is 0 at this point , L is n*n for( i = 0; i < L; i++ ) flag += reduce Line( i ); for( i = 0; i < L; i++ ) flag += reduce Column( i ); for( i = 0; i < L; i++ ) flag += reduce Block( i ); main_s tep += flag ; 5 main_f lag = (flag > 0 ) ? 1 : 0; } return main_s tep; } The previous co de fragment details the so lveStep function which pr opagates assignments of v a lues to cells by calling the (not-repre s en ted) p ropagat e func- tion, which in turn oper ates on the doma in bit arr a y re pr esen tations, deleting the assigned v alues from other cells’ doma ins in eac h relev ant line, file a nd blo c k. This is in fact step 2 of the PS-1-2 algo rithm as descr ibed in the pre- vious sectio n. Then the dual s tep in domain reductio n is ta k en by calling the (not-represe nted) redu ceLine , re duceColu mn and red uceBlock functions which handle the trans position and reduction in step 3 of the PS- 1 -2 algorithm. This function exits whe n no domain can be further reduced to a singleton through the iteration of the basic prop agate and reduce op erations. In addition the function maintains v arious counters, namely step and main step , for simple statistics. The depth-first sea rc h function is str a igh tforward: int pairRe duce( int step ){ packPt r p; struct pack keep[S ]; if( 1 == solved p() ) retur n step; if( 1 == blocke dp() ) retu rn step ; S_Redu ceSteps += 1; // Find a pair domai n p p = nextPa ir(); if( (packP tr)0 == p ){ printf ( "No pair left . S= %d, B=% d ", solvedp (), block edp() ); } else{ int hi, lo; // Store curren t stat e of sear ch as an ar ray of do main bit arrays packcp y( keep, cell ); // Extra ct low and high value s in pai r p lo = getPa ck( p ); // Delet e low value from doma in p subPac k( p, lo ); hi = getPa ck( p ); // And propag ate to othe r doma ins step = solveS tep( ste p ); if( 1 == solved p() ) retur n step; step = pairRe duce( step ); if( 1 == solved p() ) retur n step; 6 // No solu tion reac hed, rest ore se arch state packcp y( cell, keep ); // Now delete high value from domai n p subPac k( p, hi ); // And propag ate to othe r doma ins step = solveS tep( ste p ); if( 1 == solved p() ) retur n step; if( 0 == blocke dp() ){ step = pairRe duce( step ); } } return step; } This co de fragmen t illustrates the search pro cedure. If pairRed uce is en tered in a solved o r blo c ked state it returns immediately . If e n tered in an indeterminate state, it first finds a pair domain, by calling the (non-repr e s en ted) nex tPair function. (In the implementation this function do es a simple but costly linear search on the array of all domain bit arr ays.) If it fails to find such a pair domain it simply s tops, although in a ll of the test puzzles this never happ ened. When it suc c eeds, how ever, the function backs up the c urrent sear c h state, here an ar ray of domain bit arrays represe nting the remaining p ossible v alues for each cell in the puzzle, ass igns first the highest v alue of the pair domain to the cell and propag ates this ass ignmen t b y calling the previously mentioned solveS tep . A t this p oint , the puzzle is either so lv ed and p airReduc e r eturns (recursively up to the first caller in fact), or in a blo ck ed or indetermina te state. In the latter cases, and in standar d depth-first fas hion, we search another pair domain b y calling recur s iv ely p airRedu ce . Note that if the sta te is blo c ked, this recursive ca ll returns immediately . When it do es not a nd we still hav e no solution on the fir st br a nc h o f our binar y search, we try the other o ne. The function duly restores the back ed up state o f search a nd this time ass igns the lowest v alue o f the pair do main to the ce ll and propaga tes to other domains, again calling solv eStep . V ar ious c oun ters ar e a ls o up dated for statistical purp oses. In order to obtain a running solver progr am, these functions a re wrapp ed into a main func- tion which initializes all domains to the same all-o ne bit arrays, reads the puz- zle in fro m a file, executes the initial propag a tion o f the “givens” a nd calls pairRe duce(0) . An E xample Run. W e ran PS-1 -2 on some of the minimal puzzle instances as collected by Gordo n Royle [19] who main tains a catalog of order 3 Su-Dokus puzzles with only 17 “givens”. On another example, the following puzzle, whic h is not part of this “minimal puzzles” set: 7 Example 1 Puzzle .125.4 87. ...... ... 75.... .23 ..41.8 7.. .2..5. .4. ..34.9 5.. 48.... .17 ...... ... .357.1 69. is solved with only 77 propaga tion and 11 search o pera tions by PS-1 - 2, as detailed in the following tabular tra ce: Example 2 Prop Red Srch Tot. Prop Tot. Srch 3 - - 3 0 - 3 - 6 0 3 - - 9 0 - 0 - 9 0 - - h 9 1 3 - - 12 1 - 0 - 12 1 - - h 12 2 3 - - 15 2 - 3 - 18 2 3 - - 21 2 - 2 - 23 2 3 - - 26 2 - 0 - 26 2 - - h 26 3 3 - - 29 3 - 0 - 29 3 - - h 29 4 5 - - 34 4 - 1 - 35 4 3 - - 38 4 - 0 - 38 4 - - h 38 5 3 - - 41 5 - 0 - 41 5 - - h 41 6 5 - - 46 6 - 1 - 47 6 3 - - 50 6 - 0 - 50 6 - - l 50 6 8 3 - - 53 6 - 0 - 53 6 - - h 53 7 3 - - 56 7 - 1 - 57 7 3 - - 60 7 - 0 - 60 7 - - h 60 8 5 - - 65 8 - 0 - 65 8 - - h 65 9 3 - - 68 9 - 0 - 68 9 - - h 68 10 4 - - 72 10 - 0 - 72 10 - - h 72 11 5 - - 77 11 - 0 - 77 11 Grid: solved 1, blocked 0; in 77 operatio ns ------ ------- ------------ | 6 1 2 | 5 3 4 | 8 7 9 | | 3 4 9 | 2 8 7 | 1 6 5 | | 7 5 8 | 9 6 1 | 4 2 3 | ------ ------- ------------ | 5 9 4 | 1 2 8 | 7 3 6 | | 8 2 7 | 6 5 3 | 9 4 1 | | 1 6 3 | 4 7 9 | 5 8 2 | ------ ------- ------------ | 4 8 6 | 3 9 5 | 2 1 7 | | 9 3 1 | 7 4 2 | 6 5 8 | | 2 7 5 | 8 1 6 | 3 9 4 | ------ ------- ------------ The pro cess called the search pr ocedur e 11 times, when the propagation/ reduction op erations reach quies cence as indicated by a 0 in the Red(uctions) column. The Srch column indicates whether the h(igh) o r l(ow) v alue of the pa ir sear c hed is used for the next propaga tio n phase. In the pa rticular instance, backtrack o ccurred o nly o nce a t the sixth pair sear c h: b oth high and low v alue were propaga ted to find the solution. Conclusions . The canonica l pro cedure to solve CSP-formulated problems al- ternates a propag ation phase, where data is us ed to reduce domains of the v aria bles as far as p ossible, also known as filtering, with a sea rch phase, a back- track pro cedure which explores incremental steps tow a rds a so lution. There is ample r oom for v ar iabilit y in this framework both in the balance b etw een 9 propaga tion and search, a nd within ea c h phase in the c riteria use d in filtering and in search. In the case of Su-Do ku puzzles, w e hav e pr esen ted a naiv e algorithm, PS-1-2 , which only filters on unicity of the v ariable v a lue and o f this v alue p er group (line, file or blo ck) in the pr o pagation phase , a nd only uses bina ry sea rc h in the alternating sear c h phase. Alt hough th ere should be pa thological cases where the binary sear c h phase might fail, the PS-1- 2 a lgorithm was succes sful at solving quickly all the puzzles we submitted, including so-called minimal puzzles. 1.4 CSP/SA T/LP formula tions: t he alldifferen t constrain t While several ad ho c CSP so lving pro cedures may b e designe d for Su-Doku puzzles, its co nstraints g enerally fa ll under a now well do cumented cla ss o f constraints for which efficient filtering pro cedures have b een published in the literature and a r e embedded in several to ols, commercial and o therwise. The pattern a ppear ing in all the constr ain ts in the ab ov e CSP for m ulation of Su- Doku directly relates to one of the latter, the al ldiffer ent co nstraint [21]. A CSP alldifferent e xpression. W e will rephras e the CSP express ion in terms of this well studied alldifferent constra in t. Let us consider the n -s ized Su-Doku puzzle a nd in tro duce the n 4 v aria bles x 1 , 1 . . . x n 2 ,n 2 representing the cells in a grid where, b y conven tio n, x i,j , is the v a lue to be assigned to the cell in line i and file j . All v a r iables have the same domain, taking their v alues in M n 2 . The CSP expre ssion of the problem is to find a unique v alue for each v aria ble satisfying the following s et of alldiffer en t constraints: • ∀ i ∈ { 1 , . . . n 2 } alldifferent ( x 1 ,i , . . . x n 2 ,i ) • ∀ j ∈ { 1 , . . . n 2 } alldifferent ( x j, 1 , . . . x j,n 2 ) • ∀ b ∈ { 1 , . . . n 2 } alldifferent ( x b 1 , . . . x b n 2 ) where the b k are the pair of indices of v ar iables repr esen ting ce lls in the same blo ck SA T formulations. A g iv en alldiffer en t constr ain t naturally translates into a se t of simpler binary co nstraint s on its v a riables, the n aive translation. In such naive tra ns lation the alldifferent constraint is expr essed as a conjunction of disjunctive clauses involving a t most tw o v ar iables and the v alues of the v aria ble domains. F or instance in the s iz e 2 Su-Doku puzzles , an a lldifferen t co nstraint on four v aria bles as in line, file and blo ck constra in ts b ecomes: alldifferent( x 1 , x 2 , x 3 , x 4 ) ⇋ x 1 6 = x 2 ∧ x 1 6 = x 3 ∧ x 1 6 = x 4 ∧ x 2 6 = x 3 ∧ x 2 6 = x 4 ∧ x 3 6 = x 4 ∧ ( x 1 = 1 ∨ x 1 = 2 ∨ x 1 = 3 ∨ x 1 = 4) ∧ ( x 2 = 1 ∨ x 2 = 2 ∨ x 2 = 3 ∨ x 2 = 4) ∧ ( x 3 = 1 ∨ x 3 = 2 ∨ x 3 = 3 ∨ x 3 = 4) ∧ ( x 4 = 1 ∨ x 4 = 2 ∨ x 4 = 3 ∨ x 4 = 4) a CNF for m ula with 10 disjunctive clauses, 6 of which are binar y a nd 4 of which unary . Genera lly spea king the s ize n alldifferent constra in t naively translates to a CNF formula with n ( n + 1) / 2 disjunctive cla uses. 10 The naive tra nslation is a ctually enough to b e fed to s tandard SA T so lv ers such as maxsatz [10] and minisat [5], for instance. LP form ulations. Lo gic pr ogramming to ols can also directly use the ab ov e SA T expressions. In this section we inv estigate t he use of the CLP(FD), or Con- straint Logic Pr ogramming for Finite Do mains, extension to the GNU-Pr olog implemen tation [4] in Su-Dok u puzzle exp eriments. Expanding on the ab ov e ana ly sis, a naive implementation of a single a lld- ifferent constraint simply tr anslates it into a corresp onding set o f bina ry co n- straints, each one of which stating that a given v ar iable is different from the other. F o cusing on 4x4 Su-Doku grids, i.e. n = 2, for ins ta nce, suc h a naive implemen tation of the single alldifferent constr ain t on four v ar iables w ould then be as follows: naive_ all_dif ferent(X,Y,Z,Z0) :- X \= Y, X \= Z, X \= Z0, Y \= Z, Y \= Z0, Z \= Z0. which states that each v ar iable should hav e a distinct v alue from the other three v a riables in the gro up. In order to complete the size 2 Su-Doku gr id enum era tio n, a definition predicate, assig n , is created to define the (unique) domain of all v aria bles: assign (1). assign (2). assign (3). assign (4). It is a pr edicate which is true for ea c h of the four admissible v alues of the cells in a size 2 Su-Doku puzz le . T o complete the GNU-Prolog pro gram, w e use these tw o predic a tes to expre s s all the cons train ts o f the 4x4 g r id: naive_ puzzle( A00, A01, A10, A11, B00, B01, B10, B11, C00, C01, C10, C11, D00, D01, D10, D11 ) :- system _time(T 0), cpu_ti me(T10) , real_t ime(T20 ), assign ( A00 ), assign ( A01 ) assign ( A10 ) assign ( A11 ) assign ( B00 ) assign ( B01 ) assign ( B10 ) assign ( B11 ) assign ( C00 ) assign ( C01 ) assign ( C10 ) 11 assign ( C11 ) assign ( D00 ) assign ( D01 ) assign ( D10 ) assign ( D11 ) naive_ all_dif ferent(A00, A01 , A10, A11) naive_ all_dif ferent(B00, B01 , B10, B11) naive_ all_dif ferent(C00, C01 , C10, C11) naive_ all_dif ferent(D00, D01 , D10, D11) naive_ all_dif ferent(A00, A01 , B00, B01 ) naive_ all_dif ferent(A10, A11 , B10, B11 ) naive_ all_dif ferent(C00, C01 , D00, D01 ) naive_ all_dif ferent(C10, C11 , D10, D11 ) naive_ all_dif ferent(A00, A10 , C00, C10 ) naive_ all_dif ferent(A01, A11 , C01, C11 ) naive_ all_dif ferent(B00, B10 , D00, D10 ) naive_ all_dif ferent(B01, B11 , D01, D11 ) system _time(T ), cpu_ti me(T1), real_t ime(T2) write( ’time T0: ’), write( T0), w rite(’, time T : ’ ),write(T ), nl , write( ’time T0: ’), write( T10), write (’, time T1: ’ ),write( T1), nl, write( ’time T0: ’), write( T20), write (’, time T2: ’ ),write( T2), nl. The predicates assigns unique v a lues to the 1 6 v a riables repr esen ting the corres p onding c e lls of the Su-Doku gr id or puzzle, and expre sses the alldifferent constraint on each of the 4 lines, files and blo cks. It also keeps tra c k of v a rious execution times for instrumentation purp oses. Execution times a r e unsurprising ly very long, even for the size 2 Su-Doku grids as the naive implementation only uses extremely lo cal constr ain ts within one line, file or blo c k and ignores global constraints. F or tunately , GNU-Pro log bundles a constraint logic prog ramming extension for finite doma ins which incorp orates the latest filtering algor ithms for a wide v ariety of co nstraint s used in industry pro blems. The CLP(FD) extension uses sp ecific filtering techniques for the alldifferent constraint, the theoretical ba sis of which will b e explor ed in the next s ections, lea ding to a m uch mor e efficient implemen tation of enumeration and s olving tasks. More sp ecifically , the CLP(FD) extension offers a simple set of built-in pred- icates s uc h as : fd domain to define v aria bles’ domains, fd all diff erent to state a single alldifferent constra in t (of a n y a r it y), a nd fd lab eling to tr igger search ac c ording to a choice of filtering methods. The CLP(FD) is fully de- scrib ed in Diaz’s Thesis [3]. The size 2 Su-Doku implementation now b ecomes: puzzle ( A 00, A01, A10, A11, B00, B01, B10, B11, 12 C00, C01, C10, C11, D00, D01, D10, D11) :- fd_dom ain( A00, 1, 4 ) fd_dom ain( A01, 1, 4 ) fd_dom ain( A10, 1, 4 ) fd_dom ain( A11, 1, 4 ) fd_dom ain( B00, 1, 4 ) fd_dom ain( B01, 1, 4 ) fd_dom ain( B10, 1, 4 ) fd_dom ain( B11, 1, 4 ) fd_dom ain( C00, 1, 4 ) fd_dom ain( C01, 1, 4 ) fd_dom ain( C10, 1, 4 ) fd_dom ain( C11, 1, 4 ) fd_dom ain( D00, 1, 4 ) fd_dom ain( D01, 1, 4 ) fd_dom ain( D10, 1, 4 ) fd_dom ain( D11, 1, 4 ) fd_all _differ ent([A00, A01 , A10, A11]) fd_all _differ ent([B00, B01 , B10, B11]) fd_all _differ ent([C00, C01 , C10, C11]) fd_all _differ ent([D00, D01 , D10, D11]) fd_all _differ ent([A00, A01 , B00, B01 ]) fd_all _differ ent([A10, A11 , B10, B11 ]) fd_all _differ ent([C00, C01 , D00, D01 ]) fd_all _differ ent([C10, C11 , D10, D11 ]) fd_all _differ ent([A00, A10 , C00, C10 ]) fd_all _differ ent([A01, A11 , C01, C11 ]) fd_all _differ ent([B00, B10 , D00, D10 ]) fd_all _differ ent([B01, B11 , D01, D11 ]) system _time(T 0), cpu_ti me(T10) , real_t ime(T20 ) fd_lab eling([ A00, A01 , A10, A11 B00, B01, B10, B11 C00, C01, C10, C11 D00, D01, D10, D11], [variabl e_method(most_constrained)]), system _time(T ), cpu_ti me(T1), real_t ime(T2) write( ’time T0: ’), write( T0), w rite(’, time T : ’ ),write(T ), nl , write( ’time T0: ’), write( T10), write (’, time T1: ’ ),write( T1), nl write( ’time T0: ’), write( T20), write (’, time T2: ’ ),write( T2), nl. 13 Basically this new puzzle predica te defines the 16 domains for the 16 v ariables with v alues in the same M 4 set, sta tes the thr ee group of alldifferent constraints and fina lly se arches for a prop er lab eling. As before, several ancillary predicates hav e b een added for instrumentation pur p oses. On the simple enumeration task, the first solution is a lmost instantly com- puted on a standard Int el machine r unning Windows XP : puzzle ( A00, A01, A10, A11, B00, B01, B10, B11, C00, C01, C10, C11, D00, D01, D10, D11). time T0: 296, time T : 296 time T0: 1609, time T1: 1609 time T0: 155875 , time T2: 155875 A00 = 1 A01 = 2 A10 = 3 A11 = 4 B00 = 3 B01 = 4 B10 = 1 B11 = 2 C00 = 2 C01 = 1 C10 = 4 C11 = 3 D00 = 4 D01 = 3 D10 = 2 D11 = 1 ? ; time T0: 296, time T : 312 time T0: 1609, time T1: 1625 time T0: 155875 , time T2: 158472 A00 = 1 A01 = 2 A10 = 3 A11 = 4 B00 = 3 B01 = 4 B10 = 1 B11 = 2 C00 = 2 C01 = 3 C10 = 4 C11 = 1 D00 = 4 14 D01 = 1 D10 = 2 D11 = 3 ? ; time T0: 296, time T : 328 time T0: 1609, time T1: 1641 time T0: 155875 , time T2: 222624 A00 = 1 A01 = 2 A10 = 3 A11 = 4 B00 = 3 B01 = 4 B10 = 1 B11 = 2 C00 = 4 C01 = 1 C10 = 2 C11 = 3 D00 = 2 D01 = 3 D10 = 4 D11 = 1 ? ; time T0: 296, time T : 343 time T0: 1609, time T1: 1656 time T0: 155875 , time T2: 228535 and the other 288 solutions are quickly pr in ted out for a total execution time of 2,797 milliseconds. 1.5 Arc-Consistency and v alue graph In or der to unders tand ho w to make the b est use of the lo cal infor mation pro- vided by the cons tr ain ts themselves, we in tro duce so me definitions of lo c al c on- sistency . Definition 1 A c onstr aint of arity m on the variables x i 1 . . . x i m is hyp er ar c c onsistent if al l values of the variables ar e use d in some solution t o t he c on- str aint, i.e. ∀ x i k ∀ v ∈ D i k , ∃ ( v i 1 , . . . , v i k − 1 , v i k +1 , . . . , v i m ) ∈ D i 1 × . . . D i k − 1 × D i k +1 × . . . D i m such that ( v i 1 , . . . , v i k − 1 , v , v i k +1 , . . . , v i m ) is a solution to the c onstra int. Definition 2 A c onst r aint C is ar c-c onsistent when C is of arity 2 (binary) and hyp er ar c c onsistent. A constraint has a solution if it can b e made hyperar c consistent. Hyp erarc consistency is the b est p ossible pruning base d on the lo cal information provided 15 by the constr ain t. The naive implementation above translate the alldifferent constraint into a co llection of binary constra in ts which are made arc-consistent by filtering the domains following the simple proc e dure which as so on as a domain is r educed to one v a lue, remov es this v alue from the domains of a ll other v aria bles. The more efficient v ariants use d, for instance, in the CLP(FD) pack age r ely on a completely different approa c h base d on r esults from gra ph theory . The corres p ondence with graph theory was used b y R´ egin [18] to crea te a filtering algorithm from matching the ory . W e int ro duce the notion of bipartite gr aph. Definition 3 Bip artite Gr aph. A gr aph G c onsist s of a fi nite, non-empty set of elements V c al le d no des, or vertic es, and a set of unor der e d p air of no des E c al le d e dges. If V c an b e p artitione d into t wo disjoint, non-empty sets X and Y such that al l e dges in E join a no de in X to a no de in Y, G is c al le d bip artite with p artition (X,Y); we also write G = (X,Y,E). The definition directly applies to the a lldifferen t constra int say , on v ariable set X = { x 1 , . . . x n } and domains D 1 . . . D n , in that it spe c ifies its value gr aph . Definition 4 V alue Gr aph. Given an al ldiffer ent c onstr aint, the bip artite gr aph G = ( X , S D i , E ) wher e ( x i , d ) ∈ E iff d ∈ D i is c al le d the value gr aph of t he c onstra int. The v alue g raph has an edge fro m each v aria ble in the constraint to ea c h of its do main v alue. Solving such a constraint b ecomes a pr oblem o f maximum matching in the co rresp onding v alue gra ph. Definition 5 Maximum Matching. A subset of e dges in a gr aph G is a match- ing if no two e dges have a vertex in c ommon. A matching of maximum c ar di- nality is c al le d a maximum matching. A matching c overs a set of vertic es X isf every no de in X is an endp oint of an e dge in the matching. The link b etw een matching theo r y and hyperar c cons istency esta blished b y R ´ egin is as follows. Prop osition 1 The c onstra int al ldi ffer ent on variable set X is hyp er ar c c onsis- tent iff every e dge in its value gr aph b elongs to a matching that c overs X in the value gr aph. Hyper arc and a rc-consistency algorithms ar e around O ( dn 1 . 5 ) where d is the maximum cardinality o f the domains and n the num b e r of v ariables . Matc hing Theory . O bviously if there is a complete ma tc hing fro m X to Y in ( X, Y , E ) then for every S ⊂ X there a re at least | S | vertices of Y adjacent to a vertex in S . That this necessary condition is als o sufficient is us ually called Ha lls ’ theor em. This fundamental r e sult was proved by Ha ll in 193 5, but an equiv alent form o f it ha d be e n prov ed by K¨ onig and Eg erv ary in 193 1; 16 bo th versions, ho wev er, follow from Menger ’s theorem from 1 927. W e refer to Bollobas for demonstrations and historic a l remark s [1]. These r esults will also b e the or igin of yet another approach to solving Su- Doku puzzles and en umerating g rids, as a complete matching is als o called a set of distinct representativ es, from which are der iv ed new expressions o f the Su-Doku problems in terms of exact c overs or dually ex act hitting set problems. This new for m ulation will suggest a different algor ithmic approach which is explored in Section 2. R ´ egin’s alg orithm relies on the fact tha t if we know only one arbitra r y maxi- m um matching, we can efficiently compute if an edge o f the v alue graph b elongs to so me matching of the same maximum size without having to explore all s uc h matchings. 1.6 Bounds- and r ange-cons istency filtering Hall’s theorem fr om matching theor y may als o b e used in relation to weaker forms of consistency called b o unds-consistency and range-co nsistency . Definition 6 Bounds Consistency. A c onstr aint of arity m wher e no domai n D i is empty, is c al le d b oun ds c onsistent iff for e ach variable and e ach value in the r ange b oun de d by min( D i ) and max( D i ), ther e exist values in the r esp e ct ive r anges b oun de d by the other domains minimum and m ax imum values such that to gether with the latter D i value t hey c onst itute a solution to the c onstr aint. Definition 7 R ange Consistency. A c onstr aint of arity m wher e no domain D i is empty, is c al le d b oun ds c onsistent iff for e ach variable and e ach value in D i , ther e ex ist values in the r esp e ctive r anges b ounde d by the other domains minimum and maximum values s u ch that to gether with the latt er D i value they c onstitu te a solution to t he c onstr aint. Note that here all domains are supp osed to b e integer do mains which ca n be (totally) ordere d. In contrast to hypera rc a nd a rc-consistency , bounds and range consis tency lo ok fo r v alues in the interv als defined by do mains, rather than the domains themselves. As these interv als may be larger than the ac tua l domains, these no tio ns repre sen t weak er form of co ns istencies than hyperar c and ar c-consistency . Bo th may b e considered as a r elaxation of the hype r arc consistency . (In addition, b ounds co nsistency may b e reg arded as a relaxation of range consistency itself.) Hall’s theorem ha s b een applied by Puget to cre ate a bounds co nsistency algorithm for the alldiffere n t constraint [17]. Giv en an interv al I let us denote K I the set of v ar ia bles x j such that D j ⊂ I , i.e. the subset of v ariables w hich domains ar e included into the cons idered interv al. W e say that I is a Hall int erv al iff | I | = | K I | . Pug et’s re sult is a s follows. Prop osition 2 The c onstr aint al ldiffer ent on variables x 1 , . . . , x n wher e n o do- main D i is empty is b ounds c onsist ent iff 17 i. fo r e ach int erval I | K I | ≤ | I | , ii. for e ach Hal l interval I , { min( D i ) , max( D i ) } ∩ I = ∅ for al l x i 6∈ K I . This can b e used to create an algorithm for b ounds consistency on alldifferen t constraints. W e chec k every int erv al I with b ounds ra nging from the minimum of all do mains to the maximum o f all domains. When | I | ≤ | K I | the constr ain t is incons isten t. And for ea c h Hall interv al, we remove the minim um and/or maximum unt il the intersection with I is empty . Example 3 Consider the following constraint: 1. alldiffer en t( x 1 , x 2 , x 3 ) 2. D 1 = { 1 , 2 } , D 2 = { 1 , 2 } , and D 3 = { 2 , 3 } The interv als we need to chec k are [1 , 2] , [1 , 3] , a nd [2 , 3]. When I = [1 , 2], the domains included in the interv al are D 1 and D 2 , hence K I = { x 1 , x 2 } a nd since | I | = | K I | = 2 , I is a Hall interv al. W e only have one v aria ble not in K I , namely x 3 , for which { min( D 3 ) , max( D 3 ) } ∩ I = { 2 } . The alg orithm remov es then 2 from D 3 and the r esulting system of sets { 1 , 2 } , { 1 , 2 } , { 3 } is now b ounds consistent. The tw o so lutions (1 , 2 , 3) and (2,1,3 ) are now a simple conseq uence of the reduction of D 3 . F aster implementation of b ounds consistency hav e been desig ned since Pug et’s publication [1 1, 13]. Leconte intro duced an algor ithm that achiev es range co n- sistency [9], als o based o n the Hall’s theore m. In dua l definitions from a bov e, given a set of v ariables K let I K be the in terv al [min( D K ) , max( D K )] where D K is the union of all v ar iable do mains; K is a Hall set iff | K | = | I K | . Prop osition 3 The c onstr aint al ldiffer ent al ldiffer ent on variables x 1 , . . . , x n wher e n o domain D i is empty is r ange c onsistent iff for e ach H al l set K , D i ∩ I K = ∅ for al l x i 6∈ K . An algo r ithm for range consistency can b e derived from the prev ious pro p o- sition in a similar wa y to the der iv ation of the bo unds consistency algo rithm. 1.7 Su-Doku as a CSP: a sp ecific problem Enumerating Su-Doku gr ids or solving puzzles within reasona ble space and time limits requires efficient algorithms for a single type of cons train t, the alldiffer en t constraint. While g eneral “propa gate + sea r c h” constraint-solving algorithms will work well o n Su-Doku puzzle s , sp ecifically tailor ed algor ithm for the alldif- ferent constraint w ork still better. There are several v ersions o f such algorithms, which embo dy different deg rees of consistency a nd hence of p erformance in the puzzle task. Moder n CSP , SA T and LP-so lv ers usually provide specific filtering pro cedures for the alldifferent cons train t, which make them to ols of choice for studying the complexity of the Su-Doku universe. 18 2 Su-Doku as an Exact Co v er p r ob lem In fact, Su-Doku gr ids and puzzles inv olve an even mo re sp ecific constra in t than the a lldifferen t co ns train t. As is obvious fro m the previously mentioned SA T and CSP form ulations, the a lldifferen t co nstraints in the Su-Doku problems inv o lv e v ariables having the same domain, na mely M n 2 . In addition the num b er of v ariables in a given constraint is equal to the size of their sha red domain. W e call such sp ecial a lldifferen t constra in t, p ermutations . In this section we explore a completely different appro ac h to enumerating and solving grids and puzzles based on the precedent obser v ation. Although the theoretica l bas is, going ba c k to matching theory a nd Hall’s r esults in graph theory , is the same, the resulting algor ithms will significantly differ from the ones derived from consistency - c hecking filter ing pro cedures explo red in the previous section of this pap e r . 2.1 The Exact Co v er and Exact Hit ting Set problems Definition 8 (Exact Cover) Given a family A = { A 1 , . . . ., A m } of subsets of a set X , A is c al le d an ex a ct cover of X when ∀ x ∈ X , ∃ i, 1 6 i 6 m su ch that x ∈ A i This definition has a ls o a dual for m ulation which describ es an exact hitting set . Definition 9 (Distinct Rep r esentatives) Given a family A = { A 1 , . . . ., A m } of subsets of a set X , a set of m distinct elements of X, one fr om e ach A i is c al le d a s e t of distinct repr esen tatives of A , or a hitt ing set . If the set of distinct r epr esentatives is X , it is c al le d an exa ct hitting set and A is an exact c over of X . Finding exac t hitting sets and enumerating exact hitting sets may b e solved by backtracking algor ithms. Their efficiency in this ca se r elies on the fact that a representativ e ha s a unique v alue among the p ossible ones in the A i subset and the filtering pro cedure, in the pr evious sectio n sense o f CSP s o lving, then reduces to the simple elimination of this v a lue fro m all other domains. A p ermut ation pr oblem is a co nstraint satisfac tio n problem in which each decision v a riable takes a n unique v alue, and there is the same num b er of v alues as v ariables . Hence any solution ass igns a per m utation of the v alues to the v aria bles. There ar e m ! such p ermutations for a constr ain t inv olving m v ari- ables. The imp ortant feature of p ermu tation CSP s is that we can transp ose the r oles of v alues and v ariables in representing the underlying problem to g iv e a new dual mo del whic h is a lso a per m utation problem. Ea c h v ariable in the original (pr imal) pro ble m be comes a v alue in the dual problem, and vice versa. An inje ction pr oblem is a CSP in which each decision v aria ble takes a unique v alue, and ther e are mor e v alues than v aria bles. (O b viously if there a r e fewer v alues than v ariables, the problem is trivially unsatisfiable.) 19 The prima l and the dual p ermutation pr oblems are o f cour se equiv alent, but efficient algo r ithm can leverage this transp osition by switching fr om one mo del to the other when a ppr opriate [7]. Actually the simple PS-1-2 a lgorithm describ ed in the previous section indeed used the fact that th e sp ecific alldifferent constraints in Su-Doku problems are all p erm utation problems : the so -called reduce functions transp ose v alues to v ariables, seeking to further reduce primal and dual domains when po ssible. In Su- Do ku pro ble ms , each c o nstraint is bo th a permutation and an exact hitting set problem as all v ar iables hav e the same domain. Matrix representat ion of exact hitting set and exact cov er problem s. Both exa ct hitting set a nd exact cover problem ca n be repr esen ted as follows. Given a b o olean matrix M with n rows and m columns, the problem is to find a s ubset A of the rows of M , such that each column j in M has exactly one row i ∈ A such that M i,j = 1. F or exa mple, conside r the fo llowing matrix M with n = 6 and m = 4: M =         1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0         Possible exact hitting s ets ar e { 1,3,5 } , { 2,6 } and { 3,4 } . In the ca se of p ermutation pro blems, the matrices inv olved are squar e n × n matrices. 2.2 En umeration The coun t of exact hitt ing sets is the n um b er of solutions to the constra in ts us ed in Su-Doku for m ulations. Generally sp eaking, the n umber of exact hitting sets for p ermu tation co ns train ts, i.e. in which the num b er of v alues is the same as v aria bles, is given by the p ermanent of the re pr esen tation matrix [12]. Definition 10 (Permanent) If A is an n-squar e matrix then t he p ermanent of A is define d by per A = X σ ∈ S n n Y i =1 a i,σ ( i ) wher e the summation extends over S n , t he symmetric gr oup of de gr e e n . The perma nen t is an appro priate inv ariant fo r matrices that ar is e in combi- natorial inv estigations where the pro ble m is ess e n tially unaltered by re labeling of the items under consideration, which is obviously the cas e in p ermutation problems. F or exa mple, the total num b er of derange ments (“le pro bl ` eme des rencontres”) of n distinct items is given b y p er( J − I n ) wher e J is the n-square 20 matrix with e very en try equal to 1 , and I n is the n-square iden tity matrix [16]. (This is series A0001 66 in the Online Encyclo p edia of Int eger Sequence s .) Even thoug h the p ermanent lo oks sup erficially likes the more familiar de- terminant (without the alternating ± signs), P´ olya observed that no uniform affixing of ± signs to the elements of the matrix ca n conv er t the p ermanent int o the determinant, for n > 2. The appar en t simplification of de finitio n from the determinant results co un ter-intuitiv ely in tremendous complications in the ev aluatio n of p ermanent s. In particular, a nd in contrast to the determinant, the p ermanent is no t well-behav ed under p erm utation of rows and co lumns o f the matrix; it is, how e v er, m ultilinear like the determinant. V an der W aerden’ s Conjecture. B ounds for the permanent have b een found, how ever difficult its exact computation turns out to be. Given a n -square matrix A , the i -th row sum of A is defined by r i = n X j =1 a i,j and similarly the i -th column sum of A is defined by c i = n X j =1 a i,j With these, we introduce a doubly sto chastic matrix with this definitio n. Definition 11 (Doubly Sto chastic Matrix) L et A = ( a i,j ) b e a n -squar e matr ix , then A is doubly sto chastic if 0 6 a i,j 6 1 for 1 6 i, j 6 n r i = 1 for 1 6 i 6 n c i = 1 for 1 6 i 6 n Note that the r epresentation ma trix o f an exact hitting set (or e xact c over problem) is amenable to a do ubly sto c hastic matr ix, in the case of p erm utation, by replacing each entry equa l to 1 with 1 / n . V an der W aerden made a conjecture on the low er b ound for the p e rmanen t of doubly sto c hastic matrices in 1926 [2] w hich was later proved (in 1981 ) b y Egoritchev and by F alikman as exp osed by Knuth in [8]. Theorem 1 (V an der Waer den ’s Conje ctur e) L et A b e a doubly sto chastic n - squar e matrix, then per ( A ) > n ! n n with e quality iff a i,j = 1 /n for al l 1 6 i , j 6 n . 21 Minc’s Conjecture. There is also a result for the upper b ound of the pe r - manent, due to an conjecture o riginally due to Minc [1 4]. The co njecture w as first prov ed by Br egman in 1973 a nd a simpler pr oof is due to Schrijv er [20]. Theorem 2 (Minc’s Conje ctur e) L et A b e a n -squar e matrix with values in { 0,1 } and non- z ero sums r i , per ( A ) 6 n Y i =1 ( r i !) 1 /r i There are only few matrices for which an explicit for m ula fo r the p ermanent is av a ilable, the der angement s being one instance. In fact [12], per ( z I n + J ) = n ! n X r =0 z r r ! which, for the derangements, g iv es with z = − 1 , per ( J − I n ) = n !(1 − 1 1! + 1 2! − . . . + ( − 1) n 1 n ! ) Permanen ts can b e used to ev aluate the n umber of Su-Doku grids. The sca rce results known ab out p ermanents, ho wev er, yield only information on upp er bo unds o f the num ber of g rids ra ther than their exact num be r which w as essen- tially computed by brute force in [6]. 2.3 An implemen tation of Kn uth’s “Dancing Links” algo- rithm In a famo us pa per [ ? ] Dona ld Knuth prop osed an algo rithm and a very efficient implemen tation for the exact cov er pr oblem. While the pap er expa nds on its applicatio n to pentominoes, tetr astic ks and to the queens pr oblems, the algorithm itself, which Knuth called Algorithm X “for lack of a be tter name”, has a muc h broader sco p e. Through prop er formulation o f Su-Doku gr id a nd puzzle pro blems, it proved efficie nt at enumerating grids and solving problems of v arious sizes . Knuth’s first insig ht is to p oint that the ma trix representation of the exact cov er or exact hitting set problems makes it a go o d candidate for ba c ktracking. Algorithm X is a simple expression of a generic backtrack pro cess . Kn uth’s bac ktrac ki ng algorithm for the exact hitti ng set problem. Algorithm X is a nondeterministic algor ithm, defined on a given ma tr ix A o f 0s and 1s. Citing from Knuth’s pap er: If is empty, the problem is solved; terminate successful ly. Otherw ise choo se a colu mn dete rministi cally. Choose a row such that non determin istically. 22 Includ e in the partial solutio n. For each such that , - delete column from matrix ; - for each such that , delete row fr om matrix . Repeat this algori thm recu rsively on the redu ced matr ix . The nondeterministic c hoice of a row mea ns that all s uc h rows are succes- sively (or in parallel) selected for inclusion int o the partial solutio n, the algo- rithm pro ceeding es sen tially in an independent w ay on these rows. The ch oice of the column c , on the o ther hand impa cts the execution time a nd explor ation path of the alg orithm. Any systematic rule for cho osing a column in the pro - cedure will find all solutions. Certain rules, how ever, work b etter than others. In the Su-Dok u exp eriments we studied tw o such rules : the ra ndom rule, where the column is chosen at r a ndom in the reduced matrix, and the shortest rule, where the c olumn having the sma ller num b er of 1 s is selected. While for enum era tio n tasks thes e options make no r e a l difference, as Algor ithm X in this case be haves basically as a trial and erro r pro cedure, we found that fo r puzz le s, the shor test rule alwa ys outper fo rmed the o ther one. This is also the result of exp erimen ts ra n on a nother well-known combinatorial puzzle, the Langfo r d’s problem. Kn uth’s “Dancing Links” implem en tation. In the origina l paper, Knuth also pro posed a very efficient implementation of Algorithm X based on do ubly- linked cir cular lis ts . E a c h elemen t in the matrix A is represent ed as a structured ob ject with p ointers to the previous and next element s in the same row ( left and right ), to the previo us and next elements in the s a me column ( up and d own ) and an extr a -po inter to a column header structure which keeps track of the column name, its size (the num be r of 1s) and additional metric infor mation which c a n be useful to monitor the p erformance of the algorithm. typede f s truct col { struct col *l; struct col *r; struct cell *u; struct cell *d; int size; char name[ 8]; Client DataPtr clien tData; } *colPt r; typede f s truct cell { struct cell *l; struct cell *r; struct cell *u; struct cell *d; colPtr c; 23 } *cellP tr; The l and r fields of the column headers link remaining columns in the reduced matrix which ne e d to be cov ered. Global v ar iables point t o the circula r list of columns and to the partial solution: static struct col S_Heade r; static cellPt r *S_C overing; With these data structures , the concrete implementation of Algor ithm X is as follows: search ( k ): If S_Heade r.r == S_He ader, pri nt the curr ent so lution an d return. Otherw ise choo se a colu mn str ucture . Cover column . For each row in while , - set S_Cover ing[k]= ; - for each in whi le , cover co lumn ; - search ( k+1 ); - set =S_Cove ring[k] , a nd ; - for each in whi le , uncover col umn . Uncove r c olumn a nd return. The search pro cedure is initially called with k = 0 to enumerate all so lutio ns. Knuth’s second insigh t is used to implemen t the cov er/uncov er function which are used to r emo ve and reinstall columns in the matrix. Knuth obs erved that the “atomic” remov e o pera tions in a doubly-linked cir cular list: x.r .l = x.l and x.l .r = x.r are simply reversed, provided the x data structur e is kept in tact, by the subse- quent op erations: x.r .l = x a nd x.l .r = x which will put back x in the circ ula r list. The cover op eration uses the first set of op erations to remov e a column first from the header list and then to remove a ll rows in c ’s own circula r list from the other column lists they are in: int cover( colPtr col ){ int update s = 0; /* Remov e col from heade r list */ col->r ->l = col-> l; col->l ->r = col->r ; update s++; /* Remov e all rows in col list from other col list s they are in */ cellPt r cell , rowC ell; 24 for( cell = col->d ; cell != (cellP tr)col; cel l = ce ll->d ){ for( rowCe ll = cell ->r; rowC ell != c ell; rowCell = rowCell->r ){ rowCel l->d->u = row Cell->u; rowCel l->u->d = row Cell->d; rowCel l->c->s ize - = 1; update s++; } } return update s; } The function also keeps tr ac k of counters for statistical pur poses and dec r e- men ts the column size in the header . The uncov ering op eration is symmetric, taking place in precisely the reverse or der of the covering o pera tio n: /* * uncove r - Inver se cov er */ void uncov er( colPt r col ){ /* Inser ts all row cells */ cellPt r cell , rowC ell; for( cell = col->u ; cell != (cellP tr)col; cel l = ce ll->u ){ for( rowCe ll = cell ->l; rowC ell != c ell; rowCell= ro wCell->l ){ rowCel l->c->s ize + = 1; rowCel l->d->u = row Cell; rowCel l->u->d = rowC ell; } } /* Inser ts in heade r list */ col->r ->l = col; col->l->r = col; } The disconnected then reco nnected links perform what Knuth ca lled a “dance” which gav e its na me to this implementation known as the “Dancing Links”. The running time of the algo rithm is essentially prop ortional to the num b er of times it a pplies the re move o pera tion, counted here with the updates v aria ble . It is p ossible to g et go o d estimates of the r unning time on average by running the a bov e pro cedure a few times and applying techniques describ ed els e where by Knuth [ ? ] and Hammersley and Morto n [ ? ] (so c alled “Poor Man’s Monte Carlo”). Deriving cov er m atrices from representa tion m atrices. W e now turn to the prop er for m ulation of Su-Doku q uestions for c alculations by the Dancing Links a lgorithm. Considering an elementary constr a in t in the size 2 Su-Do k u puzzle, for instance on one row o f the 4x4 g r id, its matrix repres e ntation as in 25 2.1 is simply: M =     1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1     In M each column stands for a v a riable in the alldifferent constraint; there a re four of them, one for each cell in the grid’s row under consider ation. The rows represent e a c h of the p ossible four v alues 1 , 2 . . . 4 of all these v ar iables. Remem b er that in a pe r m utation constraint all v aria ble domains a re the same and their size is equal to the num b er of v a riables, her e four . And of course, should w e b e in terested in a single p ermutation constraint, the nu mber of s olutions, which as mentioned ab ov e is expressed by the pe r manen t of this “all-1 s” matrix, is simply , in this case, the num b er of p ermutations of four element s, i.e. 4! = 2 4. Now in order to obtain the A matrix for the Danc ing Links algor ithm, we augment the matrix M with the fact that each v ar iable must hav e only o ne v alue. This is captured by four additiona l columns, one for ea ch v ariable, containing a 1 for a given (row) v alue assigned to the v ariable and 0 otherwis e: x 1 x 2 x 3 x 4 C 1 C 2 C 3 C 4 x = 1 1 0 0 0 1 0 0 0 x = 1 1 0 0 0 0 1 0 0 x = 1 1 0 0 0 0 0 1 0 x = 1 1 0 0 0 0 0 0 1 x = 2 0 1 0 0 1 0 0 0 x = 2 0 1 0 0 0 1 0 0 x = 2 0 1 0 0 0 0 1 0 x = 2 0 1 0 0 0 0 0 1 x = 3 0 0 1 0 1 0 0 0 x = 3 0 0 1 0 0 1 0 0 x = 3 0 0 1 0 0 0 1 0 x = 3 0 0 1 0 0 0 0 1 x = 4 0 0 0 1 1 0 0 0 x = 4 0 0 0 1 0 1 0 0 x = 4 0 0 0 1 0 0 1 0 x = 4 0 0 0 1 0 0 0 1 In this table the x i column is the i -th v ar iable in the C pe r m utation constra in t, the C i column repres en ts the i -th p osition in the co nstraint and each row a v alue from the sha r ed domain { 1 , 2 , 3 , 4 } . The A matrix has 8 columns a nd 16 rows. More gener ally sp eaking, for a size n p ermut ation co nstraint the A matr ix counts n 2 rows and n + n = 2 n columns. F or a complete Su-Dok u gr id, there is one such constraint per line, p er file and p er blo ck. In a ddition, v ariables are shared b e t ween constaints, each one app earing in 3 constr ain ts. Let us consider a Su-Doku of size n , which contains 26 n 4 , cells in n 2 lines by n 2 files, and n 2 blo c ks. The full size A ma trix fo r the Dancing Links alg orithm has n 4 + n 4 + n 4 + n 4 = 4 n 4 columns, one for each of the cells, and n 2 for each o f the line, file and blo c k in the grid. It also has n 6 rows, one row for each of the n 2 po ssible v alue for each of the n 4 cells. The following table indicate the matrices sizes for different Su-Doku problems: n Ma trix(ro ws × cols) 2 64 × 64 3 729 × 324 4 4096 × 1024 These sizes are small enoug h for the alg orithm to p erform satisfactor ily on mo dern P Cs. En umerating grids and solving puzzles with the “Dancing Links”. Having augmented the matr ix to prepar e it for the Dancing Links algo rithms we are now rea dy to put the algo rithm through different chores. In order to enumerate all Su- Doku v alid g r ids we simply run the searc h( 0 ) pro cedure with the appropriate A matrix as ab o ve. Of course, while the 28 8 solutions of the size 2 Su-Doku g rids are quickly en umerated, the size 3 grid tak es evidently to o long to list. Interestingly eno ugh, size 2 v aria tions o f Su-Doku grids, such as diagonal Su-Doku grids where in addition one requires that a ll nu mbers in b oth diagonals to b e different – adding tw o additional p ermutation constraints to the e x isting set, captured by 2 n 2 additional co lumns in the A matrix – can also b e en umerated by the same pro cedure. In order to solve puzzles , we need to remov e from matrix A the rows cor- resp onding to the givens in the puzzle. In our implementation, this is simply another parameter file to the comma nd line. If ther e are k such g iv ens in the puzzle, k rows are initially a dded to the pa rtial solution and the pro cedure search ( k ) is called. The a lgorithm then pro ceeds, as ab ov e, to enumerate all solutions to the puzzle. It can b e used to v alidate a puzzle, making sure that it has only one solution. 2.4 Exp erimen t ation and r esults En umerating size-2 Su-Doku grids. Running the Dancing Links algo rithm on the 64 b y 64 size-2 Su-Doku A matrix, pro duces the first o f the 2 88 solutions almost immediately: Read 64 colum ns fro m sud2.mat Read 64 rows from file sud2 .mat [16] New cove ring 1/1 in 0 secs , 0 us ecs: Depth Covers Backtr acks Degrees 0 37 1 4 1 25 1 2 2 22 1 2 3 16 1 1 27 4 28 1 3 5 16 1 1 6 19 1 2 7 10 1 1 8 10 1 1 9 16 1 2 10 10 1 1 11 7 1 1 12 16 1 2 13 10 1 1 14 7 1 1 15 7 1 1 Total 256 16 Estima tion of solut ion pa th: 7620 The sud 2.mat file is the A matrix for the size-2 Su-Doku grid. The trace table shows the depth, i.e. the v alue o f k which indicates the depth in the backtrac k tree ; the cover count, whic h is the nu mber of elementary remov e op erations in the circular lis ts; the num b e r of backtrac king steps at each depth level; a nd the degree , the num b er of c hildren no des explor ed at ea c h level. Finally the estimation of the average n umber of op erations to r each a solution is print ed acco rding to the “Po or Man’s Monte Car lo” metho d. Coun ting Su-Doku grids. The algorithm ca n b e used to co un t the num b er of Su-Doku grids, here for the size-2 grid: Read 64 colum ns fro m sud2.mat Read 64 rows from file sud2 .mat 1 1 6 7620 7620 2 1 6 7620 15240 3 1 6 5316 20556 4 1 6 5316 25872 5 1 6 7620 33492 6 1 6 7620 41112 7 1 6 7620 48732 8 1 6 7620 56352 9 1 6 5316 61668 10 16 5316 6 6984 11 16 7620 7 4604 12 16 7620 8 2224 13 16 7620 8 9844 14 16 7620 9 7464 15 16 5316 1027 80 16 16 5316 1080 96 17 16 7620 1157 16 18 16 7620 1233 36 28 19 16 7620 1309 56 20 16 7620 1385 76 21 16 5316 1438 92 22 16 5316 1492 08 23 16 7620 1568 28 24 16 7620 1644 48 25 16 7620 1720 68 26 16 7620 1796 88 27 16 5316 1850 04 28 16 5316 1903 20 29 16 7620 1979 40 30 16 7620 2055 60 31 16 7620 2131 80 32 16 7620 2208 00 33 16 5316 2261 16 34 16 5316 2314 32 35 16 7620 2390 52 36 16 7620 2466 72 37 16 5316 2519 88 38 16 7620 2596 08 39 16 7620 2672 28 40 16 7620 2748 48 41 16 7620 2824 68 42 16 5316 2877 84 43 16 5316 2931 00 44 16 7620 3007 20 45 16 7620 3083 40 46 16 7620 3159 60 47 16 7620 3235 80 48 16 5316 3288 96 49 16 5316 3342 12 50 16 7620 3418 32 51 16 7620 3494 52 52 16 7620 3570 72 53 16 7620 3646 92 54 16 5316 3700 08 55 16 5316 3753 24 56 16 7620 3829 44 57 16 7620 3905 64 58 16 7620 3981 84 59 16 7620 4058 04 60 16 5316 4111 20 61 16 5316 4164 36 62 16 7620 4240 56 63 16 7620 4316 76 64 16 7620 4392 96 29 65 16 7620 4469 16 66 16 5316 4522 32 67 16 5316 4575 48 68 16 7620 4651 68 69 16 7620 4727 88 70 16 7620 4804 08 71 16 7620 4880 28 72 16 5316 4933 44 73 16 7620 5009 64 74 16 7620 5085 84 75 16 5316 5139 00 76 16 5316 5192 16 77 16 7620 5268 36 78 16 7620 5344 56 79 16 7620 5420 76 80 16 7620 5496 96 81 16 5316 5550 12 82 16 5316 5603 28 83 16 7620 5679 48 84 16 7620 5755 68 85 16 7620 5831 88 86 16 7620 5908 08 87 16 5316 5961 24 88 16 5316 6014 40 89 16 7620 6090 60 90 16 7620 6166 80 91 16 7620 6243 00 92 16 7620 6319 20 93 16 5316 6372 36 94 16 5316 6425 52 95 16 7620 6501 72 96 16 7620 6577 92 97 16 7620 6654 12 98 16 7620 6730 32 99 16 5316 6783 48 100 16 5316 68366 4 101 16 7620 69128 4 102 16 7620 69890 4 103 16 7620 70652 4 104 16 7620 71414 4 105 16 5316 71946 0 106 16 5316 72477 6 107 16 7620 73239 6 108 16 7620 74001 6 109 16 5316 74533 2 110 16 7620 75295 2 30 111 16 7620 76057 2 112 16 7620 76819 2 113 16 7620 77581 2 114 16 5316 78112 8 115 16 5316 78644 4 116 16 7620 79406 4 117 16 7620 80168 4 118 16 7620 80930 4 119 16 7620 81692 4 120 16 5316 82224 0 121 16 5316 82755 6 122 16 7620 83517 6 123 16 7620 84279 6 124 16 7620 85041 6 125 16 7620 85803 6 126 16 5316 86335 2 127 16 5316 86866 8 128 16 7620 87628 8 129 16 7620 88390 8 130 16 7620 89152 8 131 16 7620 89914 8 132 16 5316 90446 4 133 16 5316 90978 0 134 16 7620 91740 0 135 16 7620 92502 0 136 16 7620 93264 0 137 16 7620 94026 0 138 16 5316 94557 6 139 16 5316 95089 2 140 16 7620 95851 2 141 16 7620 96613 2 142 16 7620 97375 2 143 16 7620 98137 2 144 16 5316 98668 8 145 16 7620 99430 8 146 16 7620 100 1928 147 16 5316 100 7244 148 16 5316 101 2560 149 16 7620 102 0180 150 16 7620 102 7800 151 16 7620 103 5420 152 16 7620 104 3040 153 16 5316 104 8356 154 16 5316 105 3672 155 16 7620 106 1292 156 16 7620 106 8912 31 157 16 7620 107 6532 158 16 7620 108 4152 159 16 5316 108 9468 160 16 5316 109 4784 161 16 7620 110 2404 162 16 7620 111 0024 163 16 7620 111 7644 164 16 7620 112 5264 165 16 5316 113 0580 166 16 5316 113 5896 167 16 7620 114 3516 168 16 7620 115 1136 169 16 7620 115 8756 170 16 7620 116 6376 171 16 5316 117 1692 172 16 5316 117 7008 173 16 7620 118 4628 174 16 7620 119 2248 175 16 7620 119 9868 176 16 7620 120 7488 177 16 5316 121 2804 178 16 5316 121 8120 179 16 7620 122 5740 180 16 7620 123 3360 181 16 5316 123 8676 182 16 7620 124 6296 183 16 7620 125 3916 184 16 7620 126 1536 185 16 7620 126 9156 186 16 5316 127 4472 187 16 5316 127 9788 188 16 7620 128 7408 189 16 7620 129 5028 190 16 7620 130 2648 191 16 7620 131 0268 192 16 5316 131 5584 193 16 5316 132 0900 194 16 7620 132 8520 195 16 7620 133 6140 196 16 7620 134 3760 197 16 7620 135 1380 198 16 5316 135 6696 199 16 5316 136 2012 200 16 7620 136 9632 201 16 7620 137 7252 202 16 7620 138 4872 32 203 16 7620 139 2492 204 16 5316 139 7808 205 16 5316 140 3124 206 16 7620 141 0744 207 16 7620 141 8364 208 16 7620 142 5984 209 16 7620 143 3604 210 16 5316 143 8920 211 16 5316 144 4236 212 16 7620 145 1856 213 16 7620 145 9476 214 16 7620 146 7096 215 16 7620 147 4716 216 16 5316 148 0032 217 16 7620 148 7652 218 16 7620 149 5272 219 16 5316 150 0588 220 16 5316 150 5904 221 16 7620 151 3524 222 16 7620 152 1144 223 16 7620 152 8764 224 16 7620 153 6384 225 16 5316 154 1700 226 16 5316 154 7016 227 16 7620 155 4636 228 16 7620 156 2256 229 16 7620 156 9876 230 16 7620 157 7496 231 16 5316 158 2812 232 16 5316 158 8128 233 16 7620 159 5748 234 16 7620 160 3368 235 16 7620 161 0988 236 16 7620 161 8608 237 16 5316 162 3924 238 16 5316 162 9240 239 16 7620 163 6860 240 16 7620 164 4480 241 16 7620 165 2100 242 16 7620 165 9720 243 16 5316 166 5036 244 16 5316 167 0352 245 16 7620 167 7972 246 16 7620 168 5592 247 16 7620 169 3212 248 16 7620 170 0832 33 249 16 5316 170 6148 250 16 5316 171 1464 251 16 7620 171 9084 252 16 7620 172 6704 253 16 5316 173 2020 254 16 7620 173 9640 255 16 7620 174 7260 256 16 7620 175 4880 257 16 7620 176 2500 258 16 5316 176 7816 259 16 5316 177 3132 260 16 7620 178 0752 261 16 7620 178 8372 262 16 7620 179 5992 263 16 7620 180 3612 264 16 5316 180 8928 265 16 5316 181 4244 266 16 7620 182 1864 267 16 7620 182 9484 268 16 7620 183 7104 269 16 7620 184 4724 270 16 5316 185 0040 271 16 5316 185 5356 272 16 7620 186 2976 273 16 7620 187 0596 274 16 7620 187 8216 275 16 7620 188 5836 276 16 5316 189 1152 277 16 5316 189 6468 278 16 7620 190 4088 279 16 7620 191 1708 280 16 7620 191 9328 281 16 7620 192 6948 282 16 5316 193 2264 283 16 5316 193 7580 284 16 7620 194 5200 285 16 7620 195 2820 286 16 7620 196 0440 287 16 7620 196 8060 288 16 5316 197 3376 Found 288 cover ings in 0 secs , 2000 0 usecs Averag e Esti mation on 288 pa ths: 6852 The first column prints the solution’s nu mber, the second the depth reached (alwa ys 16 for siz e - 2 gr id), the third one the estimation o f the tree size, and the 34 last one the cumulated estimation used to provide the average on the la st line. Here, in av erage, 6 852 no des are explored in the backtrack tree problem space. F urther results. The Da ncing Links implementation makes it very easy to exp erimen t with several v ar iations of the Su-Do k u g rids and puzzles . Adding further constraints to the problem is simply a ma tter of a dding columns to the A matrix used by the algo rithm. In the diagonal v a riant, for instance, where a Su-Doku grid is co nsidered v alid if, in a ddition, all num b ers in b oth diag onals are also different, 2 n columns are added to the A matrix to account for the n po ssible p ositions of ea c h 1 . . . n 2 figure in each diag o nal. In this v a riant , running the Dancing Links for enumeration yields the 4 8 unique so lutions for a size 2 diag onal Su-Doku problem (a 4- b y-4 grid) and an av erage of 36 66 no des explored in the backtrack tree pr oblem space. Note that the exploratio n space/time complexity is roug hly halved on this ins tance. On a different tra c k, the Dancing Links a lgorithm was successfully used for exp erimen ting with the La ngford problems which combinatorial nature, ulti- mately re lying on p ermutation constraints, lends it p erfectly to Dancing Links- based study . References [1] Bela Bo llo bas. Mo dern Gr aph The ory , volume 18 4 of Gr aduate T exts in Mathematics . Springer, 1998. [2] Richard Brua ldi. Bo ok reviews, pe rmanen ts by henr yk minc. Bul letin of the Ameri c an Mathematic al So ciety , 1(6):965– 973, Nov ember 1 979. [3] D. Dia z and P . Co dognet. Co mpiling cons tr ain ts in c lp(fd). 19 96. [4] Daniel Diaz. Gnu-prolog. Web site , http://www.gprolog.o rg/ , 19 96. [5] Niklas Een and Niklas Sorensso n. An extensible sat s o lv er. Pr eprint , ht tp://minisa t.s e / do wnloads / MiniSat.ps.gz , 2003. [6] Bertr am F elg enhauer and F ra zer Jarvis. Enu- merating po ssible sudoku grids. Pr eprint , ht tp://www.a fjarvis.staff.shef.ac.uk/sudok u/felgenhauer jarvis sp ec1.pdf, 2005. [7] Bra him Hnic h, Barbar a M. Smith, and T ob y W alsh. Dual mo delling o f per m utation and injection pr oblems. Journal of Artificial Intel ligenc e Re- se ar ch , 21:3 57–391 , 2004. [8] Donald E. Knuth. A p ermanent inequality . The Ameri c an Mathematic al Monthly , 88(10 ):7 31–740, December 198 1. [9] M. Leco n te. A b ounds-based reduction s cheme for co nstraints of differ- ence. In Pr o c e e dings of Constr aint 96, Se c ond International Workshop on Constr aint- b ase d Re asoning , pa ges 1 9–28, 19 96. 35 [10] Chu Min L i, F elip Ma n ya, and Jordi Planes. New inference rules for max- sat. J ournal of Artificial Intel ligenc e R ese ar ch , 30:32 1–359, 2 007. [11] A. Lo pez-O rtiz, C.-G. Quimper , J. T romp, a nd P . v an Beek. A fast a nd simple algor ithm fo r b ounds consistency of the alldifferent constra in t. In IJCAI, editor, P r o c e e dings of the Eighte ent h International Joint Confer enc e on Artificia l Int el ligenc e (IJCAI ’03) . IJCAI, 2003 . [12] Marv in Marcus and Henry k Minc. Permanents. The Ameri c an Mathemat- ic al Monthly , 7 2(6):577–5 9 1, June 196 5. [13] Kurt Mehlho rn a nd Sven Thiel. F aster algo r ithms for b ound-consistency of the s ortedness and the alldifferent constr ain t. In CP ’02: Pr o c e e dings of the 6th International Confer en c e on Principles and Pr actic e of Constr aint Pr o gr amming , pages 306–3 19, London, UK, 2000. Springer-V erlag. [14] Henryk Minc. Upp er b ounds for p ermanent of (0,1)-matrices . Bu l letin of the Ameri c an Mathematic al So ciety , 69:789 –791, 1963 . [15] Peter Norv ig . Solving every sudoku puzzle. Pr eprint , ht tp://nor vig.com/sudoku.html , 2006. [16] Stephen G. Penrice. Derangements, pe r manen ts, and christmas pr esen ts. The Americ an Mathematic al Monthly , 98(7 ):6 17–620, August 1991 . [17] J.-F. Puget. A fast algo rithm for bound consistency of alldiff constraints. In Pr o c e e dings of the Fifte ent h National Confer enc e on Artificial Intel ligenc e (AAAI ’98) , pages 359 –366. AAAI, 1998. [18] Jean- Charles R ´ egin. A filtering algor ithm for co ns train ts of difference in csps. In AAAI ’94: Pr o c e e dings of the twelfth national c onfer enc e on Ar- tificial intel ligenc e (vol. 1) , pages 362 –367, Menlo Park, CA, USA, 19 94. American Asso ciation for Artificial Intelligence. [19] Gordo n Royle. M inimu sudoku. Pr eprint , ht tp://p eople.csse.uw a.edu.au/ gordon/sudo k umin.php , 2006 . [20] A. Schrijver. A short pro of of minc’s conjecture. Journal of Combinatorial The ory , (25):80–8 3, 1978. [21] W.J. v an Ho ev e. The alldifferent constra in t: A survey . In 6th Annual Workshop of t he ERCIM Working Gr oup on Constr aints , June 200 1. 36

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment