ITE: A Lightweight Implementation of Stratified Reasoning for Constructive Logical Operators

# ITE: A Lightweight Implementation of Stratified Reasoning for Constructive Logical Operators

## Abstract

Constraint Programming (CP) is a powerful declarative programming paradigm where inference and search are interleaved to find feasible and optimal solutions to various type of constraint systems. However, handling logical connectors with constructive information in CP is notoriously difficult. This paper presents If Then Else (ITE), a lightweight implementation of stratified constructive reasoning for logical connectives. Stratification is introduced to cope with the risk of combinatorial explosion of constructing information from nested and combined logical operators. ITE is an open-source library built on top of SICStus Prolog clpfd, which proposes various operators, including constructive disjunction and negation, constructive implication and conditional. These operators can be used to express global constraints and to benefit from constructive reasoning for more domain pruning during constraint filtering. Even though ITE is not competitive with specialized filtering algorithms available in some global constraints implementations, its expressiveness allows users to easily define well-tuned constraints with powerful deduction capabilities. Our extended experimental results show that ITE is more efficient than available generic approaches that handle logical constraint systems over finite domains.

Constraint Programming; Constructive Disjunction; Stratified Reasoning.
{history}

## 1 Introduction

Constraint Programming (CP) is a powerful programming paradigm which is useful to model and solve difficult combinatorial problems. The paradigm has proved its advantage to tackle a large variety of real-world problems, spanning from car manufacturing, configuration design to energy production and hardware and software engineering. As compared with other paradigms such as Linear Programming or Dynamic Programming, one of the key advantages of CP is related to its expressivity. CP usually embeds a rich constraint language expressing several types of relations, including arithmetical, numerical, logical, and symbolic constraints, as well as various computational domains, such as integers, reals, lists, strings, trees, graphs, etc.

However, unlike SAT-solving, CP has traditionally only considered conjunctions of constraints. Even though powerful reasoning capabilities are available in CP, disjunctions are usually treated in a simple way by separating the disjuncts and solving them separately without trying to reconstruct some combined information from disjuncts. Similar approaches have been depicted for negation, implications and conditionals. So, in traditional CP, a Constraint Satisfaction Problem (CSP) is composed of a set of constraints, implicitly combined via conjunction, and a set of variables, each of them having a finite variation domain. Dealing efficiently with general disjunction in CP has always been perceived as challenging, because of the uneasy but necessary trade-off between inference and search. On the one hand, inference tries to deduce as much information as possible from the constraints themselves, while search, by making hypothesis, explores a large search space where constraints are used to prune inconsistent branches. In this process, disjunctions just render the process inefficient as they cannot be used to prune subtrees of the search tree. Noticeable extensions include the definition of global constraints which embed specialized and efficient filtering algorithm for disjunctive reasoning, such as element [10], nvalue [20], cumulative [2], ultrametric [17] or disjunctive [9].

To illustrate the usual absence of inference for disjunctive constraints, consider the following request1 to SICStus Prolog clpfd [6], a state-of-the-art CP solver over Finite Domains:

###### Example 1

