Abstract

Bidirectional singleton arc consistency (BiSAC) which is an extended singleton arc consistency (SAC) has been proposed recently. The first contribution of this paper is to propose and prove two theorems of BiSAC theoretically (one is a property of BiSAC and the other is the property of allowing the deletion of some BiSAC-inconsistent values). Secondly, based on these properties we present two algorithms, denoted by BiSAC-DF and BiSAC-DP, to enforce BiSAC. Also, we prove their correctness and analyze the space and time complexity of them in detail. Besides, for special circumstances, we show that BiSAC-DF admits a worst-case time complexity in and a best one in when the problem is an already BiSAC, while BiSAC-DP also has the same best one when the tightness is small. Finally, experiments on a wide range of CSP instances show BiSAC-DF and BiSAC-DP are usually around one order of magnitude faster than the existing BiSAC-1. For some special instances, BiSAC-DP is about two orders of magnitude efficient.

1. 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 depth-first 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 , 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 and a best one in . BiSAC-DP has a best-case time 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.

2. 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 which represents the set of tuples allowed for the variables involved in . We can say the tightness of is small if is large enough for , respectively. Problem is a subproblem of if , and , . 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.

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 . The CSP is arc consistent if and only if every value of every variable is arc consistent.

We use to represent the problem which is obtained after enforcing AC on a given problem . If there is a variable with an empty domain in , denote .

Definition 2. The value of variable is singleton arc consistent (SAC) if and only if the problem restricted to is arc consistent . The CSP is singleton arc consistent if and only if every value of every variable is singleton arc consistent.

From the definition of AC and SAC, we can clearly see SAC is stronger than AC. In 2008, Bessière extended SAC to a stronger level of local consistency and proposed a new technique—bidirectional SAC (BiSAC) [13]. Now we introduce BiSAC below.

Definition 3. The value of variable is bidirectional singleton arc consistent (BiSAC) if and only if , , where . The CSP is bidirectional singleton arc consistent if and only if every value of every variable is bidirectional singleton arc consistent.

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 and , respectively (see Algorithm 1).

(1)  repeat
(2)       false;
(3)    foreach     do
(4)      ;
(5)     foreach     do
(6)      if     AC( ) then   ;
(7)     if AC( , , ) =   then
(8)      D(X) D(X) ;
(9)      if  D(X) =   then return false;
(10)     CHANGEtrue;
(11) until not  CHANGE;
(12) return true;

3. 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.

3.1. Theoretical Analysis of BiSAC

Theorem 4. Let be a CSP and let be a subproblem of . Given ,(1) is bidirectional singleton arc consistent in , if is bidirectional singleton arc consistent in ; (2) is bidirectional singleton arc consistent in , if , where , .

Proof. (1) Let , where . Because is BiSAC in , thus is clearly concluded by the definition of BiSAC. For every , the fact that is a subproblem of can produce . Moreover, according to the correctness of AC procedure, for , if , then . Above all, it implies , where . Let ; hence, is a subproblem of the problem . According to the correctness of AC procedure again, implies . So is also bidirectional singleton arc consistent in by the definition of BiSAC.
(2) Let , where . Thus, is a subproblem of . Now, using the correctness of AC and the fact that , 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 .(1) is bidirectional singleton arc inconsistent in , if .(2) is bidirectional singleton arc inconsistent in , if and , where , .

Proof. (1) Let , where and . It means that and for every s.t. . Thus, according to the correctness of AC, can lead to . Therefore, () is bidirectional singleton arc inconsistent in by the definition of BiSAC.
(2) Let ; it means that every value in is arc inconsistent when the problem is restricted to . Besides, let where, . It implies and for every in and . Thus every element in must be in , so and is a subproblem of . However, every value in is arc inconsistent in by the correctness of AC. Again, this correctness and will lead to . Thus is bidirectional singleton arc inconsistent in . So, conclusion (2) is obtained.

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.

