# Research Article alldifferent -Tabu Search Algorithm for ... ?· A Hybrid alldifferent -Tabu Search…

Post on 28-Jun-2018

212 views

TRANSCRIPT

Research ArticleA Hybrid alldifferent-Tabu Search Algorithm forSolving Sudoku Puzzles

Ricardo Soto,1,2,3 Broderick Crawford,1,4,5 Cristian Galleguillos,1

Fernando Paredes,6 and Enrique Norero7

1Pontificia Universidad Catolica de Valparaso, 2362807 Valparaso, Chile2Universidad Autonoma de Chile, 7500138 Santiago, Chile3Universidad Cientifica del Sur, Lima 18 Lima, Peru4Universidad Central de Chile, 8370178 Santiago, Chile5Universidad San Sebastian, 8420524 Santiago, Chile6Escuela de Ingeniera Industrial, Universidad Diego Portales, 8370109 Santiago, Chile7Facultad de Ingeniera, Universidad Santo Tomas, 2561694 Vina del Mar, Chile

Correspondence should be addressed to Cristian Galleguillos; cgalleguillosm@ieee.org

Received 7 January 2015; Accepted 24 April 2015

Academic Editor: Christian W. Dawson

Copyright 2015 Ricardo Soto et al. This is an open access article distributed under the Creative Commons Attribution License,which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

The Sudoku problem is a well-known logic-based puzzle of combinatorial number-placement. It consists in filling a 2 2 grid,composed of columns, rows, and subgrids, each one containing distinct integers from 1 to 2. Such a puzzle belongs to the NP-complete collection of problems, to which there exist diverse exact and approximate methods able to solve it. In this paper, we pro-pose a new hybrid algorithm that smartly combines a classic tabu search procedure with the alldifferent global constraint fromthe constraint programming world. The alldifferent constraint is known to be efficient for domain filtering in the presence ofconstraints that must be pairwise different, which are exactly the kind of constraints that Sudokus own.This ability clearly alleviatesthe work of the tabu search, resulting in a faster andmore robust approach for solving Sudokus.We illustrate interesting experimen-tal results where our proposed algorithm outperforms the best results previously reported by hybrids and approximate methods.

1. Introduction

The Sudoku puzzle is a combinatorial problem consisting ofassigning 2 digits, from 1 to 2, in each cell matrix of size2

2. The matrix is composed of 2 rows, 2 columns, and2 subgrids of size , as shown in Figure 1.The problemhas a set of simple rules; in each region every

digit must be assigned only one time, and hence all digitsmust be assigned in each cell of each region. Any digit will berepeated 2 times scattered across the grid but not repeatedin same rows, columns, and subgrids. The common size ofSudoku is = 3; thus the puzzle is defined as a 9 9 matrixwith nine 3 3 subgrids. Each Sudoku instance starts withsome values, called the givens and the difficulty of the puzzledepends on the positioning of those givens along the matrix.An instance has a unique solution if it contains at least 17givens [1].

During the last years, Sudokus have appeared as interest-ing problems to test constraint satisfaction and optimizationalgorithms because of their NP-completeness and differentmodeling capabilities. In this context, several approachesfrom different domains have been proposed. For instance,exact methods such as constraint programming [2, 3] andSAT [4] are in general efficient techniques to solve Sudokus.On the approximate methods domain, metaheuristics haveproven to be efficient as well [5, 6]. Some hybrids combiningexact and approximate methods have also been reported[7, 8], as well as techniques such as Sinkhorn balancing [9],rewriting rules [10], and entropy minimization [11].

In this work, we introduce a new hybrid that smartlyintegrates a global constraint, namely, the alldifferentconstraint, in a classic tabu search procedure. Thealldifferent constraint comes from the constraint

Hindawi Publishing CorporationComputational Intelligence and NeuroscienceVolume 2015, Article ID 286354, 10 pageshttp://dx.doi.org/10.1155/2015/286354

2 Computational Intelligence and Neuroscience

1

14

1

1

2

2

3

3

3

3

5

5

6

6

7

7

7

4

8

8

9

9

9

Subgrid Column

Row

Figure 1: Sudoku puzzle instance: AI Escargot.

programming world and has specially been designed forthe efficient domain reduction of variables involved inconstraints that must be pairwise different. This globalconstraint works perfectly for Sudokus since all the puzzleconstraints can be expressed as a pairwise comparison. Weimplement the alldifferent constraint following Pugetsapproach [12], which identifies Hall intervals [13] and thenfilters the domains. This allows one to efficiently propagatethe constraints, considerably reducing the search space andalleviating the work of the tabu search. As a consequence, thesearch process is accelerated, while the quality of solutionsis maintained. We illustrate interesting experimental resultswhere our proposed algorithm outperforms the best resultsreported in the literature.

