# Top-k Based Adaptive Enumeration in Constraint Programming

Authors: Ricardo Soto; Broderick Crawford; Wenceslao Palma; Eric Monfroy; Rodrigo Olivares; Carlos Castro; Fernando Paredes
Journal: Mathematical Problems in Engineering
 (2015)

---

## 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-k 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.


---

## Body

## 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 [11–13], 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-k (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.Figure 1
General flowchart of the adaptive enumeration based on Top-k.The rest of this paper is organized as follows. The related work is given in Section2 followed by an overview of constraint programming and associated concepts. The new Top-k 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.


## 2. Related Work

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 [14–16] 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 constraintc is a relation defined on a sequence of variables X
(
c
)
=
(
x
i
1
,
…
,
x
i
X
(
c
)
), called the scheme of c. c is the subset of Z
X
(
c
) that contains the combinations of tuples τ
∈
Z
X
(
c
) that satisfy c. X
(
c
) is called the arity of c. A constraint c with scheme X
(
c
)
=
(
x
1
,
…
,
x
k
) is also noted as c
(
x
1
,
…
,
x
k
).Definition 2 (constraint network).
A constraint network also known as constraint satisfaction problem is defined by a tripleN
=
X
,
D
,
C, where we have the following. (i)
X is a n-tuple of variables of integer variables X
=
(
x
1
,
…
,
x
n
).
(ii)
D is the corresponding n-tuple of domains for X, that is, D
=
D
x
1
×
⋯
×
D
(
x
n
), where D
(
x
i
)
⊂
Z is the finite set of values that variable x
i can take.
(iii)
C is an m-tuple of constraints C
=
{
c
1
,
…
,
c
e
}, where variables in X
(
c
j
) are in X.Definition 3 (instantiation).
Given a networkN
=
X
,
D
,
C, we have the following.(i)
An instantiationA on X
′
=
(
x
1
,
…
,
x
k
)
⊆
X is an assignment of values (
a
1
,
…
,
a
k
) to variables x
1
,
…
,
x
k.
(ii)
An instantiationB on X
′ is valid if ∀
x
i
∈
X
′
,
A
[
x
i
]
∈
D
(
x
i
), where A
[
x
i
] denotes the value of A assigned to x
i.Definition 4 (solution).
Given a networkN
=
X
,
D
,
C, we have the following.(i)
A solution to a networkN is an instantiation A on X
=
(
x
1
,
…
,
x
n
) iff it is valid and satisfies all the constraints. A solution is denoted as sol and SOL
(
N
) corresponds to the set of solutions of N.Example 5 (the Sudoku puzzle).
As an example, let us consider the Sudoku problem as a constraint network. The problem consists in filling a9
×
9 grid with prefilled cells, divided into nine 3
×
3 regions, so that each column, row, and region contain different digits from 1 to 9. Let N
=
X
,
D
,
C be the constraint network, which is composed of the following.(i)
X
=
(
x
1,1
,
…
,
x
n
,
m
) is the sequence of variables, and x
i
,
j
∈
X identifies the cell placed in the ith row and jth column of the Sudoku puzzle, for i
=
1
,
…
,
n and i
=
1
,
…
,
m.
(ii)
D is the corresponding set of domains, where D
(
x
i
j
)
∈
D is the domain of the variable x
i
j;
(iii)
C is the set of constraints defined as follows.
(a)
To guarantee that values differ in rows and columns:(1)
x
k
,
i
≠
x
k
,
j
∧
x
i
,
k
≠
x
j
,
k
,
∀
k
∈
1,9
,
i
∈
1,9
,
j
∈
i
+
1,9
.
(b)
To guarantee that values differ in each subregion:(2)
x
(
k
1
-
1
)
*
3
+
k
2
,
(
j
1
-
1
)
*
3
+
j
2
≠
x
(
k
1
-
1
)
*
3
+
k
3
,
(
j
1
-
1
)
*
3
+
j
3
,
∀
k
1
,
j
1
,
k
2
,
j
2
,
k
3
,
j
3
∈
1,3
∣
k
2
≠
k
3
∧
j
2
≠
j
3
.An instance and the corresponding solution to a Sudoku puzzle can be found in Figure2.Figure 2
An instance and the corresponding solution to a Sudoku puzzle.