3.2. 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 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 (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.

Theorem 6. BiSAC-DF is a correct algorithm to enforce bidirectional singleton arc consistency.

Proof. Consider the following.
Soundness. Suppose is the first BiSAC value removed by BiSAC-DF. It is necessarily removed in line 22 of the function Judge-DF. It means that the structure occur is , and at this time it goes to line 22 only from line 6 or line 14. Hence, if it jumps from line 6, it implies . The main loop in Judge-DF was executed only once because the structure occur is , so . Therefore, is bidirectional singleton arc inconsistent in according to conclusion (1) of Theorem 5. Jumping from line 14, it is implied that and ; conclusion (2) of Theorem 5 admits that is also bidirectional singleton arc inconsistent in . Therefore, this contradicts the assumption that is the first BiSAC value removed by BiSAC-DF. So, BiSAC-DF is sound.
Completeness. When the BiSAC-DF terminated, for every , is removed from Queue if the clause repeat (in Judge-DF) is executed for the first time. It means , where , . According to the definition of BiSAC, is bidirectional singleton arc consistent in . Otherwise, it is concluded that , where , . Theorem 4 can ensure that is also bidirectional singleton arc consistent in . Thus, BiSAC-DF is complete.

Theorem 7. BiSAC-DF admits a space complexity in and a worst-case time complexity in .

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 when the loop repeat is executed times. Notice that the number of variable-value pairs in is also . Let be the total times of calling Judge-DF at iterative times in the loop repeat (in BiSAC-DF), and let 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 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 Therefore, the times of AC called by BiSAC-DF are . If an optimal AC is used, then the time complexity is , such as AC-2001. So, the worst-case time complexity of BiSAC-DF is , namely, .

(1) repeat
(2)   CHANGE false;
(3)   foreach     do
(4)      ;
(5)   while  Queue   do
(6)     if Judge-DF() =   then return false;
(7) until not  CHANGE
(8) return true;

Theorem 8. Applied to a constraint network which is BiSAC, the worst-case time complexity of BiSAC-DF is and the best-case time complexity is .

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 times and the total is . Thus, worst-case time complexity is . For the best case, it only executes Judge-DF exactly once (finding a lucky solution). So the number of calling AC is at    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 .

(1)   ;
(2)   ;
(3)  repeat
(4)   get ( , ) from s.t. vars( ) and ( , ) ;
(5)    AC( );
(6)   if  BP =   then goto   ;
(7)   flag false;
(8)   foreach ( , )   do
(9)     if ( , )   AC( ) then
(10)      
(11)      flag true;
(12)   if flag = true then
(13)     AC( );
(14)    if   =   then goto   ;
(15)        else ;
(16)   else ;
(17)until vars( ) = vars( );
(18)return Solution;
(19) L:
(20)if   then
(21)  CHANGE true;
(22)   ;
(23)  if   =   then return   ;
(24)else
(25)   ;
(26)   ;

(1) repeat
(2)  CHANGE   false;
(3)  foreach     do
(4)    ( );
(5)   if Judge-DP( , ) =      Judge-DP( , ) =   then
(6)     return false;
(7) until not  CHANGE;
(8) return true;

(1)   ;
(2)   ( ;
(3)  if   then return true;
(4)  if   ( , ) =   then goto   ;
(5)  if AC( ) = then goto   ;
(6)  foreach ( , ) s.t do
(7)   if AC   then
(8)    if exist s.t. (   AC( ) then
(9)       ;
(10)  if AC( )   then return true;
(11) L:
(12)  if     then
(13)    ;
(14)    true;
(15)   if     then return ;
(16)      else return true;
(17)   ;
(18)  if Judge-DP(     Judge-DP( ) =   then return   ;
(19)  return true;

3.3. BiSAC-DP Algorithm

Another algorithm BiSAC-DP is also based on the previous propositions, but it is not depth-first 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 by the constraint , where the value s.t. such that . 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 at worst without additional data structure. Actually, if , the function of operator is the same as forward checking (FC). For , it can be considered as the extended forward checking. Note that the operator is only used to improve efficiency through finding an appropriate special subproblem. However when ; we cannot say that the current problem has no solutions. Actually, in that case all values in are also necessary to be propagated for BiSAC. So, a “good” domain for is very important for efficiency of our algorithm. Therefore, we introduce divide-conquer strategy to automatically find an appropriate subdomain.

The function BiSAC-DP partitions the domain of every variable into two subdomains firstly and then calls the function Judge-DP to establish the BiSAC. This process terminates until the fix-point is reached. It means that every value in the current subdomain is bidirectional singleton arc consistent when function Judge-DP returns true. Otherwise, it means that a domain has wiped out when it returns .

The main function of Judge-DP is to determine whether all values in subdomain are BiSAC in the special subproblem. If they are all BiSAC, then they return true; otherwise it needs to partition the current subdomain. Firstly, Judge-DP uses operator to find the special subproblem. If (line 4), the function would go to label L. Otherwise, Judge-DP calls the AC. It would still go to L if AC returns too. Otherwise, it enforces BiSAC on this current problem (line 6–line 10). Theorem 4 can ensure that it is BiSAC in if it is BiSAC in the current subproblem for every value in sub-domain (line 10). However, if not, it also needs to go to L for further processing. In label L, according to the definition of BiSAC, if , the single value in is bidirectional singleton arc inconsistent, so it must be removed (line 13). However, if , the current subdomain needs to be partitioned further (line 18).

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, ). If it goes through line 5, then and . So conclusion (1) of Theorem 5 admits is bidirectional singleton arc inconsistent in . Through line 4, and can also be concluded because and . So the same result can be obtained. Otherwise, from line 10 and , 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.
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.

Theorem 10. BiSAC-DP admits a space complexity in and a time complexity in , 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 .

Corollary 11. The worst-case time complexity of BiSAC-DP is , and the best-case time complexity is .

Proof. The worst-case of running BiSAC-DP is that there is exactly one value removed from its domain when the loop (see line 3 in BiSAC-DP) terminates. So it calls the function Judge-DP times. The number of partitions produced by calling the function Judge-DP once is at most , where . Consequently, . Thus the worst-case time complexity is . However the best case is . The best-case time complexity is obtained.

From the above proofs, the time complexity of the algorithm BiSAC-DP is 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.

4. 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” [1416] 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 , where defines a number of variables, defines the size of domains, (density) defines how many constraints appear in the problem, and (tightness) defines how many pairs of values are inconsistent in a constraint. This paper chooses , while and 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.

5. 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 worst-case time complexity . For different cases, they also have the same best-case time complexity . 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.

Acknowledgments

The authors of this paper express sincere gratitude to all the anonymous reviewers for their hard work. This work was supported in part by NSFC under Grant nos. 61170314, 61272208, and 61373052.