on the hardness of framed edge-matching puzzles · 2016. 6. 28. · matching puzzles by looking at...

18
On the Hardness of Framed Edge-Matching Puzzles Dasyel Willems 10172548 Bachelor thesis Credits: 18 EC Bachelor Opleiding Kunstmatige Intelligentie University of Amsterdam Faculty of Science Science Park 904 1098 XH Amsterdam Supervisor Dhr. drs. Daan van den Berg Faculty of Science University of Amsterdam Science Park 904 1098 XH Amsterdam June 24th, 2016

Upload: others

Post on 21-Aug-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

On the Hardness of FramedEdge-Matching Puzzles

Dasyel Willems10172548

Bachelor thesisCredits: 18 EC

Bachelor Opleiding Kunstmatige Intelligentie

University of AmsterdamFaculty of ScienceScience Park 904

1098 XH Amsterdam

SupervisorDhr. drs. Daan van den Berg

Faculty of ScienceUniversity of Amsterdam

Science Park 9041098 XH Amsterdam

June 24th, 2016

Page 2: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Abstract

This research focusses on the hardness of two-set Framed Generic Edge-Matching Puzzles bysetting the amount of colours in both sets against the median iterations needed to solve the puzzleswith multiple differing CSP-solver algorithms. The research is heavily based on research done by

Ansotegui et al. and tries to either verify or falsify their results. The final results hint towards aconnectivity based property of Generic Edge-Matching Puzzles as a main influence on thehardness of those puzzles, while the dissimilarities between the final results and those by

Ansotegui et al raise questions about their methodology and conclusions.

1

Page 3: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

1 Introduction

The interest for Generic edge-matching puzzles(GEMP) research spiked due to the introductionof the Eternity II puzzle and its accompanyingreward of two-million dollars for finding a solu-tion. The solution to the puzzle has not yet beenfound, at the time of writing, which means thatGEMP are computationally very hard puzzles.GEMP, similar to jigsaw puzzles and polyominopacking puzzles, are NP-Complete problemsas proven by Demaine et al.[4], meaning thatGEMP belong to both NP and NP-hard com-plexity classes, making it possible to check asolution for validity in polynomial time, whilefinding a solution is mostly not achievable inpolynomial time unless P=NP. In addition, NP-Complete problems are, by definition, reducibleto other NP-Complete problems.This reducibility property has made GEMP a no-table subject for research.

Figure 1: An example of a partially solved 4x4Two-Set GEMP-F with 3 outer-colours and 4inner-colours

Figure 2: Examples of a One-Set GEMP-F (left)and a Two-Set GEMP-F (right) accentuating thedivision between the color sets.

1.1 One-set and Two-set GEMP-F

GEMP are puzzles of size N×M , which consistof a set of N×M square tiles. All four sides of atile have a colour. Each of the tiles is then placedon an N ×M grid, such that no two neighbour-ing tiles have different colours on their matchingsides. Framed Generic Edge-Matching Puzzles(GEMP-F) have an extra constraint of forcingone colour for the outermost sides of the N×Mgrid. The frame colour may not be assigned toany of the other edges within a GEMP-F.In addition to these classifications and con-straints for GEMP an extra distinction is madebetween one-set and two-set GEMP problems.One-set GEMP, as the name implies, use one setof colours for all edges. While two-set GEMPuse two non-overlapping sets of colours whereone set is applied to the touching sides of eachset of neighbouring tiles on the edge of the grid,and the other set is used for the inner edges (seefigure 2).

1.2 CSP-solvers vs. SAT-solvers

GEMP are Constraint-Satisfaction Problems(CSP), meaning that a solution for a CSP hasbeen found when all imposed constraints aresatisfied within the current state. A way to solve

2

Page 4: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

any CSP is by using a CSP-solver, which arealgorithms specifically designed to simulate theproblem or puzzle. The states of the problem arethen changed by the solver until all constraintsare satisfied.

