New Algorithms for Bidirectional Singleton Arc Consistency

1 College of Computer Science and Technology, Jilin University, Changchun 130012, China 2 Key Laboratory of Symbol Computation and Knowledge Engineering of Ministry of Education, Jilin University, Changchun 130012, China 3 College of Computer Science and Information Technology, Northeast Normal University, Changchun 130117, China 4 School of Computer Science and Technology, Soochow University, Jiangsu 215006, China


Introduction
Constraint satisfaction problem (CSP) is an important researching area in artificial intelligence.Many combinatorial problems can be solved by modeling as CSP.However, it is the NP-complete task of determining whether a given CSP instance has a solution.Fortunately, consistency techniques can reduce the search space and speed up solving process by removing the inconsistent values [1].Many notions and algorithms of consistency have been proposed to achieve these goals so far.Among these techniques, arc consistency (AC) [2] is the oldest and most well-known way of filtering domain.This is indeed very simple and natural.More importantly, it is an effective technique to solve CSP instances.Now there are many algorithms to enforce it.For example AC-3 [3], AC-4 [4], and AC-2001 [5] are all very efficient methods and they are very easy to implement.Besides, nowadays singleton arc consistency (SAC) [6] has been focused on widely.It can remove redundant values like arc consistency and path consistency [7], but the power of pruning the inconsistent values is stronger than that of AC.In fact, it ensures that the problem is also arc consistent after assigning any value to any variable.Debruyne and Bessière proposed a straightforward algorithm SAC-1 [6], and Prosser studied SAC again [8].Consiquently, the second algorithm SAC-2 [9] has been proposed by Bartok.It is based on AC-4 and uses external data structures to avoid invoking the AC procedure to test SAC condition more times than SAC-1.Bessière and Debruyne presented the algorithms SAC-OPT [10] and SAC-SDS [11].SAC-OPT has the optimal time complexity with a high space complexity.SAC-SDS has a better space complexity though it is not optimal in time.However, it tries to avoid redundant work.Lecoutre proposed the first depthfirst greedy algorithm SAC-3 [12].Bessière and Debruyne (2008) studied the comprehensive theoretical of SAC and proposed a new local consistency-bidirectional singleton arc consistency (BiSAC) [13] by extending the SAC.They have also proved BiSAC is stronger than SAC and presented the first algorithm BiSAC-1 to enforce it.Zhang et al. proposed the algorithms BiSAC-DF and BiSAC-DP (Algorithms 4 and 5), both of them were the enforced algorithms of BiSAC.
In this paper, we firstly propose two properties of BiSAC and then prove their correctness.Based on them, we present two algorithms to enforce BiSAC, denoted by BiSAC-DF and BiSAC-DP.BiSAC-DF is inspired by algorithm SAC-3 proposed by Lecoutre, and it is also a depth-first greedy algorithm.The BiSAC-DP also uses the previous properties as a theoretical foundation and combines domain partition and divide-and-conquer strategy.Besides, we propose operator  on subdomain to improve the efficiency of it.Also we prove their correctness and analyze their complexity.Finally, in our experiments on random CSPs, classical problems, and benchmarks, the results show that our algorithms perform better than the BiSAC-1.
In terms of complexity, BiSAC-DF and BiSAC-DP have a space complexity in () and a worst-case time complexity in ( 3  5 ), where  is the number of variables,  is the greatest domain size, and  is the number of constraints.In particular, when applied to an already bidirectional singleton arc consistent problem, BiSAC-DF admits the worst-case time complexity in ( 2  4 ) and a best one in ( 2  3 ).BiSAC-DP has a best-case time ( 2  3 ) if the tightness of the problem is relatively small.Notice that it does not mean the problem is BiSAC if the tightness of it is small.Actually, the problem which is an already BiSAC may have a high tightness.

