A Variable Depth Search Algorithm for Binary Constraint Satisfaction Problems

The constraint satisfaction problem (CSP) is a popular used paradigm to model a wide spectrum of optimization problems in artificial intelligence. This paper presents a fast metaheuristic for solving binary constraint satisfaction problems. The method can be classified as a variable depth search metaheuristic combining a greedy local search using a self-adaptive weighting strategy on the constraint weights. Several metaheuristics have been developed in the past using various penalty weight mechanisms on the constraints.What distinguishes the proposedmetaheuristic from those developed in the past is the update of k variables during each iteration when moving from one assignment of values to another. The benchmark is based on hard random constraint satisfaction problems enjoying several features that make them of a great theoretical and practical interest. The results show that the proposed metaheuristic is capable of solving hard unsolved problems that still remain a challenge for both complete and incompletemethods. In addition, the proposed metaheuristic is remarkably faster than all existing solvers when tested on previously solved instances. Finally, its distinctive feature contrary to other metaheuristics is the absence of parameter tuning making it highly suitable in practical scenarios.


Introduction
Organizations like companies or public institutions are confronted in their daily life with a large number of combinatorial optimization problems which occur in many different application domains such as Operations Research (e.g., scheduling and assignment), hardware design (verification and testing, placement and layout), financial decision making (option trading or portfolio management), or even biology (DNA sequencing).The domain of combinatorial optimization refers to optimization problems where the search space (i.e., the set of all feasible solutions) is discrete.The constraint satisfaction problem (CSP) which can model a wide spectrum of combinatorial optimization problems rising in the field of artificial intelligence has become an important field of study in both theoretical and applied computer science.Constraint technology is making a considerable commercial impact worldwide due to its ability to solve highly complex applications operating in the most difficult environment counting on first-class technology to perform the job.ILOG and Cosytec are two of the leading companies producing software based on this technology.A large number of systems based on the constraints technology have been developed.Examples include the APACHE system [1] used at Roissy Airport in Paris, PLAN system [2] which is a medium-long term scheduling system for aircraft assembly line scheduling, the COBRA system [3] that generates work plans for train drivers and conductors of North Western Trains in the UK, and TAP-AI which is a planning system for crew assignment in the airline SAS [4].Disasters which have long impacted world nations, resulting in mass casualties and huge financial tolls where technology and humans have to work together hand-in-hand without fault, with every single step of a mission meticulously planned out, are another research area where solutions based on constraint technology have received a great attention lately [5,6].The handbook of Constraint Programming [7] lists example applications of several areas modeled as CSPs.The paper is organized as follows.Section 2 explains the constraint satisfaction problem.Section 3 provides a survey of methods used to solve the constraint satisfaction problem.Section 4 introduces the metaheuristic in detail.Section 5 presents the results while Section 6 concludes the paper.