Another approach to solving CSP is by us-ing SAT-solvers, which solve for a satisfactionof a logical formula as shown by Niklas Een etal.[6][5]. These formulas are mostly providedto the solver in the Conjunctive Normal-Form(CNF) or the Disjunctive Normal-Form (DNF).The crux with using SAT-solvers is the con-version from a CSP to either a CNF- or DNFformula. For GEMP-F there is currently noknown best conversion and different methodsresult in differing SAT-solver performances.

1.3 Approximate Solutions

Edge-matching puzzles can either be solved foran exact solution or for a partial solution. TheEternity II puzzle, which is a still unsolved16x16 two-set GEMP-F, has been a resource-ful subject for researching approximation tech-niques for solving GEMP-F. Wauters et al.[7]have given an extensive report on a set of theseapproximation heuristics, which focus on opti-mizing a partial solution for the Eternity II puz-zle and which have been awarded for being themost efficient and best achieving approximationheuristics.In addition to this report, Antoniadis et al.[2]have shown that finding an approximate solu-tion is APX-Complete, which means that find-ing an approximate solution is both in the APXand the APX-Hard complexity classes. This, inturn, means that finding an approximate solutionwith an error of at most a given constant c, can-not be done in polynomial time for every valuefor c higher than zero.

1.4 Exact Solutions

As opposed to looking at approximations,Ansotegui et al.[1] have researched the hardnessof finding exact solutions for framed edge-matching puzzles by looking at both one-set andtwo-set square GEMP-F problems (sized 7 × 7and 8 × 8). The research was conducted byvarying the amount of inner- and outer-coloursof generated GEMP-F and solving them withboth SAT- and CSP-solvers. Results of theexperiments imply that the hardest medianpuzzles for an N × N one-set GEMP-F liesaround N − 1 colours, while the hardest medianpuzzles for a 7× 7 two-set puzzle lies around 7inner-colours and 3 outer-colours.

The focus of this research paper is to ver-ify or falsify the findings of Ansotegui et al.by running multiple differing CSP-solver algo-rithms on sets of square GEMP-F ranging from5 × 5 to and including 7 × 7. The results willthen be compared between different algorithmsto find general conclusions.

2 Method

The aim of this research is to reproduce the re-sults on two-set GEMP-F found by Ansotegui etal. This research is split into two major steps.To start off, a set of two-set GEMP-F is gener-ated for each of the sizes: 5x5, 6x6 and 7x7.Afterwards these sets of puzzles are solved withmultiple CSP-solvers.

2.1 GEMP-F Generator

A generator for GEMP-F puzzles has beenimplemented according to the algorithm givenby Ansotegui et al.[1]. Each set of two-setGEMP-F generated exists of 20 puzzles per

3

Page 5: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

possible inner-colour- and outer-colour amountcombination. The amount of edges in an NxNpuzzle take on the following values:

Etotal = 2N2 − 2N (1)

Eouter = 4(N − 1) (2)

Einner = Etotal − Eouter (3)

Where Etotal is the number of total edges inthe puzzle excluding the edges assigned to theframe, Eouter is the number of outer edges andEinner is the number of inner edges of the puz-zle. The outer-colours can range from 1 up toEouter, with the upper bound resulting in a dif-ferent colour for each outer vertex. The sameapplies to the inner-colours with the Einner asthe upper bound.No uniqueness and rotation-invariance forpieces within puzzles was taken into account.Also no inter-puzzle uniqueness was checkedfor the eventually generated sets. Both measureswere omitted due to Ansotegui et al. not men-tioning using these measures.

2.2 GEMP-F CSP-solvers

Some different algorithms and heuristics wereimplemented to solve the same sets of GEMP-F for eventual comparison purposes and testingthe robustness of the results by Ansotegui et al.

Simple Depth-First

A basic depth-first algorithm was implemented,which solves the puzzle in a single, statictraversal-order, namely left-to-right and top-to-bottom. The solver checks for available pieceswhich fit in the next index in the puzzle andplaces each of them in no particular order ev-ery time the algorithm backtracks to that index.When no pieces are available for a given index,

the algorithm backtracks to the previous index.Once a solution is found, the algorithm stopsand returns the solution. Even though the orderof placing possible pieces for each index is notordered, the algorithm does filter for duplicatepieces to prevent extraneous results due to therepeat of previously checked paths in the search-space.