Preliminaries
A constraint satisfaction problem  = (, , ), where  is a finite set of  variables,  is a finite set of domains for every variable, and  is a finite set of  constraints.For each variable  ∈ , its domain is denoted by () ∈ . will denote the size of the greatest domain.We can use the label   to represent the domain set of the problem .Each   ∈  has an associated relation denoted by rel  (  ) which represents the set of tuples allowed for the variables involved in   .We can say the tightness of  is small if |rel  (  )| is large enough for ∀  ∈ , respectively.Problem  is a subproblem of  if ∀ ∈ ,   ⊆   and ∀  ∈ , rel  (  ) ⊆ rel  (  ).A solution of a constraint satisfaction problem is an assignment of value from its domain to each variable such that every constraint is satisfied.A problem is said to be satisfiable if it admits at least one solution.We denote  = ⊥ if there is a variable  of  and   () wipes out.
A constraint satisfaction problem can be characterized by properties called partial consistency.It always removes some inconsistent values and some inconsistent pairs of values.There are many methods to do this.Now, we introduce several important notions.In this paper, we focused on binary CSP.In [13] Bessière proposed a straightforward algorithm BiSAC-1 to enforce bidirectional singleton arc consistency.Its correctness and its space and time complexity are (1) and ( 3  5 ), respectively (see Algorithm 1).

New Algorithms to Enforce BiSAC
In this paper, we propose two algorithms to enforce BiSAC.Before describing them, we need to present two important theorems of BiSAC.They not only provide a theoretical basis for correctness of our algorithms, but also can improve efficiency for our algorithms.