### 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 Algorithm1. As input, it receives the constraint network N and the enumeration strategy s to be employed. The output is a solution sol
∈
SOL
(
N
) 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 X to then associate it with a value from its domain according to s. 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.Algorithm 1:Constraint solving.
Input: N
=
(
X
,
D
,
C
)
,
s
Output: s
o
l
∈
S
O
L
N
o
r
a
f
a
i
l
u
r
e
(1)While not
s
u
c
c
e
s
s
or
f
a
i
l
u
r
e
do
(2)select  a  variable  x  from  X  according  to  s
(3)s
e
l
e
c
t
a
v
a
l
u
e
f
r
o
m
D
(
x
)
a
c
c
o
r
d
i
n
g
t
o
s
(4)p
r
o
p
a
g
a
t
e
(5)If D
W
O
i
n
f
u
t
u
r
e
v
a
r
then
(6)s
h
a
l
l
o
w
b
a
c
k
t
r
a
c
k
(7)End If
(8)If
D
W
O
i
n
c
u
r
r
e
n
t
v
a
r
then
(9)b
a
c
k
t
r
a
c
k
(10)End If
(11)End While


## 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 Algorithm1. As input, it receives the constraint network N and the enumeration strategy s to be employed. The output is a solution sol
∈
SOL
(
N
) 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 X to then associate it with a value from its domain according to s. 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.Algorithm 1:Constraint solving.
Input: N
=
(
X
,
D
,
C
)
,
s
Output: s
o
l
∈
S
O
L
N
o
r
a
f
a
i
l
u
r
e
(1)While not
s
u
c
c
e
s
s
or
f
a
i
l
u
r
e
do
(2)select  a  variable  x  from  X  according  to  s
(3)s
e
l
e
c
t
a
v
a
l
u
e
f
r
o
m
D
(
x
)
a
c
c
o
r
d
i
n
g
t
o
s
(4)p
r
o
p
a
g
a
t
e
(5)If D
W
O
i
n
f
u
t
u
r
e
v
a
r
then
(6)s
h
a
l
l
o
w
b
a
c
k
t
r
a
c
k
(7)End If
(8)If
D
W
O
i
n
c
u
r
r
e
n
t
v
a
r
then
(9)b
a
c
k
t
r
a
c
k
(10)End If
(11)End While


## 4. Adaptive Enumeration via Top-k

In this section, we present the framework for adaptive enumeration via the Top-k 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-k approach and its incorporation to the adaptive enumeration framework.Figure 3
Ranking the portfolio of enumeration strategies (S
1 to S
8).


### 4.1. Top-k