Connectivity Based Heuristics

Cheeseman et al.[3] have researched the hard-ness of finding a Hamilton-Circuit in graphsusing depth-first search extended with theheuristic to start at the node with the highestconnectivity and to keep advancing to the nextavailable node with the highest connectivity.This connectivity of nodes is defined as thepossible nodes the path can traverse to fromthe current node. As GEMP-F and findingHamilton-Circuits are both NP-Completeproblems, the heuristic to choose the highestconnectivity first has a chance of provingbeneficial for finding solutions to GEMP-F. Analgorithm was implemented, which still followsthe same direction as the simple depth-firstalgorithm, enhanced with the heuristic to sortthe available pieces for the next index in thepuzzle by their connectivity. In this heuristicthe connectivity of a piece is measured by theamount of available neighbour piece edgeswhich can be placed against the right side ofthe piece. Notice that this definition for piececonnectivity is rather naive, as it does not takeinto account the possible connections on thetop, bottom and left side of a piece. This naivedefinition was, however, chosen to fit best withthe Simple Depth-First traversal order.

The puzzles are also solved with the in-verse of this heuristic, which prefers pieces with

4

Page 6: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

the lowest connectivity instead, as this methodwill intuitively eliminate possible pieces forindices faster.

Smallest Number of Possible Pieces First(SNOPF)

An algorithm close to the PLA heuristic usedby Ansotegui et al. was implemented. The im-plemented algorithm keeps track of the possiblepieces for each index in the puzzle. Each timea piece is added to the puzzle, the neighbour-ing indices are updated, eliminating all piecesno longer possible for that specific index. Piecesare eliminated, based on the side-colours ofneighbouring matching pieces. The last placedpiece is effectively eliminated from all indices inthe puzzle as it is no longer available. The orderthe algorithm goes through the indices is basedon the number of available pieces for each index,which is measured each time after the elimina-tion step. The index with the smallest numberof possible pieces is then chosen as the next in-dex to place a piece on. The possible pieces foreach index in the puzzle is not ordered by anymeasures.

3 Results

The use of the CSP-solver algorithms on theGEMP-F sets resulted in the graphs found inAppendix A. Due to minimal differences be-tween both Cheeseman solvers and the simpledepth-first solver, only the simple depth-first andthe SNOPF algorithm results are shown in thissection (see figures 3 and 4). Each graph showsthe median iterations needed per combination ofinner- and outer-colours. The median is basedon the needed iterations to solve 20 puzzles foreach data-point.Table 1 shows where the exact peaks are located

in the plots together with the median iterationsmeasured at that peak. Note that the iterationlimit for the 7x7 GEMP-F sets are lower thanthe limits for the 5x5 and 6x6 sets, due to timeconstraints after the last limit increase. The timeto solve the full set of 7x7 two-set GEMP-Fwith a limit of two-million iterations using theSimple Depth-First algorithm increased the to-tal solve time to 136,456.79 seconds as opposedto 53,208.03 seconds with a limit of half a mil-lion, while still no single peak location could bepinpointed. The results for the 7x7 puzzles are,however, included in appendix A as the graphsstill show meaningful data.Table 1 shows that the Lowest Connectivity Firstalgorithm performs the best on both the 5x5 and6x6 sets as its highest peak in the median valuesis significantly lower than the peaks of the otheralgorithms and the total time to solve all puzzlesin the set is lower too.There is no apparent connection between thepeak-locations in table 1, as the locations differgreatly between the different algorithms. Themedian iteration values around the peaks do,however, have overlapping areas.

4 Conclusion and Discussion

The main focus of this research was to verify orfalsify the results on two-set GEMP-F, found byAnsotegui et al. in their research on GEMP-F.This was done by submitting randomly gen-erated solvable two-set GEMP-F to a set ofdifferent CSP solvers. The differences andsimilarities between the performances of theCSP-solvers should imply intrinsic propertiesof the two-set GEMP-F puzzles.The results by Ansotegui et al. showed that7x7 two-set GEMP-F have a single symmetricaland distinguished peak of measured median

5

Page 7: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

(a) Simple Depth-First