CSP
The CSP consists of assigning values to variables while satisfying certain constraints.Constraints can be given explicitly, by listing all possible tuples or implicitly, by describing a relation in some mathematical form.As a domain example, consider problems that occur in production scheduling.Scheduling is concerned with the allocation of resources to activities with the goal of optimizing some performance objectives while satisfying certain restrictions or constraints.Depending on the problem posed, resources may refer to machines, humans, and so forth, activities could be manufacturing operations, objectives could be the minimization of the schedule length, and finally constraints may state the precedence relationship among activities as they govern the schedule solution.
A CSP is a tuple ⟨, , ⟩, where (i)  is a finite set of variables:  = { A solution to a CSP requires the assignment of values to each of the variables from their domains such that all the constraints on the variables are satisfied.In this paper, attention is focused on binary CSPs, where all constraints are binary; that is, they are based on the Cartesian product of the domains of two variables.However, any nonbinary CSP can theoretically be converted to a binary CSP [8,9].The structure of a binary CSP can be better visualized by a graph (, ) where the set of vertices  corresponds to the variables and each edge (  ,   ) ∈  represents a constraint connecting the pair of variables involved in this constraint.The CSP in its general form is NP-complete [10] and has been extensively studied due to its simplicity and applicability [7].The simplicity of the problem coupled with its intractability makes it an ideal platform for exploring new algorithmic techniques.This has led to the development of several algorithms for solving CSPs which usually fall into two main categories: systematic algorithms and local search algorithms.

A Brief Survey of Methods
Systematic search algorithms rely on a systematic way in their exploration of the search space.These methods [11][12][13][14][15][16] aim at exploring the entire solution space using tree search algorithms.The two main components of a tree search are the way to go forward, that is, which decision is taken at which point of the search and the way to go backwards, that is, the backtracking strategy that defines how the algorithm will behave when an inconsistency is detected.
In practice, methods based on systematic tree search may fail to solve large and complex CSPs instances because the computing time required may become prohibitive.For instance, a CSP with  variables, each with a domain of size , makes the search space which is to be explored proportional to (  ), that is, exponential in the number of variables.Most searches that come up in CSPs occur over spaces that are far too large to be searched exhaustively.One way to overcome the combinatorial explosion is to give up completeness.Stochastic local search (SLS) algorithms are techniques which use this strategy and gained popularity due to their conceptual simplicity and good performance.These methods start with an initial assignment of values to variables randomly or heuristically generated.During each iteration, a new solution is selected from the neighborhood of the current one by performing a move.A move might consist in changing the value of one randomly selected variable.Choosing a good neighborhood and a method for searching it is usually guided by intuition, because very little theory is available as a guide.If the new solution provides a better value in light of the objective function, the new solution becomes the current one.In order to avoid premature convergence, SLS methods resort to some sort of randomization (noise probability) to avoid local minima and to better explore the search space.The search is iterated until a termination criterion is reached.Most algorithms applied to CSPs use the so-called 1-exchange neighborhood under which two solutions are direct neighbors if, and only if, they differ at most in the value assigned to one variable.A basis for many SLS algorithms is the minimum conflict heuristic MCH [17].MCH iteratively modifies the assignment of a single variable in order to minimize the number of violated constraints.Since the introduction of MCH there have been a large number of local search heuristics proposed to tackle CSPs.Several representative state-of-the-art SLS in the literature include the break method for escaping from local minima [18], various enhanced MCH (e.g., randomized iterative improvement of MCH called WMCH [19], MCH with tabu search [20,21]), and a large body of work on evolutionary algorithms for CSPs [22][23][24][25][26] for interested readers.Weightsbased algorithms have been advocated by the intuition that, by introducing weights on variables or constraints, local minima can be avoided and the search process can learn to distinguish between critical and less critical constraints.Methods belonging to this category include genet [27], guided local search [28], discrete Lagrangian search [29], the exponentiated subgradient [30], the scaling and probabilistic smoothing [31], evolutionary algorithms combined with stepwise adaptation of weights [32][33][34], methods based on dynamically adapting weights on variables [35], or both (i.e., variables and constraints) [36].Weighting schemes have been also combined with systematic methods to reduce the size of tree search methods and consequently speeding up the solving time [37][38][39].Recently, an improved version of the Squeaky Wheel Optimization (SWO) [40] originated in [41] has been proposed for the scheduling problem.In SWO, a greedy algorithm is used to construct an initial solution which is then analyzed in order to identify those tasks that if improved are likely to improve the objective function score.The improved version provides additional postprocessing transformations to explore the neighborhood enhanced with a stochastic local search algorithm.Methods based on large neighborhood search have recently attracted several researchers for solving the CSP [42].The central idea is to reduce the size of local search space relying on a continual relaxation (removing elements from the solution) and reoptimization (reinserting the removed elements).Systematic methods exhibit poor performance on large problems because bad decisions made early in the search persist for exponentially long times.In contrast, stochastic local search methods replace systematicity with stochastic techniques for diversifying the search.However, the lack of systematicity makes remembering the history of past states problematic.To this end, hybrid search methods offering desirable aspects of both systematic methods and local search methods are becoming more and more popular and interested readers may refer to [43][44][45] to get a deeper understanding on these mixed methods.

Variable Depth Search Algorithm
Traditional local search algorithms for solving CSP problems start from an initial solution  and repeat replacing  with a better solution in its neighborhood () until no better solution is found in (), where () is a set of solutions obtained from  by updating the value of one selected variable.A solution  * is called locally optimal if no better solution exists in ( * ).The algorithm proposed in this paper belongs to the class of variable depth search algorithms where an existing solution is not modified just by making a change to a single variable; instead, the changes affect as many variables as possible when moving from one solution to another.The algorithm is inspired from the famous Kerninghan-Lin algorithm used for solving the graph partitioning problem [46] and the traveling salesman problem [47].The idea is to replace the search for one favorable move (i.e., the update of one variable) by a search for a favorable sequence of moves (i.e., the update of a series of variables) using the criterion of score to guide the search.The different steps of the algorithm are described in Algorithm 1.
(i) Random-initial-solution (): the algorithm starts building an initial solution.The initial solution is simply constructed by assigning to each variable   a random value V  from    (Line 5 of Algorithm 1).
Based on these values, the status of each constraint is set to either violated or nonviolated.(ii) Assign-Initial-Weights (): during this step the algorithm assigns a fixed amount of weight equal to 1 across all the constraints (Line 6 of Algorithm 1).The distribution of weights to constraints is a key factor to the success of the algorithm.During the course of the search, the algorithm forces hard constraints (i.e., those with large weights) to be satisfied thereby preventing the algorithm at a later stage from getting stuck at a local optimum.(iii) Stopping criterion: the outer loop (Line 7 of Algorithm 1) determines the stopping criterion met by the algorithm.The algorithm stops if a solution has been found (i.e., all the constraints are satisfied) or if a time limit has been reached.
(iv) Random-selected-variable (): a starting random variable from which the searching process begins is selected and added to the set T (Lines: 9, 10, and 11 of Algorithm 1).
(v) Inner loop: the inner loop (Lines: 12, 13, 14, 15, 16, 17, and 18 of Algorithm 1) proceeds by repeatedly selecting for each variable   removed from the set , the value V best from its domain    producing the highest score.Given the choice between several equally high scores, the algorithm picks one value at random.The score of a variable is defined as the increase (or decrease in the number of violated constraints) in the number of nonviolated constraints if   is assigned the value V  .The score is given by Score ( New ( ) .
(2) Equations ( 2) calculates the sum of the weights of the satisfied constraints the variable   is involved with.Ω(  ,   ) denotes the weight of the constraint connecting   and   while the second term returns the value of 1 if the constraint is satisfied and 0 otherwise.Thus, after the selection of V best and inserting  V best  into the set  Best , the status (i.e., violated or nonviolated) of the constraints for the neighboring variables of   is updated.Consider the following: (i) Highest cumulative score: an iteration of the algorithm terminates when the set  becomes empty.In this way, a sequence of scores with corresponding variables and their selected values is formed.Thereafter, the algorithm identifies the subset of variables having the highest cumulative score (HCS) (Line 19 of Algorithm 1).The identification of this subset is equivalent to choosing  so that HCS() in ( 3) is maximum, where represents the score of the variable   corresponding to the value V best .Finding  is the same as solving the maximum subarray problem introduced for the first time in [48].The problem is usually solved using Kadane's algorithm [49] which simply accumulates a partial sum and ); (21) if (HCS() ≥ 0) then (22) Assign all the variables up to the index  with their new best values; (23) else (24) Assign the variable at the index 1 with its new best value; (25) end (26) Adjust-Weights (); ( 27) end (28) end Algorithm 1: VNS-CSP.
updates the optimal range when this partial sum becomes larger than the global sum.If HCS ≥ 0, the solution is updated by substituting all the variables up to the index  with their new values; otherwise the update is restricted to just the first variable (index 1) (Lines: 20, 21, 22, 23, and 24 of Algorithm 1): (ii) Adjust-Weights: finally, the algorithm proceeds with the weighting process divided into two distinct steps (Line 25 of Algorithm 1).The weights of each newly violated constraint are then increased by one, whereas the newly satisfied constraints will have their weights decreased by one before another round of the algorithm is repeated or the stopping criterion is reached.This weighting procedure is the same as the one adopted in [18].

Test Instances.
The performance of the metaheuristic (VNS-CSP) has been tested on hard random CSP problems taken from Lecoutres benchmark [50] under the name RB-Model.This model enjoys several features that makes it of a great theoretical and practical interest [51].Tables 1 and 2 show the list of problem instances used in the experiments.The list contains 8 classes of problems each of which is composed of 5 instances, giving a total of 40 instances.Table 1 shows the list of solved hard problems, while Table 2 refers to those problems that remain challenging for most solvers.They are all located in the exact phase transition point [52] and the hardness of solving these instances grows exponentially with the number of variables.The first column denotes the number of variables, the second column the domain size of the each variable, and the third column the number of constraints; the fourth column specifies the combination of values not allowed (no-good) and the last column shows whether the instance has already been solved by an existing solver.All the benchmark instances used in this experiment are satisfiable instances.Each problem instance was run 100 times (i.e., each run is performed with a different seed) with a cut-off parameter (max-time) set to 15 minutes.
The tests were carried out on a DELL machine with 800 MHz CPU and 2 GB of memory.The code was written in C and compiled with the GNU C compiler version 4.6.and 2 show the evolution of the mean satisfied number of constraints as a function of the number of iterations for 4 hard problems that remain difficult for most solvers.These plots have been selected as they represent the general trend observed on all the problem instances.Investigating the trends of the algorithm from the plots suggests the presence of three different distinct phases.The first phase corresponds to the first iteration of the algorithm where all the constraints are assigned a weight equal to 1.This similar weight provides all the constraints with equal chances for being satisfied.In all the studied cases, the curves have a tendency to go uphill showing an improvement in the number of satisfied constraints.The second phase which takes most of the time corresponds to a diversification stage.During this second phase, the weights assigned to various constraints alter after each iteration depending on the status of the constraints (i.e., satisfied or unsatisfied) forcing the algorithm to favor the satisfaction of hard constraints (i.e, constraints with higher weights).This weighting of constraints results in worsening the quality of the solution by falling drastically during early stages of this phase (on average between 33% and 53%) and continues to exhibit a varying increasing decline rate over time before the curves start moving uphill marking the start of the intensification phase.This phase which tends to be of short duration compared to the diversification phase is characterized by the absence of downhill moves.A downhill move occurs when the set of changes determined by the algorithm reduces the number of satisfied constraints.
During the intensification phase, the algorithm intensifies the search around promising areas of the search space making the number of satisfied constraints to climb sharply until all the constraints of the problem are satisfied.The termination of the diversification phase ensures that each constraint relating at most two variables is assigned an ideal weight expressing its relative hardness taking into account the values assigned to its relating variables and the values of the variables defining the neighboring constraints.This ideal weight leads the system to enter a state of balance that is required for the intensification phase to be triggered leading the algorithm to easily reach the solution of the problem.Figures 3 and 4 show the evolution of the number of satisfied constraints and the sum of weights of satisfied constraints through the diversification and intensification phases, respectively.Figure 3 reveals that improving the sum of weights of satisfied constraints does not necessarily imply an increase in the number of satisfied constraints.Satisfying constraints with large weights may introduce a new set of unsatisfied constraints leading to a further decrease in the number of satisfied constraints.
Another interesting remark to be drawn from this plot is the ability of the algorithm to escape from the so-called plateau regions or local optima.Plateaus represent regions of the search space containing states with only equal or disimproving costs leaving the best solution unchanged.Figure 4 shows a continuous improvement of the two curves during the intensification phase until the solution of the problem is reached.Figure 5 shows the impact of weighting and nonweighting strategies on the algorithm's convergence.The plot illustrates the easiness encountered by the algorithm without the weighting mechanism in improving the number of satisfied constraints during the first iterations of the algorithm (up to 96% of the constraints are satisfied) before getting permanently stuck in long plateau regions or a local maximum leading to a premature convergence due to its greedy bias.The superior performance of the algorithm is Mathematical Problems in Engineering further made evident by looking at Table 3 which presents the results for already solved problem instances and unsolvable problem instances (instances in bold) that still present a challenge for all existing solvers.The results illustrate the performance of the algorithm reflecting its success ratio (i.e., defined as the ratio of successful runs with respect to the total number of runs) and the amount of time taken to reach the solution.From these results, the algorithm has a very good reliability (the success ratio is 100%).In terms of speed, VNS-CSP reaches the solutions in short computational times.Hence much of the difference in the run time (max-min) is due to the different random initial solutions and to the first chosen random variable that initiates the searching process.

Comparison with
State-of-the-Art Solvers.Tables 4-7 compare the time (i.e., the average time over 100 runs) required for different state-of-the-art solvers relative to that required by VNS-CSP.All these solvers are complete (i.e., systematic) solvers.The dash symbol means that the solver could not find the solution after 30 minutes.The first row on each table refers to the metaheuristic proposed in this work VNS-CSP.In all cases, the proposed metaheuristic remains the fastest of them all.The time of the proposed metaheuristic ranges from 10% to 90% of the time of the best solver and from 5 to several hundred times faster than the slowest solver.

Conclusions
This paper proposes a variable depth search algorithm for the CSP problem.The heart of the metaheuristic relies on a combination between an adaptive weighting strategy on the constraint weights and a greedy search.This combination proved to be an excellent mechanism to guide the search in order to achieve a suitable trade-off between intensification and diversification.The proposed metaheuristic has been experimentally evaluated on hard random CSP problems belonging to RB-Model.The difficulty of solving some of these problems by state-of-the-art solvers highlights the capabilities of the proposed metaheuristic.Indeed, the experimental results have been very positive, solving all unsolvable instances in very short computational times.Most metaheurirics have a predefined set of parameters that has to be calibrated with respect to the problem at hand.This parameter tuning which becomes a tedious task as the number of parameter increases plays a significant impact on the solving progress and therefore the solution quality.What distinguishes the proposed metaheuristic from state-of-theart techniques is the absence of parameter tuning making it highly suitable in practical scenarios.

Table 8
The second and third columns show the results of the two variants of ACO.The first number represents the number of solved instances, while the number in bracket gives the average CPU time on 3 GHz Intel Xeon.The last column shows the result of VNS-CSP.The time in bracket is the average time taken on DELL machine with 800 MHz CPU.This table is only meant as a rough guide since VNS-CSP and the other algorithms are run on different
machines.The table shows that the two variants of ACO and tabu are outperformed by VNS-CSP.VNS-CSP solved all the instances, while ACO-vertex has been able to solve 29 out of 40, ACO-clique 28 out of 40, and tabu 36 out of 40.Comparing the time of the different algorithms, VNS-CSP is the one requiring the least amount of time.