Theoretical Analysis of BiSAC
if D(X) = 0 then return false; (10) CHANGE ← true; (11) until not CHANGE; (12) return true; subproblem of the problem   .According to the correctness of AC procedure again, AC(   ) ̸ = ⊥ implies AC(  ) ̸ = ⊥.So (, ) is also bidirectional singleton arc consistent in  by the definition of BiSAC. ( is a subproblem of   .Now, using the correctness of AC and the fact that AC(   ) ̸ = ⊥, AC(  ) ̸ = ⊥ is deduced correspondingly.Hence conclusion ( 2) is obtained by the definition of BiSAC.
Actually conclusion (1) exploits BiSAC of the subproblem  to ensure that (, ) is BiSAC in .So it can avoid revoking the redundant AC procedure (see Definition 3).Conclusion (2) can be a similar result through a combination of definition of BiSAC and subproblem .It is not enough although Theorem 4 as a property of BiSAC can conclude that (, ) is BiSAC in .We also need another property to ensure (, ) is bidirectional singleton arc inconsistent in .
Theorem 5. Let  = (,   , ) be a CSP and (, ) ∈ .Theorem 5 is a property of bidirectional singleton arc inconsistency.Conclusion (1) of it, using the fact that problem  restricted to  =  is arc inconsistent, can infer (, ) is bidirectional singleton arc inconsistent in .Another conclusion also can tell us (, ) is bidirectional singleton arc inconsistent in  through arc inconsistency of a special subproblem.Actually, these theorems together provide a theoretical basis for soundness and completeness of our algorithms.More importantly, they are also approaches to speed up the efficiency of consistency technique.Now, we propose two algorithms to enforce BiSAC, denoted by BiSAC-DF and BiSAC-DP, which rely on Theorems 4 and 5.

BiSAC-DF Algorithm.
The first algorithm BiSAC-DF is inspired by SAC-3, which is also depth-first greedy approach.Moreover the above theorems can improve efficiency and ensure correctness of BiSAC-DF.The function BiSAC-DF firstly puts all variable-value pairs in the structure Queue and then calls the function Judge-DF to establish BiSAC.If the Judge-DF returns ⊥, it means there exists a domain that wipes out.So the BiSAC returns false.Otherwise, this processing continues until a fix-point is reached.
The function Judge-DF performs a depth-first search in order to instantiate variables, but it does not have a backtrack mechanism when dead ends occur.As long as, the current branch, no inconsistency is found, we try to extend it.In other words, the current problem  is restricted to  =  and then arc consistency is maintained.So a subproblem AC(| = ) is generated correspondingly.The other value pairs will be judged whether they are BiSAC on this current subproblem.Theorem 4 concludes that (, ) is BiSAC in  if it is BiSAC in sub-problem or AC(| = ) ̸ = ⊥ (line 15 and line 25).In particular, it maybe finds a lucky solution (line 18).For bidirectional singleton arc inconsistency, a dead end must occur.In that case, Theorem 5 can tell us that (, ) is bidirectional singleton arc inconsistent in  if the structure occur is null (line 6 and line 14).Therefore, the value  should be removed from the domain of the variable .If this domain wipes out, the algorithm terminates and returns ⊥ (line 23).Otherwise, we cannot judge whether (, ) is BiSAC or not.So, it needs further propagations.Proof.The additional data structure in BiSAC-DF is Queue and , while the space of them is also (), so the overall space complexity of BiSAC-DF is ().The worst-case of running BiSAC-DF is that there is exactly one value removed from its domain when the loop (see line 5 in Algorithm 2) terminates.In that case, the number of elements in Queue is ( −  + 1) when the loop repeat is executed  (1 ≤  ≤ ) times.Notice that the number of variable-value pairs in  is also (−+1).Let  be the total times of calling Judge-DF at  iterative times in the loop repeat (in BiSAC-DF), and let del  be the number of elements removed from Queue at  times of calling Judge-DF.From the function Judge-DF, it is easily concluded that the times of calling AC are at most ( −  + 1) when a value is removed from Queue.Thus, at  iterative times in the loop repeat (in BiSAC-DF), the total number of calling AC is ( ←  ∪ {(, )}; (5) while Queue ̸ = 0 do (6) if Judge-DF() = ⊥ then return false; (7) until not CHANGE (8) return true; Algorithm 2: BiSAC-DF.
Proof.When it is applied to a BiSAC network, there will be no value removed.It implies that the loop repeat (in Algorithm 2) is executed only once.During this procedure, the number of elements in Queue is .For every element in Queue, in the worst-case, it needs call AC 2 ×  times and the total is 2 × () 2 .Thus, worst-case time complexity is 2 × () 2 × ( 2 ) = ( 2  4 ).For the best case, it only executes Judge-DF exactly once (finding a lucky solution).So the number of calling AC is ( − ) +  at  (1 ≤  ≤ ) iterative times in the loop repeat (in Algorithm 3).Note that the number of elements in  is ( − ) + .Thus, the total of calling AC is ( So the best-case time complexity is /2 × (( + 1) + (1 − )) × ( 2 ) = ( 2  3 ).Completeness.When the BiSAC-DP terminated, for every (, ) ∈ , (, ) is checked or   is checked for BiSAC, where   is subdomain of  and (, ) ∈   .If (, ) is checked, then (, ) is BiSAC in  by Theorem 4. Otherwise, the same result is also obtained by the definition of operator  and Theorem 4. Thus, BiSAC-DP is complete.

BiSAC-DP
Theorem 10.BiSAC-DP admits a space complexity in () and a time complexity in ( 3 ), where  denotes the number of partitions built by the BiSAC-DP.
Proof.The BiSAC-DP has only the additional data structure  and the space complexity of it is ().So the space complexity of BiSAC-DP is ().From the function partition, we can see that the number of calling AC is  when the Judge-DP (from lines 1 to 10) is executed only once.So, the time complexity of BiSAC-DP is 2 ×  ×  × ( 2 ) = ( 3 ).
From the above proofs, the time complexity of the algorithm BiSAC-DP is ( 2  3 ) when  = .In that case, the tightness of problem must be small enough.For another algorithm BiSAC-DF, it has the same time complexity if it can find a solution in an already BiSAC constraint network.Note that a problem whose tightness is small may not be a bidirectional singleton arc consistent.In other words a bidirectional singleton arc consistent problem may have a big tightness.

Experiments
To compare the different algorithms mentioned in this paper, we have performed experimentation with respect to random CSPs, classical problems, and benchmarks.Performances have been measured in terms of the CPU time in seconds and the number of checks performed by BiSAC.All algorithms have been implemented in C++ and embedded into the constraint solving platform "Ming Yue" [14][15][16] designed by us.In this platform, we use dom/deg variable ordering and choose the AC with heuristic information [17] because it is easy to implement and very efficient.The experiments were carried out on a DELL Intel PIV 3.0 GHz CPU/512 MB RAM with Windows XP Professional SP2/Visual C++6.0.Random constraint satisfaction problems have become a standard for testing constraint satisfaction algorithms and heuristic algorithms because of their randomness [18].A binary random constraint satisfaction problem (http://www.lirmm.fr/∼bessiere/generator.html) is specified by four parameters ⟨, ,  1 ,  2 ⟩, where  defines a number of variables,  defines the size of domains,  1 (density) defines how many constraints appear in the problem, and  2 (tightness) defines how many pairs of values are inconsistent in a constraint.This paper chooses  =  = 20, while  1 and  2 range from 0.05 to 0.95 (interval is 0.05).Figure 1 shows the difference of running times for BiSAC-1 and BiSAC-DF and a ratio BiSAC-1/BiSAC-DF.From Figure 1(a) we can see that the average running time required by BiSAC-DF is much less than that of BiSAC-1.Actually, from the right graph of Figure 1, we can know that BiSAC-DF is around 2-5 times faster the BiSAC-1 for small tightness.When the tightness is relatively big, BiSAC-DF is about 10-25 times than BiSAC-1.For some special combination of the density and tightness, BiSAC-DF can reach about 30 times the BiSAC-1.All of them can be explained by the fact that the times of revoking AC procedure of BiSAC-DF are much less than BiSAC-1, and BiSAC-DF can determine whether (, ) is BiSAC earlier than BiSAC-1.Figure 2 tells us that the number of checks performed by BiSAC-DF is also much smaller than BiSAC-1.For the other algorithm BiSAC-DP, the running time is also less than BiSAC-1.In fact, it is less than BiSAC-DF too (see Figure 3).For small tightness BiSAC-DP is about 2-20 times the BiSAC-1 because the BiSAC-DP can find the appropriate subproblem earlier and more easily so that lots of values can be inferred BiSAC without more BiSAC checks.For the other tightness, BiSAC-DP is on average 40-60 times the BiSAC.BiSAC-DP is around 100 times faster than BiSAC-1 when density ranges from 0.5 to 0.6, and tightness is set to about 0.7, which is not surprising since BiSAC-DP not only uses the operator  to find a good subproblem successfully, but also avoids much redundant work at testing BiSAC checks.Figure 4 also shows that BiSAC-DP performs a visibly smaller number of checks than BiSAC-1.
Besides random CSPs, we have made our algorithms apply to classical problems like Queens, Pigeons, and Color problems.From Table 1, we can see BiSAC-DF and BiSAC-DP also outperform BiSAC-1 on range of CSP instances.On average, the efficiency of BiSAC-DF is about 3 times that of BiSAC-1, and BiSAC-DP is around 8-20 times faster than BiSAC-1.
Table 2, built from other instances (http://cpai.ucc.ie/05/Benchmarks.html),shows that our algorithms also have a better performance than BiSAC-1.Especially, BiSAC-DP and BiSAC-DP are about 1000 times more efficient than BiSAC-1 for the instances-"qk." For frb and Lsq dg, our  algorithms are 2-3 times more efficient than BiSAC-1.However, BiSAC-DF is slower than BiSAC-1.Maybe this is because that the procedure of depth-first instantiating variables delays the time of finding the domain which has been wiped out.

Conclusion
In this paper, we made a study of bidirectional singleton arc consistency and then proposed two properties.Based on these properties, two algorithms (BiSAC-DF and BiSAC-DP) were proposed.Besides, we theoretically prove that these algorithms have the same space complexity () and worstcase time complexity ( 3  5 ).For different cases, they also have the same best-case time complexity ( 2  3 ).Because our algorithms do not invoke the AC procedure to test the BiSAC condition more times than the original BiSAC-1, so they avoid lots of redundant works and have a better performance.Our experimental results also show that our approaches significantly outperform BiSAC-1 on range of CSP instances, and it will be applied to solve large scale real life problems coming from the scheduling and configuration areas.

Theorem 9 .
BiSAC-DP is a correct algorithm to enforce bidirectional singleton arc consistency.Proof.Consider the following.Soundness.Suppose (, ) is the first BiSAC value removed by BiSAC-DP.It is necessarily removed in line 13 of the function Judge-DP.It implies that the subdomain   only contains one value (  = {}).From the Judge-DP, it goes to line 13 only through line 4, line 5, or line 10 (in this case, AC() = ⊥).If it goes through line 5, then AC() = ⊥ and  = | = .So conclusion (1) of Theorem 5 admits (, ) is bidirectional singleton arc inconsistent in .Through line 4, AC() = ⊥ and  = | = can also be concluded because   = {} and (, ) = ⊥.So the same result can be obtained.Otherwise, from line 10 and AC() = ⊥, in this case, according to conclusion (2) in Theorem 5, (, ) is also bidirectional singleton arc inconsistent in .Above all, this contradicts the assumption.So, BiSAC-DP is sound.

Figure 2 :
Figure 2: A comparison of number of checks performed by BiSAC-1 and BiSAC-DF.The left shows a relative comparison (BiSAC-1 − BiSAC-DF), while the right shows number of checks ratio (BiSAC-1/BiSAC-DF).Check is measured in million.

Figure 4 :
Figure 4: A comparison of number of checks performed by BiSAC-1 and BiSAC-DP.The left shows a relative comparison (BiSAC-1 − BiSAC-DP), while the right shows number of checks ratio (BiSAC-1/BiSAC-DP).Check is measured in million.
Definition 1.The value  of variable  is arc consistent (AC) if and only if, for each variable  connected by the constraint , there exists a value  of  such that (, ) ∈ rel  ().The CSP is arc consistent if and only if every value of every variable is arc consistent.We use AC() to represent the problem which is obtained after enforcing AC on a given problem .If there is a variable with an empty domain in AC(), denote AC() = ⊥.The value  of variable  is bidirectional singleton arc consistent (BiSAC) if and only if AC(  ) ̸ = ⊥,   = (,   , ), where   () = { ∈   () | (, ) ∈ AC(| = )}.The CSP is bidirectional singleton arc consistent if and only if every value of every variable is bidirectional singleton arc consistent.
is a subproblem of   .However, every value in   \   is arc inconsistent in   by the correctness of AC.Again, this correctness and AC(   ) = ⊥ will lead to AC(  ) = ⊥.Thus (, ) is bidirectional singleton arc inconsistent in .So, conclusion (2) is obtained.
() = {} and    () ⊆   () for every  in  and  ̸ = .Thus every element in   \   must be in   \  , so   \   ⊆  and Algorithm.Another algorithm BiSAC-DP is also based on the previous propositions, but it is not depthfirst greedy approach.So it cannot find a lucky solution.However, it combines domain partition technique and uses the operator  presented by us to find a special subproblem so that it saves lots of redundant work.Now we propose operator : let  = (, , ); operator (, ) must remove every value  from the domain of every variable  connected with Algorithm 5: Judge-DP (,   ).
by the constraint , where the value  s.t.∃ ∈ () such that (, ) ∉ rel  ().During removing values, if a domain wipes out, operator  returns ⊥; otherwise, it returns the new problem.From the definition, we know operator  can run in ( 2 ) at worst without additional data structure.Actually, if |()| = 1, the function of operator  is the

Table 1 :
Results obtained on classical problems.

Table 2 :
Results obtained on benchmarks.