(b) Smallest Number of Pieces First

Figure 3: Results of solving the 5x5 two-set GEMP-F set with two distinguished algorithms.

6

Page 8: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

(a) Simple Depth-First

(b) Smallest Number of Pieces First

Figure 4: Results of solving the 6x6 two-set GEMP-F set with two distinguished algorithms.

7

Page 9: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Max MedianValue

Inner-Colours Outer-Colours Iterations Limit Total Solve-Time(seconds)

Simple Depth-First 5x5 2,829 5 3 2,000,000 68.90SNOPF 5x5 6,185 5 1 2,000,000 75.30

Highest Connectivity First 5x5 4,619 4 3 2,000,000 86.26Lowest Connectivity First 5x5 2,579 23 1 2,000,000 67.23

Simple Depth-First 6x6 2,000,000 7 2 2,000,000 11,876.86SNOPF 6x6 2,000,000 2 7 2,000,000 18,454.05

Highest Connectivity First 6x6 913,158 3 9 2,000,000 15,957.48Lowest Connectivity First 6x6 228,980 6 2 2,000,000 10,700.64

Simple Depth-First 7x7 500,000 multiple multiple 500,000 53,208.03SNOPF 7x7 500,000 multiple multiple 500,000 63,718.49

Highest Connectivity First 7x7 500,000 multiple multiple 500,000 63,715.66Lowest Connectivity First 7x7 500,000 multiple multiple 500,000 56,642.75

Table 1: Median iterations peak locations and heights

solve-time, whereas the results of this researchshow that the peak of 5x5 and 6x6 two-setGEMP-F is not symmetrically shaped. The7x7 puzzle-set results also indicate an irregularpeak neighbourhood, even though the limiton the amount of iterations was too small topinpoint the exact peak. A second notabledifference between the results of this researchin comparison to the results by Ansotegui et al.,is the hardness of puzzles with outer-colours=1.Where they have found that those puzzles arefairly easy in the neighbourhood of the mediansolve-time peak, while this research has found aconsistent hardness on those puzzles around thepeaks.These differences in results might be caused bythe different approaches the CSP solvers taketo solve GEMP-F problems. The similaritiesbetween the Simple Depth-First algorithmgraphs and the graphs of the connectivitybased algorithms support this claim, as thesealgorithms are similar in traversal order, whilethe SNOPF algorithm, which shows a moresymmetric peak region, is closer to the PLAalgorithm Ansotegui et al. used. Another reasonfor the differing results may be the fact that

Ansotegui et al. measured their solve-time inseconds while this research used the more stablemeasure of iterations which does not depend onthe efficiency of implemented algorithms or cpufluctuations.While the peaks for the 5x5 and 6x6 puzzlemedian solve-times differ between the differentsolving algorithms, the immediate surroundingarea of the peaks, with values close to the peakvalue, seem to overlap on the area denoted bythe peak found by Ansotegui et al. This mayindicate that two-set GEMP-F do have a singlehardest combination of inner- and outer-colours,while the generated puzzle sets in this researchwhere either too small or not sampled wellenough to undermine outliers.

The performance results of the CSP solversused in this research (Table 1) show thatthe Lowest Connectivity First algorithm issignificantly faster iterations-wise at solvingtwo-set GEMP-F. The median iterations graphof that algorithm (figure 12) compared to theSNOPF algorithm graph (figure 10) shows thatthe SNOPF algorithm performs better at inner-and outer-colour combinations further away

8

Page 10: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

from the epicentre/peak of the graphs. As theSNOPF algorithm differs mostly in traversalorder as compared to the other algorithms, ahybrid solver based on both connectivity andadaptable traversal-order might prove to be amore efficient solver than the ones presented inthis research.The efficiency of the Lowest Connectivity Firstalgorithm might imply the influence of averageinter-piece connectivity on the hardness ofGEMP-F. The inner- and outer-colour valueswhich define the hardest puzzles may actuallyhave higher chances on generating the hardernumber of average connectivity. As correlationdoes not necessarily mean causation, changingthe focus to average connectivity instead ofinner- and outer-colours might prove interestingfor future research.Another point of critique, which may be usefulin future research, is the fact that this research,just like the research by Ansotegui et al., didnot take into account the occurrence of rotationinvariant or duplicate pieces, as well as puzzleduplicates, in the puzzle-set generation process.These factors do affect the search-space ofpuzzle solutions significantly.