In database systems, a Top-k query [24] aims at retrieving the k 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-k 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-k 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 functionF, defined on predicates p
1
,
…
,
p
n, is monotone if F
(
p
1
,
…
,
p
n
)
≤
F
(
p
1
′
,
…
,
p
n
′
) whenever p
i
≤
p
i
′ for every i.Then, assuming that an indicatori of the search process can be seen as a predicate p
i, a scoring function F for evaluating the performance of enumeration strategies by using n indicators can be generically defined as
(3)
F
=
i
1
+
⋯
+
i
n
,
where i
j with j
∈
1
⋯
n 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 s
l
∈
S is defined as
(4)
F
s
l
=
w
1
i
1
s
l
+
⋯
+
w
n
i
n
s
l
,
where w
j is the weight associated with indicator i
j
s
l, which in turn provides a score for the strategy s
l, with respect to a given performance criterion.Definition 7 (Top-k result set).
LetS be the set of enumeration strategies used in the adaptive enumeration framework. The Top-k result denoted by Top
k
(
S
) is a sorted set on the score, in increasing order, such that (1)
Top
k
(
S
)
⊆
S;
(2)
ifS
<
k, Top
k
(
S
)
=
S; otherwise Top
k
(
S
)
=
k;
(3)
∀
s
∈
Top
k
(
S
), ∀
s
′
∈
S
∖
Top
k
(
S
), F
s
≤
F
s
′.Definition 8 (result’s rank).
Given a Top-k result set R, the rank of result r
∈
R is the position of r in the set R.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-k 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.Algorithm2 depicts from a high-level standpoint the integration of the Top-k approach in a classic constraint solving algorithm. The algorithm receives as input the constraint network N, the set of strategies denoted by S, and the set of indicators denoted by I; the output is a solution sol
∈
SOL
(
N
) 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-k. Once the best s
l 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 s
l is employed next along the resolution process. Finally, if a solution sol
∈
SOL
(
N
) exists, it is reported.Algorithm 2:Adaptive enumeration via Top-k.
Input: N
=
(
X
,
D
,
C
)
,
S
,
I
Output: s
o
l
∈
S
O
L
(
N
)
o
r
a
f
a
i
l
u
r
e
(1)s
e
t
u
p
p
o
r
t
f
o
l
i
o
(2)s
e
l
e
c
t
s
l
∈
S
u
s
i
n
g Top-k
(3)While not
s
u
c
c
e
s
s
or
f
a
i
l
u
r
e
do
(4)s
e
l
e
c
t
a
v
a
r
i
a
b
l
e
x
f
r
o
m
X
a
c
c
o
r
d
i
n
g
t
o
s
l
(5)s
e
l
e
c
t
a
v
a
l
u
e
f
r
o
m
D
(
x
)
a
c
c
o
r
d
i
n
g
t
o
s
l
(6)p
r
o
p
a
g
a
t
e
(7)If
D
W
O
i
n
f
u
t
u
r
e
v
a
r
then
(8)s
h
a
l
l
o
w
b
a
c
k
t
r
a
c
k
(9)End If
(10)If
D
W
O
i
n
c
u
r
r
e
n
t
v
a
r
then
(11)b
a
c
k
t
r
a
c
k
(12)End If
(13)∀
s
l
∈
S
,
∀
i
∈
I
g
e
t
s
c
o
r
e
s
(14)∀
s
l
∈
S
c
o
m
p
u
t
e
s
c
o
r
i
n
g
f
u
n
c
t
i
o
n
(15)s
e
l
e
c
t
s
l
u
s
i
n
g Top-k
(16)End While


## 4.1. Top-k

