Abstract

Constraint programming effectively solves constraint satisfaction and optimization problems by basically building, pruning, and exploring a search tree of potential solutions. In this context, a main component is the enumeration strategy, which is responsible for selecting the order in which variables and values are selected to build a possible solution. This process is known to be quite important; indeed a correct selection can reach a solution without failed explorations. However, it is well known that selecting the right strategy is quite challenging as their performance is notably hard to predict. During the last years, adaptive enumeration appeared as a proper solution to this problem. Adaptive enumeration allows the solving algorithm being able to autonomously modifying its strategies in solving time depending on performance information. In this way, the most suitable order for variables and values is employed along the search. In this paper, we present a new and more lightweight approach for performing adaptive enumeration. We incorporate a powerful classification technique named Top- in order to adaptively select strategies along the resolution. We report results on a set of well-known benchmarks where the proposed approach noticeably competes with classical and modern adaptive enumeration methods for constraint satisfaction.

1. Introduction

Constraint programming (CP) is a modern and efficient programming paradigm for solving complex constraint satisfaction and optimization problems. It is commonly employed for solving real-life problems in various application domains; practical examples can be seen in rostering [1], scheduling [2], manufacturing [3], engineering [4], and bioinformatics [5], among others. Under this paradigm, problems are seen as constraint networks, which consist in a sequence of variables owning a domain of values and a set of constraints imposing conditions that those variables must satisfy. A solution is then a set of values for the variables that satisfies the whole set of constraints. Constraint networks, also named constraint satisfaction problems (CSPs), are usually solved by a backtracking-based algorithm that explores a search tree where the potential solution is distributed. The exploration proceeds by combining two main phases: enumeration and propagation. Enumeration is the process of assigning values to variables in order to generate partial solutions, while the propagation attempts to remove from the constraint network the conflicting values that do not lead to any feasible solution.

The enumeration process involves two actions. Firstly, a variable from the constraint network is selected and then a value is assigned to this variable. These actions are handled by the variable and value ordering heuristics, which together form the enumeration strategy. Enumeration is a crucial phase in constraint satisfaction that may conduct to very different solving processes depending on the strategy employed. Indeed, by selecting the correct strategy, a solution can be reached without performing backtracks and as a consequence requiring a minor solving time. However, a main concern in this context is the difficulty of a priori selecting the correct strategy as their performance is notably hard to predict.

During the last years, various approaches have been proposed to tackle this concern; most of them are based on performing adaptive enumeration during the search process. The idea is to enable the search algorithm to control and automatically choose its own ordering heuristics based on information collected during the solving process. A preliminary framework is proposed in [6] which allows the solver to choose and replace its heuristics during solving time by using priorities. The idea is to penalize bad performing strategies while the efficient ones receive more credits. The quality of strategies is evaluated by using performance indicators of the search process. A more modern and efficient approach is presented in [7], where a hyperheuristic is proposed to control the enumeration. A hyperheuristic [8, 9] can be seen as a method to choose heuristics [10]; in particular a meta-heuristic is used on the top of the hyperheuristic in order to select and adapt the ordering heuristics. Although this hyperheuristic approach has illustrated promising results [1113], the top part is quite expensive adding a significant overhead to the whole resolution of the constraint satisfaction problem.

In this paper, we propose a novel and more lightweight framework for adaptive enumeration. We follow a different approach avoiding the use of hyperheuristics by incorporating a simple and efficient classification technique named Top- (see Figure 1) in order to rapidly evaluate and rank the strategies along the resolution. We illustrate encouraging results where our approach noticeably competes with classical and modern adaptive enumeration methods for constraint satisfaction.

The rest of this paper is organized as follows. The related work is given in Section 2 followed by an overview of constraint programming and associated concepts. The new Top- based approach for adaptive enumeration is illustrated in Section 4. In Section 5, we present the experiments and the analysis of results. Finally, we give conclusions and some future research directions.