To summarize; Grasping the hardness ofgeneric edge-matching puzzles proves to be ahard problem itself.

References

[1] Carlos Ansotegui, Ramon Bejar, CesarFernandez, and Carles Mateu. Princi-ples and Practice of Constraint Program-ming: 14th International Conference, CP2008, Sydney, Australia, September 14-18,2008. Proceedings, chapter Edge Match-ing Puzzles as Hard SAT/CSP Benchmarks,

pages 560–565. Springer Berlin Heidelberg,Berlin, Heidelberg, 2008.

[2] Antonios Antoniadis and Andrzej Lingas.SOFSEM 2010: Theory and Practice ofComputer Science: 36th Conference onCurrent Trends in Theory and Practiceof Computer Science, Spindleruv Mlyn,Czech Republic, January 23-29, 2010.Proceedings, chapter Approximability ofEdge Matching Puzzles, pages 153–164.Springer Berlin Heidelberg, Berlin, Heidel-berg, 2010.

[3] Peter Cheeseman, Bob Kanefsky, andWilliam M Taylor. Where the really hardproblems are. In IJCAI, volume 91, pages331–340, 1991.

[4] Erik D. Demaine and Martin L. Demaine.Jigsaw puzzles, edge matching, and poly-omino packing: Connections and complex-ity. Graphs and Combinatorics, 23(1):195–208.

[5] Niklas Een and Armin Biere. Theoryand Applications of Satisfiability Testing:8th International Conference, SAT 2005,St Andrews, UK, June 19-23, 2005. Pro-ceedings, chapter Effective Preprocessing inSAT Through Variable and Clause Elimina-tion, pages 61–75. Springer Berlin Heidel-berg, Berlin, Heidelberg, 2005.

[6] Niklas Een and Niklas Sorensson. The-ory and Applications of Satisfiability Test-ing: 6th International Conference, SAT2003, Santa Margherita Ligure, Italy, May5-8, 2003, Selected Revised Papers, chapterAn Extensible SAT-solver, pages 502–518.Springer Berlin Heidelberg, Berlin, Heidel-berg, 2004.

9

Page 11: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

[7] Tony Wauters, Wim Vancroonenburg, andGreet Vanden Berghe. A guide-and-observehyper-heuristic approach to the eternity iipuzzle. Journal of Mathematical Modellingand Algorithms, 11(3):217–233, 2012.

10

Page 12: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Appendix A: Result Graphs

The following pages show all median solve iterations graphs for the 5x5, 6x6 and 7x7 two-setGEMP-F sets. Note that the iteration limit for solving the 5x5 and 6x6 puzzle sets lies on twomillion iterations, while the limit for the 7x7 puzzle set lies on half a million iterations.

Figure 5: Median iterations for 5x5 Simple Depth-First

11

Page 13: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 6: Median iterations for 5x5 Smallest Number of Pieces First

Figure 7: Median iterations for 5x5 Highest Connectivity First

12

Page 14: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 8: Median iterations for 5x5 Lowest Connectivity First

Figure 9: Median iterations for 6x6 Simple Depth-First

13

Page 15: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 10: Median iterations for 6x6 Smallest Number of Pieces First

Figure 11: Median iterations for 6x6 Highest Connectivity First

14

Page 16: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 12: Median iterations for 6x6 Lowest Connectivity First

Figure 13: Median iterations for 7x7 Simple Depth-First

15

Page 17: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 14: Median iterations for 7x7 Smallest Number of Pieces First

Figure 15: Median iterations for 7x7 Highest Connectivity First

16

Page 18: On the Hardness of Framed Edge-Matching Puzzles · 2016. 6. 28. · matching puzzles by looking at both one-set and two-set square GEMP-F problems (sized 7 7 and 8 8). The research

Figure 16: Median iterations for 7x7 Lowest Connectivity First

17