In database systems, a Top-k query [24] aims at retrieving the k 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-k 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-k 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 functionF, defined on predicates p
1
,
…
,
p
n, is monotone if F
(
p
1
,
…
,
p
n
)
≤
F
(
p
1
′
,
…
,
p
n
′
) whenever p
i
≤
p
i
′ for every i.Then, assuming that an indicatori of the search process can be seen as a predicate p
i, a scoring function F for evaluating the performance of enumeration strategies by using n indicators can be generically defined as
(3)
F
=
i
1
+
⋯
+
i
n
,
where i
j with j
∈
1
⋯
n 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 s
l
∈
S is defined as
(4)
F
s
l
=
w
1
i
1
s
l
+
⋯
+
w
n
i
n
s
l
,
where w
j is the weight associated with indicator i
j
s
l, which in turn provides a score for the strategy s
l, with respect to a given performance criterion.Definition 7 (Top-k result set).
LetS be the set of enumeration strategies used in the adaptive enumeration framework. The Top-k result denoted by Top
k
(
S
) is a sorted set on the score, in increasing order, such that (1)
Top
k
(
S
)
⊆
S;
(2)
ifS
<
k, Top
k
(
S
)
=
S; otherwise Top
k
(
S
)
=
k;
(3)
∀
s
∈
Top
k
(
S
), ∀
s
′
∈
S
∖
Top
k
(
S
), F
s
≤
F
s
′.Definition 8 (result’s rank).
Given a Top-k result set R, the rank of result r
∈
R is the position of r in the set R.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-k 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.Algorithm2 depicts from a high-level standpoint the integration of the Top-k approach in a classic constraint solving algorithm. The algorithm receives as input the constraint network N, the set of strategies denoted by S, and the set of indicators denoted by I; the output is a solution sol
∈
SOL
(
N
) 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-k. Once the best s
l 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 s
l is employed next along the resolution process. Finally, if a solution sol
∈
SOL
(
N
) exists, it is reported.Algorithm 2:Adaptive enumeration via Top-k.
Input: N
=
(
X
,
D
,
C
)
,
S
,
I
Output: s
o
l
∈
S
O
L
(
N
)
o
r
a
f
a
i
l
u
r
e
(1)s
e
t
u
p
p
o
r
t
f
o
l
i
o
(2)s
e
l
e
c
t
s
l
∈
S
u
s
i
n
g Top-k
(3)While not
s
u
c
c
e
s
s
or
f
a
i
l
u
r
e
do
(4)s
e
l
e
c
t
a
v
a
r
i
a
b
l
e
x
f
r
o
m
X
a
c
c
o
r
d
i
n
g
t
o
s
l
(5)s
e
l
e
c
t
a
v
a
l
u
e
f
r
o
m
D
(
x
)
a
c
c
o
r
d
i
n
g
t
o
s
l
(6)p
r
o
p
a
g
a
t
e
(7)If
D
W
O
i
n
f
u
t
u
r
e
v
a
r
then
(8)s
h
a
l
l
o
w
b
a
c
k
t
r
a
c
k
(9)End If
(10)If
D
W
O
i
n
c
u
r
r
e
n
t
v
a
r
then
(11)b
a
c
k
t
r
a
c
k
(12)End If
(13)∀
s
l
∈
S
,
∀
i
∈
I
g
e
t
s
c
o
r
e
s
(14)∀
s
l
∈
S
c
o
m
p
u
t
e
s
c
o
r
i
n
g
f
u
n
c
t
i
o
n
(15)s
e
l
e
c
t
s
l
u
s
i
n
g Top-k
(16)End While


## 5. Experimental Evaluation