(#\/ is the logical or operator of clpfd, based on reification)
Query: Y in 62..77, (X#=6) #\/ (X#=13) #\/ (X#=Y).
Answer: X in inf..sup

In this example, as no information is known on the FD_variable X, the solver cannot refute any of the disjuncts and thus cannot perform any pruning. As a consequence, the domain of X is left unconstrained (i.e., inf..sup where inf and sup denote and ). For this request, a stronger (and expected) answer would be the following:

###### Example 2

(cd, available in ITE, means constructive disjunction)
Q: Y in 62..77, (X#=6) cd (X#=13) cd (X#=Y).
A: X in{6}\/{13}\/(62..77)

Getting this result requires to use some global reasoning through a constructive disjunction operator, that is an operator able to construct knowledge from both disjuncts, without knowing which one will eventually be true. In most CP implementations, the ’constructive disjunction’ operator is unfortunately not natively available, as it is considered too costly to propagate [11].

Note that, besides the simple example given above, more complex constraints can be combined using logical operators, such as in the following example:

###### Example 3

(cn means constructive negation)
Q: A in 1..10, B in 1..10,
 (A#>1,B#<9)cd(A#>2,B#<10), (A+7#=<B)cd(cn(B+7#>A)).
A: A in 8..10, B in 1..3

Constructive reasoning requires to propagate domain reduction over each disjunct before any constructive information can be propagated through the constraint network. Such constructive information is often crucial to solve efficiently some practical real-world problems originating from planning [4], scheduling [18], software engineering [7] or configuration. However, it comes at a certain cost which needs to be controlled in order to deal with an inevitable combinatorial explosion when the number of disjunctive operators grows.

In this paper, we propose an open-source and open-access library called If Then Else (ITE)2, which implements a lightweight approach to constructive operators on top of an existing Prolog-based CP solver, namely SICStus Prolog clpfd. ITE includes constraints such as constructive disjunction, negation, implication, conditional, where parametric stratified reasoning is available to cope with the inherent combinatorial explosion of disjunctive reasoning. By comparing various operators which handle disjunctions in SICStus Prolog clpfd, we show that ITE is a good compromise between inference and search to solve problems for which specialized global constraint is not available. In particular, we propose lightweight implementations of several useful global constraints with ITE which demonstrate the versatility and expressiveness of the library as compared to existing methods.

The rest of this paper is organized as follows. The next section presents some of the related works and positions our work. Section 3 introduces the necessary background and notations to understand the rest of the paper. Section 4 presents constructive disjunction and negation and discusses of their implementation. This section also presents the various implementations of relaxation of entailments. It contains several examples to help the reader understand the proposed approach. Section 5 proposes stratified reasoning to cope with possible combinatorial explosion. Section 6 gives the implementation of several global constraints with ITE. Section 7 gives our experimental results with ITE, while Section 8 concludes this work and proposes further work.

## 2 Related Work

Constructive disjunction is not new in CP. Besides the initial proposition by Van Hentenryck [10], several implementations have been proposed in different CSP solvers including Oz [27], Gecode [24], SICStus Prolog [3] or Choco4 [21]. Implementation of constructive disjunction propagators in CP solvers is usually considered straightforward when it is perceived as an extension of constraint reification [12]. In that case, it suffices to associate a Boolean variable to any constraint, representing its truth value, and use Boolean constraints to combine the constraints. This approach is available in Choco4, for example, with its embedded SAT solver. In SICStus Prolog clpfd, besides the constraint reification mechanism, a more sophisticated approach is available through the smt global constraint [3] which propagates disjunctive linear information. Reasoning over disjunctions of temporal constraints has also been extensively considered in CP, with specialized algorithms [26].

The problem with the reification approach is that it propagates little constructive information. Entailment is usually poorly deductive as it is limited to local reasoning, that is, local filtering over the variables of the reified constraint. In most cases, more constructive knowledge can be propagated but the implementation of constructive disjunction requires a good tradeof between inference and search. An interesting attempt in that direction is given in [25, 19] where interval reasoning is used to propagate more information through constraint refutation. The proposed approach is however limited to numerical constraint systems and does not easily extend to finite domains constraints. Similarly, [15] presents an algorithm which is as powerful as constructive disjunction but requires to maintain satisfying assignments for the constraints of the disjuncts. This approach thus requires to modify in depth the solver and in particular the filtering algorithm of each propagator. Taking inspiration of SAT-solving where part of the success comes the ability to propagate efficiently or-constraints, [11] proposes to maintain active at most two constraints of the disjunction at any time. By implementing new features within the solver such as satisfying sets, constraint trees and movable triggers, the approach of [11] successfully achieves important speedups for various disjunctive models, including the supertree problem which makes use of the ultrametric global constraint [17]. A more lightweight method is given in [1] where the goal is to encode various global constraints with logical connectives such as Or, And, Not and characterize the cases where generalized arc-consistency (GAC) can be achieved. In that respect, [11] generalizes the approach of [1] by proving that their proposed filtering algorithm for Or enforces GAC when all its disjunct constraints are GAC-filtered, and no variables is shared among the disjuncts. Recently, an attempt was made to propose specialized global constraints dedicated to disjunctive problems. In particular, [9] introduced linear-time filtering algorithms for the Disjunctive constraint, which is a simplified version of the Cumulative global constraint. Even though these propositions are interesting to develop a library of logical connectives, we observe that they require to modify in depth the constraint solver and/or its constraint propagators and that they do not guarantee to filter as constructive disjunction can deduce. The implementation of constructive disjunction presented in this paper has this property and can be added on top of any constraint solver. Its expressivity is also strengthened by the possible combination with recursion as shown in various global constraints implementations (see Section 6). The downside is however rooted in the inherent complexity of propagating constructive information which makes the approach innapropriate in a number of cases. We thus introduce stratified reasoning to cope with the inherent risk of combinatorial explosion of full constructive disjunction reasoning.

## 3 Background

### 3.1 Constraint Satisfaction Problems

Constraint Satisfaction Problems (CSP) are materialized by where stands for a set of variables, each variable taking a value in a finite domain such that stands for the Cartesian Product and, is a set of constraints. A constraint of arity , is a relation over a subset of variables from which restrains the acceptable tuples for the relation. The subset of variables involved in the relation, noted , is usually known in advance, but there are cases where the size of the subset is parameterized by the problem instance. In the former case, the relations are called primary constraints while they are called global constraints in the latter. is said to be satisfied by an assignment of its variables to values from their domain iff evaluates to true with this assignment. A CSP is said to be satisfiable iff there exists at least one full assignment of its variables such that all constraints in are satisfied. In that case, the assignment is called a solution. The set of all solutions of a CSP is written by . When the CSP has no solution or one of its domain is empty, then is said to be unsatisfiable or inconsistent. Formally,

###### Definition 1

(Inconsistency) A CSP is inconsistent iff at least one of its domain is void, i.e., such that in .

Solving a CSP means to either exhibit a solution or to prove inconsistency. In both cases, local filtering consistencies are used to address this question. Among the many filtering consistencies proposed in the literature, we will focus only on two well-known, namely hyperarc-consistency and bound-consistency.

###### Definition 2

(hyperarc-consistency) For a given CSP , a constraint is hyperarc-consistent if for each of its variable and value there exist values in such that is satisfied. A CSP is hyperarc-consistent if for each of its constraints , is hyperarc–consistent.

Filtering a CSP with hyperarc-consistency, also known as generalized arc-consistency (GAC), can be very demanding in terms of time or space computational resources. That is why other consistencies, less demanding, have been introduced. Among them, bound-consistency is a good compromise.

###### Definition 3

(bound-consistency)
A constraint is bound-consistent if for each variable and value there exist values in such that is satisfied. In this definition, stands for (obviously ). A CSP is bound-consistent if for every constraint , is bound-consistent.

In this paper, we will use a generic function name to refer to the CSP filtering process, namely a function called propagate. The function takes as inputs a constraint to filter and the Cartesian product of all domains , and returns filtered domains . This function is parametrized by , which is a user-defined parameter used to define stratified reasoning. More details on CSP and local filtering consistencies can be found in [16, 23, 14] and a detailed presentation of the parameter is given in Section 5. Note that when is irrelevant, i.e., when there is no stratified reasoning, then is assimilated to and the function becomes .

### 3.2 Global Constraint Definition

As said above, global constraints are relations over an unknown subset of variables. Typical examples include the all_different constraint [22] which constrains all variables to take different values (here, is a user-defined parameter) or the element which constrains to be equal to . An important feature of modern CSP solvers is their ability to let the user define its own global constraints. Using such a mechanism allows us to propose a lightweight implementation of logical connectives on top of an existing solver, avoiding the need to revise deeply the architecture of the solver itself.

Defining a global constraint requires three elements given by the user:

1. (Interface) An interface which contains the name for the constraint, along with a list of FD_variables possibly unbounded, and optionally some input parameters ;

2. (Algorithm) Each time the global constraint is awaked into the propagation queue of the CSP solver, a filtering algorithm has to be launched with the goal to eliminate as many inconsistent values of the variable domains as possible. This algorithm can use not only the current status of variable domains but also the status as it was in the previous awakening of the constraint. This is usually referred as the notion of state of the constraint ;

3. (Awakening) Guidance to the awakening of the constraint in the propagation queue must also be provided. It is important to decide when to launch the filtering algorithm in order to avoid any misusage of the constraints. Typical examples of awakening conditions include the change of boundaries of variable domains involved into the relation or the assignment of one of its variables.

As a concrete example, let us present the global constraint definition of SICStus Prolog clpfd which allows the users to define new global constraints through an interface composed of two distinct parts:

1. dispatch_global(Constraint, S0, S, Actions)
This predicate tells the solver that the predicate Constraint is a new global constraint. Constraint defines the interface of the constraint, while Actions define what actions to take. These actions include conditions when global inconsistency is proved (i.e., failing condition), when constraint entailment is proved (i.e., success), and when partial satisfaction is obtained through variable binding or domain reduction. S0, S are used to store previous and current states of the variable domains while applying the filtering algorithm ;

2. fd_global(Constraint, State, Suspensions)
This predicate is used to post an instance of the constraint Constraint. Suspensions define the awakening conditions which include, in this implementation, variable binding, boundaries reduction or domain reduction. State contains the current state of the variables domain.

Using this mechanism, it is thus possible to implement various types of constraints, including those which are used to combine constraints with logical operators.

### 3.3 Syntax of the Constraint Language

The syntax of ITE constraint language is detailed in Fig. 1.

The language contains several operators working on classical arithmetic constraints. It also introduces logical operators such as which are typically useful to represent logical constraints. Note that the language introduces two version of constructive negation and constructive disjunction in order to distinguish the versions of these operators which implement stratified reasoning from the others. Both logical implication and if_then_else operators only use stratified reasoning as it is more useful (See Section 5 for more details). This language is powerful as it allows us to perform various forms of disjunctive reasoning.

## 4 Constructive Operators

Implementing meta-constraints such as disjunction, negation, implication, etc. requires to reason on the truth value of constraints and their possible (dis-)entailment by the current status of the CSP [5].

###### Definition 4

(entailment)
A constraint is entailed by a CSP iff, for any solution of , the constraint is satisfied. On the contrary is disentailed iff for any solution of , is violated.

Note that, by construction, all constraints of are entailed by the CSP . In the above definition, is not necessary part of .

###### Example 4

If all tuples of are solutions of a CSP then the constraint is entailed by , while the constraint is disentailed because none of the tuples satisfy the constraint.

Proving constraint entailment or disentailment is as demanding as finding all solutions of a CSP. As solving CSP is NP-hard in the general case [10], relaxations of constraint entailment have been proposed.

### 4.1 Relaxations of Constraint Entailment

Entailment checking in practical settings is based on local consistency filtering. Two partial entailment tests have been introduced in [10]: domain-entailment and interval-entailment which are based on hyperarc-consistency and bound-consistency respectively (See Section 3). Another partial entailment test can be introduced here based on constraint refutation, namely Abs-entailment. Abs-entailment is a relaxation of entailment which exploits the filtering capabilities of the entire CSP to try to refute the negation of the constraint. Using more formal presentation, we now describe these three relaxations of entailment which are available in ITE.

###### Definition 5

(domain-entailment)
Let be a CSP where , then a constraint is domain-entailed by iff, for all domains and all values , is satisfied.

Based on this definition, a constraint can be entailed, but not necessary domain-entailed by a CSP . On the contrary, the opposite is true: any constraint which is domain-entailed is also entailed by .

###### Example 5

If , and then the constraint is entailed by but not domain-entailed. is entailed because all satisfying tuples of , namely are also solutions of . But, the constraint is not domain-entailed because there exist pairs in which do not satisfy , e.g., the pair .

Domain-entailment is a local property as it requires only to examine the tuples of with respect to the current domains of its variables. At the same time, proving domain-entailment is demanding as it requires to examine all satisfying tuples of , which can be time-consuming when domains are huge. Another less-demanding relaxation is thus proposed in some solver implementations.

###### Definition 6

(interval-entailment)
A constraint is interval-entailed by a CSP iff, for all domains and all values in , the constraint is satisfied.

Obviously, if a constraint is interval-entailed by a CSP , then is also domain-entailed as . But, the opposite is not true. Nevertheless, these two relaxed versions of entailment are quite similar and both are used in implementations of classical (non constructive) negation and disjunction. For instance, both are used in SICStus Prolog clpfd for implementing the reification operator. This operator is used to evaluate the truth value of any constraint, including some global constraints [3].

### 4.2 Abs-entailment

We introduce here another partial entailment test which is based on constraint refutation :

###### Definition 7

(abs-entailment)
A constraint is abs-entailed by a CSP iff filtering the CSP with a local consistency property, yields to an inconsistency. Formally, is abs-entailed iff

This definition is operational as it is based on concrete filtering properties that are available in most CSP solvers. In practice, as hyperarc-consistency and bound-consistency are sound relaxations of consistency, it is trivial to see that abs-entailment is a sound relaxation of entailment. Indeed, if is inconsistent then entails .

Unlike domain-entailment or interval-entailment, abs-entailment is not a local property, restricted to the constraint . It involves all the constraints of the CSP and requires the computation of . In addition, it requires the restoration of the computational state after the test of inconsistency of . This comes at the cost of calling recursivelly the solver and can thus be innapropriate in some cases. Nevertheless abs-entailment is more powerful to deduce entailment and prune domains than domain- and/or interval-entailment. We make use of it for implementing the logical connectives of ITE.

### 4.3 Constructive Disjunction

By using a global constraint definition mechanism, such as the one presented earlier, it is possible to introduce a new constructive disjunctive operator, i.e., within a CSP solver with the simple algorithm Alg.1 shown below.

Alg.1 makes use of the propagate function which is provided by the solver for filtering any constraint system. It is obviously parametrized by the level of consistency offered by the solver and its implemented constraints. Note that testing if or is void is actually an implementation of the abs-entailement test for the disjunctive operator. Indeed, testing if (resp. ) is like checking if is abs-entailed (resp. ). Alg.1 implements a monotonic propagator as it returns filtered domains which are necessarily a subset of , i.e., . It is trivial to see that only , or , or else can be returned. In addition to filtered domains, Alg.1 also returns a status of the cd constraint, which can be either or , as explained in Section 3.2.

The algorithm works over as a whole here but it can perform over any projection of over a subset of its domains. In particular, a restricted version of this algorithm can project over the union of variable domains of and , namely . This allows us to preserve the local property of constraint filtering. Note that the two successive calls to show that the solver is actually called twice for each cd operator, which can lead to a combinatorial explosion of the number of calls to the solver when the number of disjunctive constraints grows. This raises the question of what to do when, during the recursive calls to the solver, other cd operators are encountered. The following example illustrates the normal behaviour of the generic algorithm.

###### Example 6

Q: A in 1..5, B in 1..5, C in 1..5,
Q (A-B#=4)cd(B-A#=4),(A-C#=4)cd(C-A#=4).
A: A,B,C in {1}\/{5}

The values 2,3,4 are pruned from the domains of A,B,C because any pairwise combination of the constraints will prune these values, but this powerful deduction has been obtained by solving 4 constraint systems in this example. This nested analysis may lead to very precise results but, at the price of being computationally expensive. In Section 5, we introduce stratified reasoning as a way to cope with the possible combinatorial explosion of this reasoning, but let us examine first the other logical operators using constructive reasoning.

### 4.4 Constructive Negation

Typical negation operators in Logic Programming implement negation-as-failure, which triggers failure when the negated goal succeeds and conversely. Although very useful in many contexts, this operator coincides with logical negation only when the negated goal is grounded, which means that all its variables are bound. In the general case, when negating a constraint, there are several unbounded variables and then posting the negation of that constraint cannot be handled anymore with the negation-as-failure operator. Constructive negation in Constraint Logic Programming has been proposed to cope with this issue, using Clarke’s completion process [8]. Unfortunately, for CSPs, only a few implementations have been considered. In ITE, we propose an implementation called cn, which is based on a combination of negation-as-failure, De Morgan’s rewriting rules and constructive disjunction.

The following rewriting rules are considered:

where is the complementary of
where is the negation of

This approach is useful for unary operators such as constructive negation, as it allows us to eliminate the negation from any request. For the language given in Fig.1, it is not difficult to see that by pushing negation on elementary constraints, only negated elementary constraints remain and that they can easily be eliminated by negating the corresponding operators. For a more extended language including added global constraints, this approach would require to include the negation of global constraints which is more problematic, even though approaches exist [13, 3].

### 4.5 Other Operators

Other logical operators based on constructive disjunction can be implemented using similar principles. In particular, exclusive disjunction (noted cxd), logical implication (=>) and conditional (ite) are easy to derive from the implementation of constructive disjunction. For exclusive disjunction , when performing the abs-entailment test for one disjunct, e.g., , we can propagate the negation of this disjunct in addition to the other constraint, i.e., we can perform . Adapting Alg.1 for cxd is thus not difficult.

Logical implication can be translated as follows: is equivalent to , but such a transformation replaces one binary operator (=>) by two operators (). Even though this approach is certainly acceptable, in CSP solving, it is interesting to keep the number of operators as low as possible. That is why we preferred, in this case, an approach where => is implemented as a new operator with its own filtering algorithm based on a variation of Alg.1. Note that, as CSP works on finite domains, the closed world hypothesis guarantees that there is no solution available which satisfies both and . Similarly any conditional operator such as , representing if() then else , can trivially be converted into an exclusive disjunction operator by using the equivalent formulae: . But, here again, we preferred a dedicated implementation of its filtering algorithm. The following example illustrates the usage of when it is combined with other constraints.

###### Example 7

Q:ite(I0#=<16, J2#=J0*I0, J2#=J0, ENV), J2#>8, J0#=2.
A: J0 = 2, I0 in 5..16, J2 in 10..32

## 5 Stratified Reasoning

In the previous section, we have proposed implementations of logical operators without paying much attention to the computational cost of propagating disjunctive constraints. Even though filtering by hyperarc-consistency and bound-consistency is time-polynomial for elementary constraints in the worst case, the number of inconsistency checks performed can rapidly explode and lead to some unwanted combinatorial explosion. Indeed, the number of abs-entailment tests grows exponentially with the number of cd in the formulae. In order to cope with this problem, we propose stratified reasoning which aims at exploring disjuncts up to a certain depth, controlled by the user. This process is stratified as it allows the user to increase the depth to be explored and thus to reason by strates.

In concrete implementation terms, by setting up a user-defined parameter to a positive integer (usually a small value), one can decrease by one each time an inconsistency check (abs-entailment test) is performed. When reaches the value , then the abs-entailment test is simply discarded, avoiding so to perform an uncontrolled and redundant exploration of all disjunctions. A straightforward algorithm based on this idea is given in Alg.2. In this algorithm, the variable captures general information about the computational environment, including the value of . While performing the abs-entailment test with the function, is simply decreased.

This way of handling disjunctive reasoning is correct and does not compromise the final result of CSP solving: it just delays full reasoning up to the final labeling stage. In fact, when there is no variables left in a disjunct, i.e., when all the variables have been labelled in one disjunct, then one can discard the cd operation by evaluating that disjunct. This explains the presence of tests in Alg.2.

The following examples illustrates the benefit of stratified reasoning. By setting up different values of the user-defined parameter , one gets distinct results with the same constraint system. Predicates init_env/2 and end_env/1 are used to set up the environment for solving the formulae with ITE. Note that when the parameter is equal to in this example, one gets the maximal possible deduction as all tuples are solutions and increasing its value does not bring any other result.

###### Example 8

Q:init_env(E,[kflag(3)]),cd(cd(X=0,cd(Y=4,Y=5,E),E),X=9,E),
 cd(cd(Y=9,Y=6,E),cd(Y=2,Y=7,E), E), end_env(E).
A: X in {0}\/{9}, Y in {2}\/(6..7)\/{9}

Q:init_env(E,[kflag(2)]),cd(cd(X=0,cd(Y=4,Y=5,E),E),X=9,E),
 cd(cd(Y=9,Y=6,E),cd(Y=2,Y=7,E), E), end_env(E).
A: X in inf..sup, Y in {2}\/(6..7)\/{9}

Q:init_env(E,[kflag(1)]),cd(cd(X=0,cd(Y=4,Y=5,E),E),X=9,E),
 cd(cd(Y=9,Y=6,E),cd(Y=2,Y=7,E), E), end_env(E).
A: X in inf..sup, Y in inf..sup

Formalizing the concept of maximal , we get the following definition.

###### Definition 8

(maximal k)
For a given CSP and any disjunctive constraint of , the user-selected parameter is said to be maximal iff is the greatest value such that and .

Note that the parameter is totally unrelated to the level of achieved consistency and that finding maximal k does not guarantee to achieve any kind of consistency. In the example, when the result is neither domain- or bound- consistency.

We conjecture that maximal can be approached by using the immediate successor of the maximum depth of any disjunctive constraint in the formulae but we do not have a proof of this. However, this conjecture is evaluated and discussed in the experimental Section 7 of the paper. Stratified reasoning appears to be a good trade-off between search and inference, although coupled with a decision of which aspect is more important.

## 6 Global Constraints with ITE

The ITE library can be used to implement various global constraints. In this section, we show a selection of various global constraints which reveal the expressiveness of the constructive operators.

### 6.1 Ultrametric constraint

The Ultrametric constraint, as proposed in [17], is a ternary constraint defined as follows:

 X>Y=Z∨Y>X=Z∨Z>X=Y∨X=Y=Z

Its implementation in ITE is straightforward:

###### Example 9

(Ultrametric constraint)
um3(X, Y, Z, ENV):-
 cd(cd((X#>Y,Y=Z),(Y#>Z,X=Z),ENV),cd((Z#>X,X=Y),(X=Y,Y=Z),ENV),ENV).

Note that balancing the cd connectors is advantageous for ITE so that the depth of the formulae remains minimal.

### 6.2 Domain Constraint

The Domain constraint is defined over a set of variables as follows: Domain is true when . Note that the Domain constraint is natively available in SICStus Prolog clpfd with bool_channel(L, X, #=, 0). Its implementation in ITE shows the combined usage of constructive disjunction and recursion:

###### Example 10

(Domain constraint)
domctr(X, L, ENV) :-
 length(L, N), X in 1..N, domain(L, 0,1),
 domctr(N, X, L, ENV).

domctr(1, X, [X1], ENV) :- !, X=1, X1=1.
domctr(N, X, [X1|L], ENV) :- N>2, !,
 N1 is N-1,
 cd((X=1,X1=1,domain(L,0,0)),
 (X#>1,X1=0,Y in 1..N1,incr(X,Y),domctr(N1,Y,L,ENV)),ENV).

incr(X, Y) +:
 X in dom(Y)+1,
 Y in dom(X)-1.

Using domctr in one of the disjuncts of the cd constraint illustrates the interest of ITE in terms of expressiveness. In fact, constraint reasoning can easily be combined with recursion to create powerfull implementations of global constraints. Even though they have less filtering capabilities than specialized algorithms, these implementations can help the developer to create very quickly a dedicated constraint which has interesting deduction capabilities. Note that we had to create or our constraint with incr(X,Y) in order to reach domain-consistency.

### 6.3 Element Constraint

We give here an implementation of the well-konwn Element constraint [10], which is based on very similar principles as Domain:

###### Example 11

(Element constraint)
elemctr(I, L, J, ENV):-
 length(L, N),
 I in 1..N,
 elemctr(N, I, L, J, ENV).

elemctr(1, I, [X1], J, _ENV) :- !, I=1, J#=X1.
elemctr(N, I, [X1|L], J, ENV) :- N>2, !,
 N1 is N-1,
 cd((I=1,X1#=J),(I#>1,I1 in 1..N1,incr(I,I1),elemctr(N1,I1,L,J,ENV)),ENV).

### 6.4 Lex Constraint

The Lex constraint is true iff . It can be implemented in ITE as follows:

###### Example 12

(Lex constraint)
lexctr(X, Y, ENV):-
 X=[X1|Xs], Y=[Y1|Ys],
 lexctr(Xs, Ys, [X1], [Y1], fail, T, ENV),
 call(cd(X1#<Y1, T, ENV)).

lexctr([], [], _LX, _LY, TIN, TIN, _ENV) :- !.
lexctr([X|Xs],[Y|Ys],LX,LY,TIN,TOUT,ENV) :-
 gen_eq(LX, LY, T1),
 T = cd(TIN, (X#<Y, T1), ENV),
 lexctr(Xs,Ys,[X|LX],[Y|LY],T,TOUT,ENV).

gen_eq([X], [Y], (X#=Y)) :- !.
gen_eq([X|Xs], [Y|Ys], (X#=Y, T)) :-
 gen_eq(Xs, Ys, T).

This constraint is natively available in SICStus Prolog clpfd under the name lex_chain.

### 6.5 Mulctr Constraint

Unlike the previous ones, the Mulctr is not available in the clpfd library and can be implemented easily. The constraint Mulctr is a specialized constraint which is true iff . Its implementation in ITE can be as follows:

###### Example 13

(Mulctr constraint)
mulctr(OP, N, X, Min, Max, ENV):-
 X#>=Min, X#=<Max, fd_max(X,Xmax),fd_max(N,Nmax),
 Mmax is (Xmax div Nmax),
 gen_mulctr(1, Mmax, N, X, [], L),
 mulctr1(L, T, ENV),call(T).

gen_mulctr(M, M, _N, _X, L, L):-!.
gen_mulctr(M, Mmax, N, X, T, [X#=M*N|Xs]):-
 M1 is M+1,
 gen_mulctr(M1, Mmax, N, X, T, Xs).

mulctr1([CTR], CTR, _ENV) :-!.
mulctr1([CTR|S], cd(CTR,CS,ENV), ENV):-!,
 mulctr1(S, CS, ENV).

### 6.6 Disjunctive Constraint

The Disjunctive constraint is true iff for all pairs of tasks such that , where is the duration of task and is the horizon, i.e., . Its implementation in ITE can be as follows:

###### Example 14

(Disjunctive Constraint)
disjctr(S, P, H, ENV) :-
 joinsp(S, P, SP),gen_disj(SP, G, ENV),
 append(S, P, VSP), sum(VSP, #=, H),call(G).

joinsp([], [], []).
joinsp([X|Xs], [Y|Ys], [(X,Y)|S]) :-
 joinsp(Xs, Ys, S).

gen_disj([_], true, _ENV):- !.
gen_disj([X|XL], (G1, G), ENV) :-
 gen_disj1(X, XL, G1, ENV),
 gen_disj(XL, G, ENV).

gen_disj1((Si,Pi),[(Sj,Pj)], RES, ENV ) :-!,
 RES = cd( Si+Pi#=<Sj, Sj+Pj#=<Si, ENV).
gen_disj1((Si,Pi),[(Sj,Pj)|YL], RES, ENV):-
 RES = (cd( Si+Pi#=<Sj, Sj+Pj#=<Si, ENV), G),
 gen_disj1((Si,Pi), YL, G, ENV).

## 7 Experimental Results

To confirm the effectiveness of the lightweight approach to constructive disjunction, we compare the implementation of global constraints using ITE to the default implementations from SICStus Prolog. As benchmark scenarios, we use constraint formulations which heavily rely on disjunctive clauses. Specifically, we use the global constraints Domain, Element, Lex and Mulctr as described in Section 6.

### 7.1 Setup

For all constraints, we compare the implementation using ITE’s cd and cd(K) operators with an implementation using the regular operators from clpfd. We also compare to the global constraints implementation of SICStus Prolog, except for mulctr, which is not implemented in clpfd.

The benchmark dataset and its execution scripts are available as part of the ITE software package3. All experiments have been performed with SICStus Prolog version 4.5.1 on Linux running on an Intel i7-6820HQ (2.70 GHz) with 16 GB RAM.

### 7.2 Experiments

In the following, we will describe the actual experiments performed and their results. In summary, before showing the detailed results, constraints implemented on ITE are mostly competitive and outperforming the corresponding implementations using the regular clpfd operators. An implementation of the constraints using smt is usually not efficient, due to the limitation of smt to linear constraints. If available, a global constraint implementation from the clpfd library is most efficient. For all experiments, we combine the global constraint with a deterministic labeling predicate to ensure the exact same search process is performed by each implementation.

However, we do not claim that ITE can outperform a highly optimized implementation of a specific global constraint. Instead, and this is one of the major contributions of the ITE framework, it is a versatile and flexible approach for constructive disjunction, which is a building block of many complex constraint constructions, such as the global constraints which we consider in the experiments. Therefore, the goal of the experiments, which is confirmed by the results, is that the advantage of ITE’s expressiveness does not lead to a performance decrease, but is competitive or in some cases exceeding the performance of regular operators.

#### Domain

As the first global constraint, we employ Domain as described in Section 6.2 and its implementations in ITE, regular clpfd, smt and the clpfd global constraint.

The experiment is performed by labeling an list of 0/1 variables with side constraint , such that is maximized: . Labeling is used to ensure all implementations perform the same search and we actually measure the difference in propagation performance. We vary the number of elements from with a timeout of 5 minutes.

The results are shown in Figure 2. Best performance is shown by the clpfd global constraint, as expected. This implementation is written in native C and highly optimized, where as the other results are based on a composition of standard constraints, either from clpfd or ITE. The slow performance of smt is explained as it does not natively support non-linear constraints and requires an alternative formulation of the constraint. Using ITE without an additional parameter , i.e. cd, is competitive to the performance of the implementation with regular clpfd operators and performs better when the number of elements is small to medium. When using an additional parameter , i.e. cd(2) and cd(3), ITE is faster to resolve the expressions than the other methods, except the clpfd global constraint.

#### Element

The second global constraint is Element as described in Section 6.3, with results shown in Figure 3. A larger number of elements makes the problem more complex, such that smt exceeds the timeout of 1 minute for and cd for . cd with an additional parameter , i.e. cd(3) and cd(4), are able to resolve all expressions within the time limit. The implementation using regular clpfd operators does not resolve any of the expressions within the timeout, whereas the global constraint implementation of clpfd is the most efficient.

#### Lex

The Lex global constraint (Section 6.4) shows interesting behaviour with a small number of elements . With elements, the regular clpfd implementation exceeds the timeout and does not resolve the expression, but with larger , this problem does not occur and the performance is actually better than ITE’s.

#### Mulctr

Finally, for evaluation of the Mulctr global constraint (Section 6.5), a larger number of values is considered (). However, there is no standard implementation in clpfd and we also do not provide an implementation in smt. Therefore, this experiment mostly focuses on the differences within ITE parametrization.

The results are shown in Figure 5 and show three main aspects: a) a misparametrization can have a performance impact, as shown by cd(2); b) once a minimum parameter value has been found, the actual performance differences vary not much more, as shown by cd(3)-cd(7); c) the non-parametrized cd is a good starting point, as it can have good or better performance than the parametrized versions.

## 8 Conclusion

In this paper, we have introduced ITE, a open-source, open-access lightweight implementation of constructive operators in Prolog-based CSP solvers. Our implementation provides a variety of operators which are useful to compute logical combination of constraints, including some global constraints. By exploiting abs-entailment, a relaxation of entailment, and global constraint definition mechanisms, ITE has interesting expressiveness capabilities and good tradeof between inference and search. To cope with the risk of combinatorial explosion of constructive reasoning, our approach provides stratified deduction, which is a versatile technique which requires only to set up a single parameter. Exploring various parameter values, we show that ITE with stratified reasoning is an advantageous alternative to implement some global constraints with more powerful deduction mechanisms than reification.

Our experimental results show that ITE is competitive with available tools to deal with disjunctive reasoning, namely reification with domain- and interval- entailment and the smt global constraint. It is however not competitive with dedicated filtering algorithms used specialized global constraints. As future work, we plan 1) to propose to automatically adjust the value of for stratified reasoning through heuristic reasoning and 2) to explore the capability to infer more symbolic information from disjunctions than just pure domain information. The later proposition would require to propagate not only domains, but also deduced variable relations. This is a challenging problem as there does not exist any general recipe to perform the union of symbolic information in CSP solving.

## Acknowledgements

This work is supported by the Research Council of Norway under the grant agreement Certus SFI.

### Footnotes

1. All the example queries of the paper can be replayed by using SICStus Prolog version 4.5.0, augmented with ITE
2. Available at https://github.com/ite4cp/ite
3. Available at https://github.com/ite4cp/ite

### References

1. Fahiem Bacchus and Toby Walsh. Propagating logical combinations of constraints. In IJCAI-05, Proceedings of the Nineteenth International Joint Conference on Artificial Intelligence, Edinburgh, Scotland, UK, July 30 - August 5, 2005, pages 35–40, 2005.
2. Nicolas Beldiceanu, Mats Carlsson, Sophie Demassey, and Emmanuel Poder. New filtering for the cumulative constraint in the context of non-overlapping rectangles. Annals of Operations Research, 184(1):27–50, Apr. 2011.
3. Nicolas Beldiceanu, Mats Carlsson, Pierre Flener, and Justin Pearson. On the reification of global constraints. Constraints, 18(1):1–6, January 2013.
4. Minh Binh Do and Subbarao Kambhampati. Planning as constraint satisfaction: Solving the planning graph by compiling it into CSP. Artificial Intelligence, 132(2):151–182, 2001.
5. B. Carlson, M. Carlsson, and D. Diaz. Entailment of Finite Domain Constraints. In Proc. of 11th International Conference on Logic Programming. MIT Press, 1994.
6. M. Carlsson, G. Ottosson, and B. Carlson. An Open–Ended Finite Domain Constraint Solver. In Prog. Lang., Impl., Logics, and Programs (PLILP), 1997.
7. Stefano Di Alesio, Shiva Nejati, Lionel Briand, and Arnaud Gotlieb. Stress testing of task deadlines: A constraint programming approach. In Int. Symposium on Soft. Reliability and Engineering (ISSRE’13), Research track, Pasadena, CA, USA, Nov. 2013.
8. François Fages. Constructive negation by pruning. J. Log. Program., 32(2):85–118, 1997.
9. Fahimi Hamed and Claude-Guy Quimper. Linear-time filtering algorithms for the disjunctive constraint. In In Proc. of the Twenty-Eighth AAAI Conference on Artificial Intelligence (AAAI’18), New Orleans, USA, 2018.
10. Pascal Van Hentenryck, Vijav Saraswat, and Yves Deville. Design, implementation, and evaluation of the constraint language cc(fd). Journal of Logic Programming, 37:139–164, 1998. Also in CS-93-02 Brown–University 1993.
11. Christopher Jefferson, Neil C. A. Moore, Peter Nightingale, and Karen E. Petrie. Implementing logical connectives in constraint programming. Artif. Intell., 174(16-17):1407–1429, November 2010.
12. Mikael Z. Lagerkvist and Christian Schulte. Propagator groups. In Principles and Practice of Constraint Programming - CP 2009, 15th International Conference, CP 2009, Lisbon, Portugal, September 20-24, 2009, Proceedings, pages 524–538, 2009.
13. Nadjib Lazaar, Noureddine Aribi, Arnaud Gotlieb, and Yahia Lebbah. Dfa-based formulation for constraint negation. In Proc. of the 11th Int. Workshop on Constraint Modelling and Reformulation (ModRef’12), in the 18th Int. Conf. on the Principles and Practice of Constraint Prog. (CP 2012) in Quebec City, Canada, 2012.
14. Christophe Lecoutre. Constraint Networks: Techniques and Algorithms. ISTE/Wiley. ISBN 978-1-84821-106-3, 2009.
15. Olivier Lhomme. An efficient filtering algorithm for disjunction of constraints. In Principles and Practice of Constraint Programming - CP 2003, 9th International Conference, CP 2003, Kinsale, Ireland, September 29 - October 3, 2003, Proceedings, pages 904–908, 2003.
16. Kim Marriott and Peter J. Stuckey. Programming with Constraints : an Introduction. The MIT Press, 1998.
17. Neil C. A. Moore and Patrick Prosser. The ultrametric constraint and its application to phylogenetics. Journal of Artificial Intelligence Research (JAIR), 32:901–938, 2008.
18. Morten Mossige, Arnaud Gotlieb, Helge Spieker, Hein Meling, and Mats Carlsson. Time-aware test case execution scheduling for cyber-physical systems. In Proc. of Principles of Constraint Programming (CP’17), Aug. 2017.
19. Bertrand Neveu, Gilles Chabert, and Gilles Trombettoni. When interval analysis helps inter-block backtracking. In International Conference on Principles and Practice of Constraint Programming, pages 390–405. Springer, 2006.
20. F. Pachet and P. Roy. Automatic generation of music programs. In In Proc. of Constraint Programming Conf. (CP’99), Washington, VA, number 1713/2004 in LNCS, pages 331–345. Springer Verlag, 1999.
21. Charles Prud’homme, Jean-Guillaume Fages, and Xavier Lorca. Choco Documentation. TASC - LS2N CNRS UMR 6241, COSLING S.A.S., 2017.
22. Jean-Charles Régin. A filtering algorithm for constraints of difference in csps. In Proc. of the 12th National Conference on Artificial Intelligence, Seattle, WA, USA, July 31 - August 4, 1994, Volume 1., pages 362–367, 1994.
23. F. Rossi, P. van Beek, and T. Walsh, editors. Handbook of Constraint Programming. Elsevier, 2006.
24. Christian Schulte and Peter J. Stuckey. Efficient constraint propagation engines. Transactions on Programming Languages and Systems, 31(1):2:1–2:43, December 2008.
25. Gilles Trombettoni and Gilles Chabert. Constructive interval disjunction. In Principles and Practice of Constraint Programming - CP 2007, 13th International Conference, CP 2007, Providence, RI, USA, September 23-27, 2007, Proceedings, pages 635–650, 2007.
26. Ioannis Tsamardinos and Martha E. Pollack. Efficient solution techniques for disjunctive temporal reasoning problems. Artificial Intelligence, 151(1):43 – 89, 2003.
27. Jörg Würtz and Tobias Müller. Constructive disjunction revisited. In 20th Annual German Conference on Artificial Intelligence (KI’96), Dresden, Germany, pages 377–386, 1996.
You are adding the first comment!
How to quickly get a good reply:
• Give credit where it’s due by listing out the positive aspects of a paper before getting into which changes should be made.
• Be specific in your critique, and provide supporting evidence with appropriate references to substantiate general statements.
• Your comment should inspire ideas to flow and help the author improves the paper.

The better we are at sharing our knowledge with each other, the faster we move forward.
The feedback must be of minimum 40 characters and the title a minimum of 5 characters