In constraint solving, the enumeration strategy is composed of the pair variable and value ordering heuristics. The enumeration is adaptive when the solver is able to control and automatically choose its own ordering heuristics. We can distinguish two dimensions depending on the sources of feedback information: online and offline methods. The feedback, when used, corresponds to the information that is learned while solving (online) or while using a set of training instances (offline). In the context of offline methods, preliminary approaches proposed to sample and learn good strategies after solving a problem. For instance in [1416] learning algorithms are used to analyze the resolution process of problems successfully solved. This information is then used by advisors that are able to recommend good heuristics. Another interesting approach is suggested in [17], which proposes to select the variable with the largest weighted degree. The weighted degree is computed by associating weights to constraints which are incremented once they lead to the deletion of a variable’s domain. Then, the weight degree of a variable corresponds to the sum of weights of constraints where they participate. This idea follows the contention principle, which states that variables directly related to conflicts are more likely to cause failures. A variation of the weighted degree strategy, known as random probing, is reported in [18, 19], which incorporates sampling during an initial gathering phase arguing that initial choices are often the most important.

Following an online process, a pioneer work is the one presented in [6]. This framework introduced a four-component architecture, allowing the dynamic replacement of enumeration strategies. The strategies are evaluated via performance indicators of the search process, and better evaluated strategies replace worse ones during solving time. Such a pioneer framework was used as basis of different related works. For instance, a more modern approach based on this idea is reported in [7]. This approach employs a two-layered framework where a hyperheuristic placed on the top-layer controls the dynamic selection of enumeration strategies of the solver placed on the lower-layer. A hyperheuristic can be regarded as a method to choose heuristics [10]. In this approach, two different top-layers have been proposed, one using a genetic algorithm [11, 12] and another using a particle swarm optimizer [13]. Similar approaches have also been implemented for solving optimization problems instead of pure CSPs [21].

3. Preliminaries

In this section, we briefly survey the basic concepts associated with constraint programming.

Definition 1 (constraint). A constraint is a relation defined on a sequence of variables , called the scheme of . is the subset of that contains the combinations of tuples that satisfy . is called the arity of . A constraint with scheme is also noted as .

Definition 2 (constraint network). A constraint network also known as constraint satisfaction problem is defined by a triple , where we have the following. (i) is a -tuple of variables of integer variables .(ii) is the corresponding -tuple of domains for , that is, , where is the finite set of values that variable can take.(iii) is an -tuple of constraints , where variables in are in .

Definition 3 (instantiation). Given a network , we have the following.(i)An instantiation on is an assignment of values to variables .(ii)An instantiation on is valid if , where denotes the value of assigned to .

Definition 4 (solution). Given a network , we have the following.(i)A solution to a network is an instantiation on iff it is valid and satisfies all the constraints. A solution is denoted as and corresponds to the set of solutions of .

Example 5 (the Sudoku puzzle). As an example, let us consider the Sudoku problem as a constraint network. The problem consists in filling a grid with prefilled cells, divided into nine regions, so that each column, row, and region contain different digits from 1 to 9. Let be the constraint network, which is composed of the following.(i) is the sequence of variables, and identifies the cell placed in the th row and th column of the Sudoku puzzle, for and .(ii) is the corresponding set of domains, where is the domain of the variable ;(iii) is the set of constraints defined as follows.(a)To guarantee that values differ in rows and columns: (b)To guarantee that values differ in each subregion:

An instance and the corresponding solution to a Sudoku puzzle can be found in Figure 2.

3.1. Constraint Solving

Constraint solving is usually handled by building a search tree composed of potential solutions. Those potential solutions are then verified if they can lead to a feasible solution. If not, the search tree is pruned by deleting from domain those unfeasible values. The search process is commonly divided in two phases: enumeration and propagation. The enumeration can be seen as a sorting process [22, 23] where the potential solutions are incrementally constructed by assigning values to variables. The propagation is the phase responsible for pruning the tree.

A general procedure for constraint solving is illustrated in Algorithm 1. As input, it receives the constraint network and the enumeration strategy to be employed. The output is a solution to the constraint network or a failure; that is, no solution has been found. The process begins by initiating a while loop which iterates over a set of actions until a solution or a failure is found. The first action corresponds to selecting a variable from the set to then associate it with a value from its domain according to . The propagation phase is next called in order to delete from domains the values that will not lead to any solution considering the current instantiation. This phase may empty the domain of a given variable, which is known as a domain wipe-out (DWO). If a DWO happens in a future variable, a shallow backtrack assigns the following available value to the current variable. Finally, if a DWO occurs in the current variable, the backtrack jumps back to the previous instantiated variable that is still able to reach a solution.