This paper is organized as follows. In Section 2, wedescribe the previous work. Section 3 presents the classictabu search. The alldifferent constraint is presented inSection 4. The proposed algorithm is presented in Section 5,followed by the corresponding experimental results. Finally,we conclude and give some directions for future work.

2. Related Work

In this paper, we concentrate on incomplete search methods,specially on solving hard instances of the puzzle. Within thisscenario, different approaches have been suggested, mainlybased on metaheuristics. For instance, in [14], the Sudokupuzzles aremodeled as a combinatorial optimization problemwhere the objective function is the minimization of theincorrectly placed numbers on the board.Thepreviousmodelis solved by using simulated annealing, but the approachis mostly focused on producing valid Sudokus than on theperformance of the resolution. In [15], where a particleswarm optimizer (PSO) for solving Sudokus is presented,the goal of authors was to validate the use of geometricoperators for PSO for complex combinatorial spaces. In [5],a classic genetic algorithm is tuned with similar geometricoperators, particularly Hamming space crossovers and swapspace crossovers, reporting good solutions for a hard Sudoku

instance. In [16], another GA is presented improving theselection, crossover, and mutation operators. They achievea better convergence rate and stability with respect to theclassic GA. In [8], a hybrid combining AC3 and tabu searchis reported, where the idea is to apply AC3 at each iteration ofthemetaheuristic in order to systematically attempt to reducethe variable domains.A similar approachusing cuckoo searchis presented in [7], but the AC3 is only employed as apreprocessing phase.

In [17], the alldifferent constraint is used to reducevariable domains by overlapping the 27 Sudoku constraints.The approach succeeds for easy instances and some otherones, but in more complex instances the solution is reachedwith a complete search solver. In Section 6, a comparisonof the proposed algorithm with respect to the best resultsreached by hybrids and approximate methods is given.

3. Tabu Search

Tabu search (TS), introduced by Glover [18, 19], is a meta-heuristic mainly concerned with combinatorial optimizationproblems. TS has successfully been employed for workingon different kind of real-life problems as well as problemsfrom operation research and computer science, such as thetraveling salesman problem, the knapsack problem, and thetimetabling problem.

TS is based on local search over single solutions, employ-ing a given solution as a start point. Then, this startingsolution will be improved across small changes, being thosesolutions called neighbors of , iteratively until somestopping criterion has been reached. The local search movesfrom neighbor to neighbor as long as possible according to aminimization/maximization of a defined objective function.Normally there exist problemswith somemoves so that maybe trapped in local optimum where the local search cannotfind any further neighborhood solution.

To tackle the previous problem, TS makes use of amemory structure named tabu list, which is a feature thatdistinguishes it from other incomplete methods. The aim ofthe tabu list is

(i) to evade poor-scoring areas;(ii) to dodge unpromising areas and return to previously

reached ones.

Hence, in the tabu list some data is kept of the recentlyvisited solutions, with the aim of avoiding them if these arebad solutions, and so improving the efficiency of the searchprocess.The tabu list is considered themost important featureof TS.

Algorithm 1 describes the classic procedure of TS. Asinput, the algorithm receives a primary solution that includesthe givens values and an empty cell in the other positions,and as output it returns the best solution scored. At line 3,a while statement manages the iterations of the process untilthe defined stop criteria is reached. For instance, the stopcondition is a maximum iteration limit or a threshold onthe evaluation function. In this implementation, we use asevaluation function the minimization of remaining values to

Computational Intelligence and Neuroscience 3

Input: 0Output:

(1)

0(2) 0(3) While Stop Condition do(4) 0(5) For (

) do(6) If ContainsAnyFeatures(

, )

(7) push(,

)(8) End If(9) End For(10)

LocateBestCandidate()

(11) If cost(

) cost(

)(12) FeatureDifferences(

,

)(13)

(14) While >

do(15) ExpireFeature()(16) EndWhile(17) End If(18) EndWhile(19) Return

Algorithm 1: Tabu Search.

complete the puzzle. At line 7, new potential solutions arecreated by a neighboring procedure, these solutions are addedto the candidate list exclusively if they do not include newsolution elements on the tabu list. Then, a promising bestcandidate is selected on condition which is the best qualitysolution according to the evaluation by the cost function.At line 11, the cost evaluation of the chosen candidate iscompared. If it improves the best solution (

) cost, the

differences of those are added to the tabu list and the

becomes the new