This section illustrates the experimental results of the proposed approach. The Top-k 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)
then-queens problem with n
=
{
8,10,12,15,20,50
},
(ii)
the magic squares withsize
=
{
3,4
,
5
},
(iii)
the Sudoku puzzle,
(iv)
the knight tour withsize
=
{
5,6
}.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.Table 1
Portfolio used.
Strategy
Variable ordering
Value ordering
S
1
First variable of the list
min. value in domain
S
2
The variable with the largest domain
min. value in domain
S
3
The variable with the smallest domain
min. value in domain
S
4
The variable with the largest number of
min. value in domain
attached constraints
S
5
First variable of the list
max. value in domain
S
6
The variable with the largest domain
max. value in domain
S
7
The variable with the smallest domain
max. value in domain
S
8
The variable with the largest number of
max. value in domain
attached constraintsTable 2
Search process indicators.
Name
Weight
Description
VFP
50
Number of variables fixed by propagation.
T
st
(
s
k
)
10
Number of steps since the last time that an enumeration strategy
s
k was used until step stth.
SB
-
10
Number of shallow backtracks [20]
B
-
20
Number of backtracks.
In1
10
Represents a variation of the maximum depth. It is calculated as
Current  Maximum  Depth − Previous  Maximum  Depth
In2
10
Calculated asCurrent  Depth − Previous  Depth. A positive value   means that the current node is deeper than the one explored at the   previous step.
Thrash
−20
The solving process alternates enumerations and backtracks on a  small number of variables without succeeding in having a strong   orientation. It is calculated asd
t
-
1
-
VF
P
t
-
1, where d
t   is the current depth in the search in a given time t.We compare the adaptive enumeration based on Top-k 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-k approach. We also include in the comparison the results of using a single strategy during the complete solving process (S
1 to S
8). Tables 3 and 4 report solving times needed to reach a solution. The results illustrate that Top-k is able to outperform both hyperheuristics and single strategies for small instances of the n-queens. Top-k is about 20 times faster than HH-PSO and about 30 times faster than HH-GA for n
=
8; this difference is increased for n
=
10 and n
=
12, being about 7 times faster than hyperheuristics for the biggest tested instance of n-queens. For the Sudoku puzzle, Top-k is not able to improve previous performance, but for magic squares and knight’s tour, Top-k performs notably better than hyperheuristics, remaining competitive with respect to single strategies. Indeed, Top-k takes the first place for knight’s tour (n
=
6) when single strategies are not able to solve it before stop criterion.Table 3
Runtime in ms for different instances of the N-queens problem with different strategies.
Strategy
NQ
NQ
NQ
NQ
NQ
NQ
(n
=
8)
(n
=
10)
(n
=
12)
(n
=
15)
(n
=
20)
(n
=
50)
S
1
12
13
20
86
21,027
t.o.
S
2
8
35
30
815
6,315
t.o.
S
3
7
10
25
4
17
962
S
4
15
11
23
54
21,945
t.o.
S
5
17
9
21
56
21,319
t.o.
S
6
12
12
17
778
5,561
t.o.
S
7
9
6
19
3
18
987
S
8
11
6
18
47
21,297
t.o.
HH-GA
151
124
285
215
2,358
21,009
HH-PSO
113
123
201
145
1,068
20,340
Top-k
5
4
7
18
110
2,845Table 4
Runtime in ms for magic squares, Sudoku, and the knight problem with different strategies.
Strategy
MS
MS
Sudoku
Knight
Knight
(n
=
4)
(n
=
5)
(n
=
5)
(n
=
6)
S
1
21
1,216
8
1,321
t.o.
S
2
2,093
t.o.
3,644
t.o.
t.o.
S
3
5
318
7
1,352
t.o.
S
4
14
7,505
7
t.o.
t.o.
S
5
67
t.o.
11
1,326
t.o.
S
6
36
t.o.
2,127
t.o.
t.o.
S
7
88
t.o.
18
1,751
t.o.
S
8
31
t.o.
17
t.o.
t.o.
HH-GA
158
1,591
1,631
2,615
12,928
HH-PSO
327
1,868,453
234
85,574
11,547
Top-k
7
857
6,349
2,553
8,931These results evidence the ability of Top-k 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, 26–28]. 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 Tables5 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-k approach can fail more to reach a result but obtain minor solving times than hyperheuristics (see, e.g., n-queens with n
=
20 and n
=
50; magic squares with size
=
5). This is explained by the fact that the Top-k 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-k algorithm used runs in (n
2) 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.Table 5
Number of backtracks solving different instances of the N-queens problem with different strategies.
Strategy
NQ
NQ
NQ
NQ
NQ
NQ
(n
=
8)
(n
=
10)
(n
=
12)
(n
=
15)
(n
=
20)
(n
=
50)
S
1
10
6
15
73
10,026
>27,406
S
2
11
12
11
808
2,539
>39,232
S
3
10
4
16
1
11
177
S
4
10
6
15
73
10,026
>26,405
S
5
10
6
15
73
10,026
>27,406
S
6
11
12
11
808
2,539
>39,232
S
7
10
4
16
1
11
177
S
8
10
6
15
73
10,026
>26,405
HH-GA
4
6
4
73
0
7
HH-PSO
6
2
16
11
11
252
Top-k
5
2
2
13
18
212Table 6
Number of backtracks solving magic squares, Sudoku, and the knight problem with different strategies.
Strategy
MS
MS
Sudoku
Knight
Knight
(n
=
4)
(n
=
5)
(n
=
5)
(n
=
6)
S
1
12
910
18
767
>19,818
S
2
1,191
>46,675
10439
>42,889
>43,098
S
3
3
185
4
767
>19,818
S
4
10
5,231
18
>18,838
>19,716
S
5
51
>46,299
2
767
>19,818
S
6
42
>44,157
6,541
>42,889
>43,098
S
7
3
>29,416
9
767
>19,818
S
8
29
>21,847
2
>18,840
>19,716
HH-GA
0
7
2
8,190
4,105
HH-PSO
4
53
826
667
29,608
Top-k
1
207
2,744
613
6,835Figure 4
Comparing runtimes of adaptive approaches.Figure 5
Comparing backtracks of adaptive approaches.


## 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-k 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-k 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.



---

*Source: 580785-2015-02-22.xml*