Input:
Output:
(1) While not   or     do
(2)   select  a  variable  x  from  X  according  to  s
(3)   
(4)   
(5)   If    then
(6)    
(7)   End If
(8)   If     then
(9)    
(10)  End If
(11) End While

4. Adaptive Enumeration via Top-

In this section, we present the framework for adaptive enumeration via the Top- approach. The idea is to evaluate, via performance indicators, and then to rank a portfolio of enumeration strategies in running time in order to use the most appropriate one at each step of the process (see Figure 3). Our goal here is to avoid the use of hyperheuristics to provide a faster process while maintaining the quality of solutions. In the following, we briefly describe the Top- approach and its incorporation to the adaptive enumeration framework.

4.1. Top-

In database systems, a Top- query [24] aims at retrieving the tuples that better satisfies a given set of preferences. This is a widely used technique as selecting data according to user requirements is largely required in different real-life domains such as the Web, multimedia search, distributed systems, and multicriteria decision making. A common way to identify the Top- objects is to provide a score to each object according to its relevance within the tuple and then to compute a scoring function for all involved objects. There exist different techniques to processing Top- queries which are mainly related to database access, design, and implementation aspects (see [24] for a detailed presentation). We adopt the monotone ranking function approach which is the most appropriate one for our purposes, as it can straightforwardly be mapped to a scoring function for evaluating performance. Another interesting feature is the ability to upper-bound objects scores. This allows one to early prune certain objects without exactly knowing their scores, alleviating the function computation, and as consequence accelerating the whole solving process. A monotone ranking function is defined as follows.

Definition 6 (monotone ranking function). A function , defined on predicates , is monotone if whenever for every .

Then, assuming that an indicator of the search process can be seen as a predicate , a scoring function for evaluating the performance of enumeration strategies by using indicators can be generically defined as where with is an indicator that measures the performance of the strategy in a given amount of time. However, according to [12], indicators do not have the same relevance for evaluating a solving process; a weight is therefore associated with each indicator to balance their effect on the scoring function. Finally, the general scoring function for a given enumeration strategy is defined as where is the weight associated with indicator , which in turn provides a score for the strategy , with respect to a given performance criterion.

Definition 7 (Top- result set). Let be the set of enumeration strategies used in the adaptive enumeration framework. The Top- result denoted by is a sorted set on the score, in increasing order, such that (1);(2)if , ; otherwise ;(3), , .

Definition 8 (result’s rank). Given a Top- result set , the rank of result is the position of in the set .

Because our approach does not deal with hard disks issues and the processing of large volumes of data in main memory we use the most straightforward way to compute the Top- result set; that is, all the strategies are sequentially scanned and the score of each of them is calculated and placed in a sorted list. Thus, the adaptive enumeration framework selects the best enumeration strategy in order to continue with the solving process.

Algorithm 2 depicts from a high-level standpoint the integration of the Top- approach in a classic constraint solving algorithm. The algorithm receives as input the constraint network , the set of strategies denoted by , and the set of indicators denoted by ; the output is a solution to the constraint network or a failure. The process begins by setting up the portfolio and the indicators of the solving process and a cutoff value, which is usually a given number of steps (other stop cutoff values can be used such as the percentage or number of fixed variables, number of visited nodes, or number of backtracks). Then, the constraint network is attempted to be solved until the cutoff, and the best strategy is selected by using Top-. Once the best is selected, the constraint network is solved and at every step, the indicators provide the corresponding score, which are used to compute the scoring function. In this way, the best is employed next along the resolution process. Finally, if a solution exists, it is reported.

Input:
Output:
(1)
(2) Top-
(3) While not     or     do
(4)    
(5)    
(6)    
(7)    If     then
(8)     
(9)    End If
(10)  If     then
(11)   
(12)  End If
(13)  
(14)  
(15)   Top-
(16) End While