.Finally, some features are expired in the tabu list, and

generally in the same order they were included, permittingin next iterations to add solutions to the candidate list whichcontains the expired features.

4. CP Overview andthe alldifferent Constraint

Constraint programming (CP) is a paradigm for solvingcombinatorial search and optimization problems mainlyfrom domains such as scheduling, planning, and vehiclerouting. In CP, a problem is modeled by relating all involvedvariables of the problem in constraints terms, and a constraintsolver is employed to solve it.

CP consists in two identifiable stages:(i) Modeling: stating constraints involving the problem

variables;(ii) Solving: finding a solution satisfying all the con-

straints.Hence, all problems are represented in terms of decision

variables and constraints, and the aim of the constraint solveris to find an assignment to all the variables that satisfies all theconstraints.

4.1. Basic Concepts. AConstraint Satisfaction Problem (CSP)is defined by:

(i) A finite set of variables, = 1, 2, . . . , .(ii) A domain for each variable, () =

(1), (2), . . . , (), also noted as 1, 2, . . . , ,where

is the domain of

.

(iii) A finite set of constraints (), where (1, . . . , )denotes a constraint involving variables 1, . . . , .

A CSP is denoted by the tuple ,, . A CSP hassolution only if every constraint in is satisfied, and it iscalled a consistent CSP; further if no solution exists, it is aninconsistent CSP. Algorithms based on backtracking such asthe forward checking are in general employed to solve CSPs.[20].

4.2. alldifferent Constraint. The alldifferent con-straint commonly appears in problems which are based onpermutations or when disjoint paths need to cover a directedgraph [2123], among other problems that involve constraintsof pairwise difference. The main ability of this constraintis that it exploits the global information of the problemconstraint, instead of handling each pairwise constraintindependently. Exploiting the whole information leads to amore efficient domain filtering as explained in [24]. In thefollowing, we provide some necessary definitions.

Definition 1. A -ary constraint connecting variables in with domains () is defined as a subset of the cartesianproduct () and it is intended as the set of allowed-tuples for these variables.

A constraint that involves one variable (e.g., 1-ary: 1 =8) is called unary constraint and a binary one (e.g., 2-ary:

4 Computational Intelligence and Neuroscience

1 = 2) involves 2 variables, and so on. In general, a -ary constraint has a scope of size . A conjunction of severalsimpler constraints is called a global constraint providing amore simple model for a problem; one of these constraints isthe well-known alldifferent constraint.

The alldifferent constraint is a constraint of differ-ence between all variables involved in the variable relationand specified that the value assigned to the variables must bepairwise different.

Definition 2. Let 1, 2, . . . , be variables with respectivefinite domains(1), (2), . . . , (), then

alldifferent (1, . . . , )

= {(1, . . . , ) | () , = = } .(1)

Since the introduction of the alldifferent constraint[25], several filtering algorithms have been developed [24],depending on the desired degree of local consistency fromweaker local consistency with low degree of filtering butshort-time to stronger with an efficient filtering in a longerruntime. In this work, we employ the alldifferent con-straint based on bounds consistency [12] and Halls marriagetheorem [13]. This implementation provides stronger propa-gation behavior, checking for exhaustion of all subranges ofpossible values [24].

Definition 3 (bounds consistency). Let be a constraint(1, 2, . . . , ) with > 1; a CSP is bounds consistentif for all variables and each value

from its domain,

{min(),max(

)}, there exist values

[min(),max(

)] for all {1, . . . , } such that

(1, 2, . . . , ) . min and max represent the mini-mum and maximum value, respectively, from the domain.

Definition 4 (Halls theorem). Let be a set of variablesand the corresponding finite variable domains. Suppose is a bipartite graph with bipartition (,). There exists amatching that covers if and only if for every subset ,|()| || is fulfilled. Then is called a Hall interval if|| = |

| with

= {| }.

Theorem 5. The constraint alldifferent(1, . . . , ) isbounds consistent if and only if {

1 |

} and

(i) for each interval : || ||,

(ii) for eachHall interval : {min,max

} = 0;

.

Proof. We proceed by induction, observing that the case|| = 1 obviously holds, because all domains aregreater than 1. Let I be a Hall interval and

.

If alldifferent(1, 2, . . . , ) is bounds consistent, it hasa solution when

= min

, by Definition 3.

Example 6. Consider the following CSP which is representedin Figure 2:

1 {1, 2} ,

2 {1, 2} ,

3 {1, 2, 3} ,

4 {1, 2, 4}

alldifferent (1, 2, 3, 4) .

(2)

In order to make bounds consistency of the CS...

Recommended