5. Experimental Evaluation

This section illustrates the experimental results of the proposed approach. The Top- adaptive enumeration has been implemented on the Eclipse Constraint Logic Programming Solver v5.10 interfaced with Java. The experiments have been launched on a 3.3 GHz Intel Core i3 with 8 Gb RAM running Ubuntu. We test our approach using different instances of the following classic benchmarks:(i)the -queens problem with ,(ii)the magic squares with ,(iii)the Sudoku puzzle,(iv)the knight tour with .

We provide in the Appendix Section the encodings of the tested benchmarks. As in previous works [4], we use 65535 steps as the stop criterion; problems having no solution at this point are set to t.o. (time out). Once the problem is launched, the step begins from 0 and it is incremented by 1 each time a variable is instantiated by enumeration. The adaptive enumeration uses a portfolio of eight strategies, which are described in Table 1. Indicators and weights employed are described in Table 2. Weights have been collected from experience and tuning phases done in previous works [12, 13] in order to correctly represent the relevance that each one has on the scoring function.

We compare the adaptive enumeration based on Top- with the two last reported online methods based on hyperheuristics, one controlled by a genetic algorithm (HH-GA) [25] and the other one by particle swarm optimization (HH-PSO) [13]. The portfolio used by hyperheuristics is the same as the one of the Top- approach. We also include in the comparison the results of using a single strategy during the complete solving process ( to ). Tables 3 and 4 report solving times needed to reach a solution. The results illustrate that Top- is able to outperform both hyperheuristics and single strategies for small instances of the -queens. Top- is about 20 times faster than HH-PSO and about 30 times faster than HH-GA for ; this difference is increased for and , being about 7 times faster than hyperheuristics for the biggest tested instance of -queens. For the Sudoku puzzle, Top- is not able to improve previous performance, but for magic squares and knight’s tour, Top- performs notably better than hyperheuristics, remaining competitive with respect to single strategies. Indeed, Top- takes the first place for knight’s tour () when single strategies are not able to solve it before stop criterion.

These results evidence the ability of Top- to dynamically adapt the search in order to use the best strategy for each part of the search tree, allowing producing better results than most of single strategies. Certainly, selecting the correct variable and value ordering for the different regions of the search space can have a dramatic effect on the performance of the backtracking algorithm with huge variances on solving performance [12, 13, 17, 2628]. This is explained by the fact that selecting the correct strategy to the correct part of the search tree should lead to more promising instantiations (variable-value assignments conducting to solutions) than failures (variable-value assignments not conducting to any solution), reducing as a consequence the number of backtracks and runtime.

We also consider in the experimental evaluation the number of backtracks reported to reach a solution as a performance indicator (see Tables 5 and 6), since it allows one to measure how many times the process fails in instantiating a variable. Here, we illustrate that in adaptive enumeration the number of backtracks is not exactly related to solving time. Indeed, the Top- approach can fail more to reach a result but obtain minor solving times than hyperheuristics (see, e.g., -queens with and ; magic squares with ). This is explained by the fact that the Top- is a more lightweight component than the optimizer on top of hyperheuristics, which is able to find good heuristic configurations but add a noticeable overhead to the whole solving process. Indeed, the Top- algorithm used runs in () while the optimizers used in HH-GA and HH-PSO run in exponential time. A graphical comparison of adaptive enumeration approaches in terms of runtime and backtracks can be seen in Figures 4 and 5, respectively.

6. Conclusions

In this paper, we have presented a new and more lightweight framework for adaptive enumeration. The idea is to reduce the cost of associated hyperheuristics presented in previous approaches so as to alleviate the whole work obtaining faster solving processes. To this end, we have incorporated a simple and efficient classification technique named Top- in order to rapidly evaluate and rank the strategies along the resolution. We have performed a set of experiments on different instances of classic benchmarks where the Top- based adaptive enumeration is able to outperform in several cases the last adaptive enumeration methods reported in the literature while keeping the quality of solutions. Indeed, considerable runtime reductions are achieved in several instances of the tested problems.

We visualize different directions for future work; a straightforward one is the incorporation of new combinations of strategies to provide a bigger portfolio, while finding the balance to avoid increasing the cost of the rank computation. Another interesting idea is to experiment with new and possibly more lightweight optimizers in order to alleviate the work of the hyperheuristic approach. Finally, the use of a similar adaptive framework could be used to interleave different propagation techniques.

Appendix

In this appendix we provide the encodings of all models employed in the experiments.

A. Eclipse Models

A.1. Queens

See Algorithm 3.

:-lib(ic).
queens(N, Board):-
length(Board, N),
Board:: 1..N,
(fromto(Board, Q1|Cols, Cols, ) do
  (foreach(Q2, Cols), param(Q1), count(Dist,1,_) do
   noattack(Q1, Q2, Dist)
  )
),
%call to search predicate
noattack(Q1,Q2,Dist):-
Q2 #= Q1,
Q2 - Q1 #= Dist,
Q1 - Q2 #= Dist.

A.2. Magic Squares

See Algorithm 4.

:-lib(ic).
magic(N):-
NN is N*N,
Sum is N*(NN+1)//2,
dim(Square, N,N),
Square:: 1..NN,
alldifferent(Square),
(for(I,1,N),
  foreach(U,UpDiag),
  foreach(D,DownDiag),
  param(N,Square,Sum)
do
  Sum #= sum(SquareI,1..N),
  Sum #= sum(Square1..N,I),
  U is SquareI,I,
  D is SquareI,N+1-I
),
Sum #= sum(UpDiag),
Sum #= sum(DownDiag),
Square1,1  #< Square1,N,
Square1,1  #< SquareN,N,
Square1,1  #< SquareN,1,
Square1,N  #< SquareN,1,
% call to search predicate
write(Square).

A.3. Knight’s Tour

See Algorithm 5.

:-lib(ic).
knight_tour(N, Board):-
N2 is N*N,
length(Board, N2),
C = -2,-1,1,2,
alldifferent(Board),
( fromto(Board, Q1|Cols, Cols, ), param(N,C) do
  t_Q2(Cols,Q2),
  I:: 1..N,
  J:: 1..N,
  A:: C,
  B:: C,
  IA #= I+A,
  JB #= J+B,
  IA #>= 1,
  JB #>= 1,
  IA #=< N,
  JB #=< N,
  abs(A)+abs(B) #= 3,
  (I-1)*N + J #= Q1,
  Q2 #= (I-1+A)*N + J+B
),
% call to search predicate
t_Q2(A|B,A).
t_Q2(,A).

A.4. Sudoku

See Algorithm 6.

sudokusolve(ProblemName):-
problem(ProblemName, Board),
sudoku(3, Board).
sudoku(N, Board):-
N2 is N*N,
dim(Board, N2,N2),
Board1..N2,1..N2  :: 1..N2,
( for(I,1,N2), param(Board,N2) do
  Row is BoardI,1..N2,
  alldifferent(Row),
  Col is Board1..N2,I,
  alldifferent(Col)
),
( multifor(I,J,1,N2,N), param(Board,N) do
  ( multifor(K,L,0,N-1), param(Board,I,J),
   foreach(X,SubSquare) do
    X is BoardI+K,J+L
  ),
  alldifferent(SubSquare)
),
term_variables(Board, Vars),
  % call to search predicate
write(Board).
problem(1, (
(_, _, 2, _, _, 5, _, 7, 9),
(1, _, 5, _, _, 3, _, _, _),
(_, _, _, _, _, _, 6, _, _),
(_, 1, _, 4, _, _, 9, _, _),
(_, 9, _, _, _, _, _, 8, _),
(_, _, 4, _, _, 9, _, 1, _),
(_, _, 9, _, _, _, _, _, _),
(_, _, _, 1, _, _, 3, _, 6),
(6, 8, _, 3, _, _, 4, _, _))).

Conflict of Interests

The authors declare that there is no conflict of interests regarding the publication of this paper.

Acknowledgments

Ricardo Soto is supported by Grant CONICYT/FONDECYT/INICIACION/11130459, Broderick Crawford is supported by Grant CONICYT/FONDECYT/1140897, and Fernando Paredes is supported by Grant CONICYT/FONDECYT/1130455.