# An Introduction of FD-Complete Constraints

Sven Löffler, Ke Liu, Petra Hofstedt

► To cite this version:

Sven Löffler, Ke Liu, Petra Hofstedt. An Introduction of FD-Complete Constraints. 16th IFIP International Conference on Artificial Intelligence Applications and Innovations (AIAI), Jun 2020, Neos Marmaras, Greece. pp.27-38, 10.1007/978-3-030-49186-4_3. hal-04060688

HAL Id: hal-04060688

https://inria.hal.science/hal-04060688

Submitted on 6 Apr 2023

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
<figure><img src="image_2.png" /></figure>

ifip

International Federation for Information Processing

This document is the original author manuscript of a paper submitted to an IFIP
conference proceedings or other IFIP publication by Springer Nature. As such, there
may be some differences in the official published version of the paper. Such
differences, if any, are usually due to reformatting during preparation for publication or
minor corrections made by the author(s) during final proofreading of the publication
manuscript.
# An Introduction of FD-Complete Constraints

Sven Löffler, Ke Liu, and Petra Hofstedt

Brandenburg University of Technology Cottbus-Senftenberg, Germany
Sven.Loeffler@b-tu.de

**Abstract.** The performance of solving a constraint problem can often be improved by converting a subproblem into a single constraint (for example into a regular membership constraint or a table constraint). In the past, it stood out, that specialist constraint solvers (like simplex solver or SAT solver) outperform general constraint solvers, for the problems they can handle. The disadvantage of such specialist constraint solvers is that they can handle only a small subset of problems with special limitations to the domains of the variables and/or to the allowed constraints. In this paper we introduce the concept of fd-complete constraints and fd-complete constraint satisfaction problems, which allow combining both previous approaches. More accurately, we convert general constraint problems into problems which use only one, respectively one kind of constraint. The goal is to interpret and solve the converted constraint problems with specialist solvers, which can solve the transformed constraint problems faster than the original solver the original constraint problems.

**Keywords:** Constraint Programming · CSP · Refinement · Optimizations · Regular Membership Constraint · Regular CSPs · Table Constraint · FD-Completeness

## 1 Introduction

Constraint programming (CP) is a powerful method to model and solve NP-complete problems in a declarative way. Typical research problems in CP are among others rostering, graph coloring, optimization, resource management, planning, scheduling and satisfiability (SAT) problems [12].

Because the search space of constraint satisfaction problems (CSPs) and constraint satisfaction optimization problems (CSOPs or COPs) is immensely big and the solution process often needs an extremely high amount of time we are always interested in improving the solution process. There are various ways to describe a CSP in practice and consequently, the problem can be modeled by different combinations of constraints, which results in the differences in resolution speed and behavior.

In particular, there is the possibility to represent a CSP with only one constraint or with constraints, which are of the same kind. Inspired by the concept of np-complete problems, we introduce the definition of fd-complete constraints.
A finite domain complete constraint (fd-complete constraint) is a finite domain constraint which can represent every other fd constraint. Thus an fd-complete constraint can be used to replace each other constraint in a CSP.

Possible representatives of fd-complete constraints are the *table* constraint or the *regular membership* constraint. Previous researches show how constraints can be transformed into *table* [2] and *regular membership* [8–11] constraints. These publications also showed, that already the transformations into a *regular membership* or *table* constraint can improve the solving speed of a CSP.

In this paper, we want to go a step further. We not only transform parts of a CSP into an fd-complete constraint, we transform the whole CSP into one, which contains only a set (of the same kind) of fd-complete constraints. Thus we have the possibility to use a solver, solver settings or search strategies which are optimized for the used constraints.

The rest of this paper is structured as follows. In Section 2, we explain the necessary definitions of constraint programming. In Section 3, we introduce our new concept of fd-complete constraint satisfaction problem. Section 4 shows the transformation of a regular CSP into a binary variable scalar CSP. In Section 5, a rostering example is given to underline the benefit of finite domain CSPs. Finally, Section 6 draws a conclusion and proposes research directions in the future.

*Remark 1:* We use the notation of a *regular* constraint as a synonym for *regular membership* respectively *regular language membership* constraint.

## 2 Preliminaries

In this section we introduce some basic definitions and concepts of constraint programming (CP) and show the relevant constraints, which are used in the rest of the paper. We consider CSPs, which are defined in the following way.

A constraint satisfaction problem (CSP) is defined as a 3-tuple $P = (X, D, C)$ where $X = \{x_1, x_2, ..., x_n\}$ is a set of variables, $D = \{D_1, D_2, ..., D_n\}$ is a set of finite domains where $D_i$ is the domain of $x_i$ and $C = \{c_1, c_2, ..., c_m\}$ is a set of constraints covering between one and all variables of $X$ [16].

A constraint $c_j = (X_j, R_j)$ is a relation $R_j$, which is defined over a set of variables $X_j \subseteq X$ [4].

The *scope* of a constraint $c_j = (X_j, R_j)$ indicates the set of variables, which is covered by the constraint $c_j$: $scope(c_j) = X_j$ [4].

The relation $R$ of a constraint $c = (X, R)$ is more clearly a subset of the Cartesian product of the domain values $D_1 \times \dots \times D_n$ of the corresponding variables $X = \{x_1, ..., x_n\}$. Examples for constraints are amongst other things $c_1 = (\{x, y\}, (x > y))$, $c_2 = (\{R, U, I\}, (R = U/I))$ or $c_3 = (\{A, B, C\}, (A \land$
$B \to C)$). For the reason that we only consider finite domains, it is always possible to enumerate all allowed tuples of a constraint, which we will use for the transformation into other constraints like regular or table constraints.

Based on the definition above, an fd-complete constraint can substitute all constraints C of a given CSP P = (X, D, C). For the reason that a CSP can only have a limited number of solutions c<sub>sol</sub>, because we have a limited number of variables n and a limited number of values inside of the domains of the variables, it is possible to enumerate all of the solutions of a CSP.

It follows a list of definitions of the relevant constraints for this paper. Let a CSP P = (X, D, C) and a subset X' of variables X of the CSP P be given.

The scalar constraint guarantees for an ordered subset of variables X' = {x<sub>1</sub>, ..., x<sub>n</sub>} ⊆ X, a vector of integers v = (v<sub>1</sub>, ..., v<sub>n</sub>), a relation ℜ and another variable x<sub>r</sub> ∈ X that the scalar product of the variables X' with the vector v is in relation ℜ to x<sub>r</sub>.

$$scalar(X', v, \Re, x_r) = \left( \sum_{i=1}^{n} x_i * v_i \right) \Re x_r$$

Like we already figured out, the table and the regular constraints are representatives of fd-complete constraints. It follows a short description of these both constraints.

The table constraint is one of the most frequently used constraints in practice. For an ordered subset of variables X' = {x<sub>1</sub>, ..., x<sub>n</sub>} ⊆ X, a positive (negative) table constraint defines that any solution of the CSP P must (not) be explicitly assigned to a tuple t of a given tuple list T, which consists the allowed (disallowed) combinations of values for X'. For a given list of tuples T, we can state the positive table constraint as:

$$table(X', T) = \{(x_1, \dots, x_n) \mid x_1 \in D_1, \dots, x_n \in D_n\} \subseteq T$$

The regular constraint and its propagation [5, 13, 14] is based on deterministic finite automatons (DFAs) [7]. Thus, we briefly review the notion of a deterministic finite automaton (DFA) before we define the regular constraint.

A deterministic finite automaton (DFA) is a quintuple M = (Q, Σ, δ, q<sub>0</sub>, F), where Q is a finite set of states, Σ is the finite input alphabet, δ is a transformation function Q × Σ → Q, q<sub>0</sub> ∈ Q is the initial state, and F ⊆ Q is the set of final or accepting states. A word w ∈ Σ* is accepted by M, if the corresponding DFA M with the input w stops in a final state f ∈ F. All accepting words of the DFA M can be summarized to the accepting language L(M) of the DFA M [7].

The regular constraint is another of the most common constraints in practice. Let M = (Q, Σ, δ, q<sub>0</sub>, F) be a DFA, let X = {x<sub>1</sub>, ..., x<sub>n</sub>} be an ordered set of variables with domains D = {D<sub>1</sub>, D<sub>2</sub>, ..., D<sub>n</sub>}, ∀i ∈ {1, ..., n} : D<sub>i</sub> ⊆ Σ. The regular constraint is defined as:
$$ \text{regular}(X, M) = \{ (w_1, \dots, w_n) \mid \forall i \in \{1, \dots, n\}, w_i \in D_i, (w_1 w_2 \dots w_n) \in L(M) \} [6] $$

So the concatenation of the values $v_i$ of the variables $x_i$ for $i \in \{1, \dots, n\}$ must be accepted by the automaton $M$. The input DFA $M$ of a regular constraint is internally transformed into a directed acyclic graph (DAG) $M'$ [14].

We define a directed acyclic graph (DAG) as a DFA $M = (Q, \Sigma, \delta, q_{initial}, F)$, where the states $q$ in $Q$ are partitioned into levels $Q = \{Q_0, \dots, Q_n\}$, $q_i = \{q_{i,1}, q_{i,2}, \dots\} \mid \forall i \in \{1, \dots, n\}$, the initial state $q_{0,0}$ is the only element of $Q_0$, the final states are members of the last level of states ($F = Q_n$), and transitions are only allowed from a state $q_{i,j}$ in level $Q_i$ to a state $q_{j,k}$ in level $Q_k$, where $t \ge i$.

For our use, we only allow transitions from a state $q_{i,j}$ in level $Q_i$ to a state $q_{i+1,k}$ in level $Q_{i+1}$. We use the notation $v \xrightarrow{q_{i+1,k}} q_{i+1,k}$, if the state $q_{i,j}$ of level $Q_i$ have a transition with value $v$ to the state $q_{i+1,k}$ of level $Q_{i+1}$. A solution of a regular constraint is a path from the initial state $q_{0,0}$ to the final state $q_{n,0}$ with values $v_1 \in D_1, \dots, v_n \in D_n$ ($q_{0,0} \xrightarrow{v_1} q_{1,j_1} \xrightarrow{v_2} \dots \xrightarrow{v_n} q_{n,0}$).

Based on the definition of the regular constraint, we use the notation of a regular constraint satisfaction problem, and analogously the notation of a table CSP:

A regular constraint satisfaction problem (regular CSP) is defined as a 3-tuple $P = (X, D, C)$, where $X = \{x_1, x_2, \dots, x_n\}$ is a set of variables, $D = \{D_1, D_2, \dots, D_n\}$ is a set of finite domains where $D_i$ is the domain of $x_i$ and $C = \{c_1, c_2, \dots, c_m\}$ is a set of regular constraints over variables of $X$.

A table constraint satisfaction problem (table CSP) is defined as a 3-tuple $P = (X, D, C)$, where $X = \{x_1, x_2, \dots, x_n\}$ is a set of variables, $D = \{D_1, D_2, \dots, D_n\}$ is a set of finite domains where $D_i$ is the domain of $x_i$ and $C = \{c_1, c_2, \dots, c_m\}$ is a set of table constraints over variables of $X$.

## 3 FD-Complete CSPs

After we defined fd-complete constraints and showed two examples (the table and the regular constraint), we will extend this concept a little bit more. The possibility to substitute a constraint or a subset of constraints of a CSP with an fd-complete constraint can lead to a speed up in the solution process [2, 8–11]. The problem is that it is mostly not useful to transform a whole CSP into another one with only one fd-complete constraint, which substitutes all constraints of the original CSP. In most cases, the transformation process will be more time consuming than solving the original problem.
Mostly, we can reduce this slow-down significantly and reach a speed-up, if we substitute only some of the constraints $c_i \in C$ of a given CSP $P = (X, D, C)$ with semantically equivalent **fd**-complete constraints $c_i^{\text{fd}} \in C^{\text{fd}}$ and combine them together (to constraints $c_j^{c\text{-fd}} \in C^{c\text{-fd}}$). Finding the best subset of constraints, which should be transformed and combined, depends on several things like the needed time for transformation or the size of the data structures of the transformed or the combined constraints.

Often, a CSP $P' = (X, D, C')$, which contains some of the original constraints $c_i \in C$ and some of the combined constraints $c_j^{c\text{-fd}}$, which are semantically equivalent to a subset of the fd-complete constraints $C^{\text{fd}}$, has the fastest solution process.

In contrast to this, we will explain why it can be useful to create a CSP $P = (X, D, C)$ with only singleton $c_i^{\text{fd}}$ and combined fd-complete constraints $c_j^{c\text{-fd}}$, even though the propagation of the original constraint $c_i$ is possibly faster than the propagation of the corresponding fd-complete constraint $c_i^{\text{fd}}$.

The advantage is, that we may be able to (create and) use specialist constraint solvers for CSPs which have only constraints of a special type (a popular example is the simplex algorithm, which allows only linear optimization under linear side conditions). Furthermore, we can create and use more efficient search strategies and solver settings if the used constraints have the same shape.

Also interesting for future researches is, that a CSP $P$ with only one kind of constraint may be able to be transformed easier into other models for example a SAT model and make it possible simpler to transfer a constraint problem of a given language into another one. The last idea is for example used to translate MiniZinc [18] models into other models (like Gecode [17], Google OR-Tools [1] or Choco [15] models). Thus, many constraints, which were entered in MiniZinc, will be translated into the *table* constraint.

Based on the potential benefit of CSPs, which contain only fd-complete constraints, we created the definition of an fd-complete CSP.

A *finite domain complete constraint satisfaction problem (fd-complete CSP)* is a CSP $P = (X, D, C)$ which contains only fd-complete constraints of the same kind.

Examples for an fd-complete CSP are the *regular CSP* [9] or the *table CSP*. We call fd-complete CSPs with *n* different kinds of constraints fd-complete CSPs of degree *n*. We differentiate between two kinds of fd-complete CSPs. On the one hand we have directly convertible fd-complete CSPs like table or regular CSPs. Every general CSP $P = (X, D, C)$ can be transformed into a *directly convertible fd-complete CSP* $P^{\text{dc\text{-}fd}} = (X, D, C^{\text{fd}})$ by transformation of each single constraint $c \in C$ to the corresponding fd-complete constraint $c \in C^{\text{fd}}$. In particular, it is not necessary to transform the variables *X* or domains *D* of the original CSP *P*.

On the other hand, there are *indirectly convertible fd-complete CSPs* $P^{\text{ic\text{-}fd}} = (X', D', C^{\text{fd}})$, where the variables and their domains must be transformed addi-
tionally to the constraints. We present a representative example of this group in
the next section.

4 The Binary Scalar CSP as a Representative of FD-Complete CSPs

In this Section, we will introduce a description of how a general CSP $P$ can be transformed into a CSP $P^{\text{bvsc}}$, which contains only **binary** variables and scalar constraints. Using only binary variables allows us the use of the very good researched SAT solvers, for solving $P^{\text{bvsc}}$. Furthermore, for the reason that the CSP $P^{\text{bvsc}}$ only contains scalar constraints, we expect that a possibley more accurate and more specialized solver can be created to solve it.

Traditionally, an input CSP $P$ for a SAT solver contains binary variables and logic constraints like *and*, *or*, *implication*, *negation* etc. It is also possible to transform a regular constraint into a set of logic constraints, but we will see, that the transformation into a set of scalar constraints is more compact. Thus, we expect that a specialized solver for scalar constraints over binary variables works faster than a usual SAT solver.

The transformation from a general CSP $P$ to a binary variable scalar CSP $P^{\text{bvsc}}$ can happen in two steps.

Step one: transforming the CSP $P = (X, D, C)$ into a regular CSP $P^{\text{reg}} = (X, D, C^{\text{reg}})$, which contains the same variables $X$, the same domains $D$, but only regular constraints $C^{\text{reg}}$ instead of the original constraints $C$. For example, it is possible to transform each original constraint $c \in C$ into a regular constraint $c^{\text{reg}} \in C^{\text{reg}}$. The algorithms and transformations presented in [8–11] can be used for this step.

Step two: transform the regular CSP $P^{\text{reg}} = (X, D, C^{\text{reg}})$ into a binary variable scalar CSP $P^{\text{bvsc}} = (X^{\text{b}}, D^{\text{b}}, C^{\text{sc}})$. We consider a regular CSP $P^{\text{reg}} = (X, D, C^{\text{reg}})$ with $n$ variables $X = \{x_1, ..., x_n\}$, the associated finite domains $D = \{D_1, ..., D_n\}$ and $m$ regular constraints $C^{\text{reg}} = \{c_1^{\text{reg}}, ..., c_m^{\text{reg}}\}$ and transform it into a binary variable scalar CSP $P^{\text{bvsc}} = (X^{\text{b}}, D^{\text{b}}, C^{\text{sc}})$ with $k$ variables $X^{\text{b}} = \{x_1^{\text{b}}, ..., x_k^{\text{b}}\}$, which have all the domain $\{0,1\} = D_1^{\text{b}} = ... = D_k^{\text{b}}$, and $l$ scalar constraints $C^{\text{sc}} = \{c_1^{\text{sc}}, ..., c_l^{\text{sc}}\}$.

There are two kinds of variables in $X^{\text{b}}$. The first kind contains for each domain value of each variable of the regular CSP $P^{\text{reg}}$, respectively the original CSP $P$, a binary variable $x_{i,j}^{\text{b}} \forall i \in \{1, ..., n\}, j \in \{1, ..., |D_i|\}$. If such a variable $x_{i,j}^{\text{b}} \in X^{\text{b}}$ of $P^{\text{bvsc}}$ is set to 1, it represents that the corresponding variable $x_i \in X$ in the regular CSP $P^{\text{reg}}$ is set to the value $d_j$, where $d_j$ is the $j$-th value of $D_i$, otherwise, if a variable $x_{i,j}^{\text{b}} \in X^{\text{b}}$ of $P^{\text{bvsc}}$ is set to 0, it represents that the corresponding variable $x_i \in X$ in the regular CSP $P^{\text{reg}}$ cannot be set to the value $d_j$. Thus transform the original search space into a binary variable search space.

The second kind of variables represents the states of the underlying DAGs of the regular constraints $C^{\text{reg}}$. Each regular constraint $c_h^{\text{reg}} \in C^{\text{reg}}$ has a DAG $M_h$ which represents the regular expression of the *regular* constraint. For each
state $q_{i,j}^h$ of each DAG $M_h$, a binary variable $x_{i,j}^h$ represents if the state $q_{i,j}^h$ is on a solution path ($x_{i,j}^h$ is set to one) or not ($x_{i,j}^h$ is set to 0).

After defining the variables and the domains (all {0,1}) we need to define our constraints, which must be semantically equivalent to the constraints $C^{\text{reg}}$ and realize that each binary variable set {$x_{i,1}^b, ..., x_{i,|D_i|}^b$}, which represents one original variable $x_i \in X$, contains only one variable which is instantiated to 1. This guarantees that we can directly conclude a solution of the original CSP $P$ from a solution of $P^{\text{bvsc}}$. Doing this, we have for each binary variable set {$x_{i,1}^b, ..., x_{i,|D_i|}^b$} a scalar constraint, which set the number of 1s in {$x_{i,1}^b, ..., x_{i,|D_i|}^b$} to one (see Equation 1).

$$ \forall i \in \{1, ..., n\} : \text{scalar}(\{x_{i,1}^b, ..., x_{i,|D_i|}^b\}, \{1, ..., 1\}, =, 1) \quad (1) $$

Analogously, we have constraints for each set of variables $x_{i,j}^h$, which represents each one level $i$ of the DAG $M_h$. The path of each solution of a DAG contains only one state $q_{i,j}^h$ of each level $i$. Thus, we can define the following scalar constraints (see Equation 2).

$$ \forall i \in \{0, ..., n\}, h \in \{1, ..., |C^{\text{reg}}|\} : \text{scalar}(\{x_{i,*}^h\}, \{1, ..., 1\}, =, 1) \quad (2) $$

To represent a DAG $M_h$, we need to describe the paths of the solutions of the DAG. The initial state $q_{0,0}^h$ and the final state $q_{n,0}^h$ are mandatory parts of a solution path. Thus, the variables $x_{0,0}^h$ and $x_{n,0}^h$ must be set to 1. A state $q_{i,j_3}^h$ of a DAG $M_h$ is part of a solution path, if one of its predecessor states $q_{i-1,j_1}^h$ and one of the values $d_{i-1,j_2} \in D_{i-1}$ of the edge between this both states is part of the solution path. This can be represented by the logical formula $q_{i-1,j_1} \wedge d_{i-1,j_2} \rightarrow q_{i,j_3}^h$. See Figure 1 for some example path relations.

Applied to our variable system it concludes the formula $x_{i-1,j_1}^h \wedge x_{i-1,j_2}^b \rightarrow x_{i,j_3}^h$. Furthermore, this logical formula can be represented as scalar constraint (see Equation 3).

$$ \begin{array}{l} \forall i \in \{1, ..., n\}, h \in \{1, ..., |C^{\text{reg}}|\}, j_1, j_2, j_3, \\ \text{where } q_{i-1, j_1}^h \xrightarrow{d_{i-1, j_2}} q_{i, j_3}^h \text{ is an edge in } M_h : \\ \text{scalar}(\{x_{i-1, j_1}^h, x_{i-1, j_2}^b, x_{i, j_3}^h\}, \{1, 1, -2\}, \le, 1) \end{array} \quad (3) $$

The equivalence of the statement $x_{i-1,j_1}^h \wedge x_{i-1,j_2}^b \rightarrow x_{i,j_3}^h$ with the statement in Equation 3 can be easily proved with the truth table shown in table 1. The result of the logical formula is always true if the scalar product is smaller or equal to one, otherwise it is false.

Thus, we have everything we need to represent the regular CSP $P^{\text{reg}} = (X, D, C^{\text{reg}})$ as a binary variable scalar CSP $P^{\text{bvsc}} = (X^b, D^b, C^{\text{sc}})$, with
<figure><img src="image_3.png" /><figcaption>Fig. 1: Example path relations for an excerpt of a DAG.</figcaption></figure>

<table><caption>Table 1: The truth table to show the equivalence of $x_{i-1,j1}^h \wedge x_{i-1,j2}^b \rightarrow x_{i,j3}^h$ and scalar($\{x_{i-1,j1}^h, x_{i-1,j2}^b, x_{i,j3}^h\}, \{1, 1, -2\}, \le, 1$).</caption><thead><tr><th>x<sup>h</sup><sub>i-1,j1</sub> &and; x<sup>b</sup><sub>i-1,j2</sub> &rarr; x<sup>h</sup><sub>i,j3</sub></th><th>&harr; 1 &middot; x<sup>h</sup><sub>i-1,j1</sub> + 1 &middot; x<sup>b</sup><sub>i-1,j2</sub> &minus; 2 &middot; x<sup>h</sup><sub>i,j3</sub> &le; 1</th></tr></thead><tbody><tr><td>True &and; True &rarr; True</td><td>True &harr; 0 &le; 1</td></tr><tr><td>True &and; True &rarr; False</td><td>False &harr; 2 &le; 1</td></tr><tr><td>True &and; False &rarr; True</td><td>True &harr; &minus;1 &le; 1</td></tr><tr><td>True &and; False &rarr; False</td><td>True &harr; 1 &le; 1</td></tr><tr><td>False &and; True &rarr; True</td><td>True &harr; &minus;1 &le; 1</td></tr><tr><td>False &and; True &rarr; False</td><td>True &harr; 1 &le; 1</td></tr><tr><td>False &and; False &rarr; True</td><td>True &harr; &minus;2 &le; 1</td></tr><tr><td>False &and; False &rarr; False</td><td>True &harr; 0 &le; 1</td></tr></tbody></table>

$$
\begin{align*}
X^b &= \{x_{i,j}^b \mid \forall i \in \{1, \dots, n\}, j \in \{1, \dots, |D_i|\}\} \\
&\quad \cup \{x_{i,j}^h \mid \forall h \in \{1, \dots, |C^{\text{reg}}|\}, i \in \{0, \dots, n\}, j \in \{1, \dots, |Q_i^h|\}\} \\
D^b &= \{D_i = \{0, 1\} \mid \forall i \in \{1, \dots, |X^b|\}\} \\
C^{\text{sc}} &= \{\text{scalar}(\{x_{i,1}^b, \dots, x_{i,|D_i|}^b\}, \{1, \dots, 1\}, =, 1) \mid \forall i \in \{1, \dots, n\}\} \\
&\quad \cup \{\text{scalar}(\{x_{i,*}^h\}, \{1, \dots, 1\}, =, 1) \mid \forall i \in \{0, \dots, n\}, h \in \{1, \dots, |C^{\text{reg}}|\}\} \\
&\quad \cup \{\text{scalar}(\{x_{i-1,j1}^h, x_{i-1,j2}^b, x_{i,j3}^h\}, \{1, 1, -2\}, \le, 1)\} \mid \\
&\quad \quad \forall i \in \{1, \dots, n\}, h \in \{1, \dots, |C^{\text{reg}}|\}, j_1, j_2, j_3, \text{ where } \\
&\quad \quad q_{i-1,j1}^h \xrightarrow{d_{i-1,j2}} q_{i,j3}^h \text{ is an edge in } M_h\}
\end{align*}
$$

*Remark 2:* The constraints in Equation 1 and 2 are the reason, why we use scalar constraints instead of logic constraints, because such *count* constraints are just not compactly representable as logic constraints, but very simple as scalar constraints.

*Remark 3:* In the implementation we did some optimizations like merging different scalar constraints, which represent path relations between the same
states $(q_{i-1,j_1}, q_{i,j_3})$, but with $k$ different values $(d_{i-1,j_2,1}, \dots, d_{i-1,j_2,k})$ to one single scalar constraint.

# 5 Experimental Results

For demonstrating the benefit of fd-complete constraints and fd-complete CSPs, we use a rostering problem close to the presented one in section 4.1 in [9]. Briefly summarized, consider the rostering problem four shifts (0 = day off, 1 = early, 2 = late, 3 = night shift), $m$ employees and $w$ weeks. Let $n$ be the number of days ($n = w \cdot 7$). The goal is to find a valid shift assignment for all employees, such that the following four restrictions are satisfied:

$R_1$: At each Saturday is the same shift as at the following Sunday.

$R_2$: A forward rotating system is used, so the following shift combinations are not allowed for two days in a row: (late, early), (night, early), (night, late).

$R_3$: There is a minimum number of two and a maximum number of four (for night shifts 3) consecutive days, with the same shift.

$R_4$: Between $\lfloor \frac{w}{4} \rfloor$ and $\lfloor \frac{w}{4} \rfloor + 1$ employees are needed for each shift and day.

The given restrictions cover some but not all German laws for shift planning, but it is possible to extend the problem for individual use cases. The difference to [9] is that we changed in restriction $R_4$ the upper bound from $\lfloor \frac{w}{4} \rfloor$ to $\lfloor \frac{w}{4} \rfloor + 1$ to guarantee that every problem has at least one solution.

As typical for many rostering problems, we just consider the plan of one person $P_1$ and assume that the plan for further staff is received by rotating $P_1$'s plan by one week, two weeks, etc. For example given a shift plan $sol_{P_1} = (v_1, v_2, \dots, v_n)$ for person $P_1$, the plan for a person $P_2$ would be $(v_8, v_9, \dots, v_n, v_1, \dots, v_7)$, for a person $P_3$ would be $(v_{15}, v_{16}, \dots, v_n, v_1, \dots, v_{14})$, and so on.

The following naive CSP $P_{naive}$ describes the given rostering problem. The constraints in $C_1$ satisfy the restriction $R_1$, the constraints in $C_2$ satisfy the restriction $R_2$, the constraints in $C_3, C_4$ and $C_5$ satisfy the restriction $R_3$ and the constraints in $C_6$ and $C_7$ satisfy the restriction $R_4$.

<caption>Fig. 2: The naive CSP $P_{naive}$, which describes the given rostering problem.</caption>

$$
\begin{aligned}
X &= \{x_1, \dots, x_n\} \\
D &= \{D_1 = \dots = D_n = \{0, 1, 2, 3\}\} \\
C &= C_1 = \{x_{i+6} = x_{i+7} \mid \forall i \in \{1, \dots, w\}\} \\
  &\quad \cup C_2 = \{(x_i, x_{i+1}) \notin \{(2, 1), (3, 1), (3, 2)\} \mid \forall i \in \{1, \dots, n\}\} \\
  &\quad \cup C_3 = \{(x_i == x_{i+1}) \lor (x_i == x_{i-1})\} \mid \forall i \in \{2, \dots, n-1\}\} \\
  &\quad \cup C_4 = \{allEqual(x_i, x_{i+1}, x_{i+2}, x_{i+3}) \rightarrow (x_i \neq x_{i+4}) \mid \forall i \in \{1, \dots, n-4\}\} \\
  &\quad \cup C_5 = \{allEqual(x_i, x_{i+1}, x_{i+2}, 3) \rightarrow (x_i \neq x_{i+3}) \mid \forall i \in \{1, \dots, n-3\}\} \\
  &\quad \cup C_6 = \{\sum_{i=1}^{w} x_{i+d} \ge \lfloor \frac{w}{4} \rfloor \mid \forall d \in \{1, \dots, 7\}\} \\
  &\quad \cup C_7 = \{\sum_{i=1}^{w} x_{i+d} \le \lfloor \frac{w}{4} \rfloor + 1 \mid \forall d \in \{1, \dots, 7\}\}
\end{aligned}
$$
For our benchmark suite we computed different instances of the rostering problem with number of weeks respectively number of employees is equal to 4(, 5, 6, 7 and 8) in different versions:

1. *Naive*: The CSP is directly solved as it is modeled in $P_{naive}$.

2. *Regular*: Each constraint was substituted by a regular version of it as described in [11].

3. *RegularIntersected*: Each constraint was substituted by a regular version of it as described in [11] and the regular versions of the constraints $C_1$ to $C_5$ are combined to one regular constraint.

4. *BVSC*: The CSP $P_{naive}$ was transformed into a binary variable scalar constraint CSP $P^{bvsc}$ as described above.

5. *BVSCO*: The binary variable scalar constraint CSP $P^{bvsco}$ was created and optimized by hand.

All the experiments are set up on a DELL laptop with an Intel i7-4610M CPU, 3.00GHz, with 16 GB 1600 MHz DDR3 and running under Windows 7 Professional with Service Pack 1. The algorithms are implemented in Java under JDK version 1.8.0_191 and Choco Solver version 4.0.4 [15]. We used the DowOverWDeg search strategy which is explained in [3] and used as default search strategy in the Choco Solver [15].

<table><caption>Table 2: A comparison of the solution process of the given rostering problem with different sizes and different modelling versions. (*Time limit was reached.)</caption><thead><tr><th>Problem</th><th>#Solutions</th><th>Naive</th><th>BVSC</th><th>BVSCO</th><th>Regular</th><th>RegularIntersected</th></tr></thead><tbody><tr><td rowspan="2">4 weeks</td><td rowspan="2">44</td><td>100%</td><td>100%</td><td>100%</td><td>100%</td><td>100%</td></tr><tr><td>0.726s</td><td>5.815s</td><td>0.155s</td><td>2.139s</td><td>0.371s</td></tr><tr><td rowspan="2">5 weeks</td><td rowspan="2">217339</td><td>100%</td><td>100%</td><td>100%</td><td>100%</td><td>100%</td></tr><tr><td>96.622s</td><td>345.377s</td><td>8.87s</td><td>59.599s</td><td>5.697s</td></tr><tr><td rowspan="2">6 weeks</td><td rowspan="2">9443633</td><td>17%</td><td>2%</td><td>100%</td><td>34%</td><td>100%</td></tr><tr><td>600s*</td><td>600s*</td><td>396.619s</td><td>600s*</td><td>196.055s</td></tr><tr><td rowspan="2">7 weeks</td><td rowspan="2">8463303</td><td>9%</td><td>0.1%</td><td>84%</td><td>28%</td><td>100%</td></tr><tr><td>600s*</td><td>600s*</td><td>600s*</td><td>600s*</td><td>214.486s</td></tr><tr><td rowspan="2">8 weeks</td><td rowspan="2">42979</td><td>11%</td><td>0.002%</td><td>93%</td><td>76%</td><td>100%</td></tr><tr><td>600s*</td><td>600s*</td><td>600s*</td><td>600s*</td><td>25.649s</td></tr></tbody></table>

Table 2 shows a comparison of the different modelling versions. For four and five weeks, all approaches found all solutions (100%). The RegularIntersected and the BVSCO approach are the fastest with distance to the other approaches. Only the RegularIntersected approach found all solutions for the 6, 7 and 8 week problem. It is shown how many solutions every approach found in at maximum 600 seconds, which was the time out. It is visible that the RegularIntersected
approach is always the fastest and the BVSC approach is always the worst. But we also can see, that the by hand optimized BVSCO is also always very good, much better than the original approach. In these experiments we did not use reduction methods, which are known from equality and inequality solving. We think that in the future we can find an automatic way from the original CSP to one which is very close to the BVSCO, and so one that is much better than the original, naive problem. It is clearly evident, those fd-CSPs like regular CSPs or binary variable CSPs with scalar constraints can lead to significant improvement of the solution process of constraint problems.

*Remark 4:* The transformation time to create the responsible fd-CSPs from the original CSP was always included in the calculation time in table 2.

*Remark 5:* The results presented in table 2 show already the power of fd-complete constraints (the RegularIntersected and the BVSCO approach are partial more than 24 times faster as the original naive approach). Further more we may can improve the solution process much more if we use a specific solver for regular CSPs or binary variable CSPs with scalar constraints instead of the general fd-solver Choco.

# 6 Conclusion and Future Work

We have presented a new class of constraints, which allows describing every other CSP with a single constraint (fd-complete constraint). We extended this approach to fd-complete CSPs, which are also able to represent each other CSP. Furthermore, we introduced an example fd-complete CSP, the binary scalar CSP, and explained why we think, that this fd-complete CSP can improve the solution speed of general CSPs. In Section 2 was shown that the use of fd-CSPs like regular CSPs or binary variable CSPs with scalar constraints can improve the solution process of CSPs in a significant way.

Future work includes the creation of specialist constraint solvers, specialist search strategies and specialist constraint solver settings. We expect that there are a big number of fd-complete constraints and fd-complete CSPs and, therefore, also a high number of specialist constraint solvers and search strategies, which need to be discovered. Moreover, we need an algorithm to decide into which fd-CSP we should transform given problems.

# References

1. Google LLC, Google OR-Tools, 2019, last visited 2019-11-22, https://developers.google.com/optimization/

2. Akgün, Ö., Gent, I.P., Jefferson, C., Miguel, I., Nightingale, P., Salamon, A.Z.: Automatic discovery and exploitation of promising subproblems for tabulation. In: Hooker, J.N. (ed.) Principles and Practice of Constraint Programming - 24th International Conference, CP 2018, Lille, France, August 27-31, 2018, Proceedings. Lecture Notes in Computer Science, vol. 11008, pp. 3–12. Springer (2018), https://doi.org/10.1007/978-3-319-98334-9_1
3. Boussemart, F., Hemery, F., Lecoutre, C., Sais, L.: Boosting systematic search by weighting constraints. In: de Mántaras, R.L., Saitta, L. (eds.) Proceedings of the 16th European Conference on Artificial Intelligence, ECAI'2004, including Prestigious Applicants of Intelligent Systems, PAIS 2004, Valencia, Spain, August 22-27, 2004. pp. 146-150. IOS Press (2004)

4. Dechter, R.: Constraint processing. Elsevier Morgan Kaufmann (2003)

5. Hellsten, L., Pesant, G., van Beek, P.: A domain consistency algorithm for the stretch constraint. In: Wallace, M. (ed.) Principles and Practice of Constraint Programming - CP 2004. Lecture Notes in Computer Science, vol. 3258, pp. 290-304. Springer (2004)

6. van Hoeve, W.J., Katriel, I.: Global Constraints. In: [16], First edn. (2006), chapter 6

7. Hopcroft, J.E., Ullman, J.D.: Introduction to Automata Theory, Languages and Computation. Addison-Wesley (1979)

8. Löffler, S., Liu, K., Hofstedt, P.: The power of regular constraints in csps. In: 47. Jahrestagung der Gesellschaft für Informatik, Informatik 2017, Chemnitz, Germany, September 25-29, 2017. pp. 603-614 (2017), https://doi.org/10.18420/in2017_57

9. Löffler, S., Liu, K., Hofstedt, P.: The regularization of csps for rostering, planning and resource management problems. In: Artificial Intelligence Applications and Innovations - 14th IFIP WG 12.5 International Conference, AIAI 2018, Rhodes, Greece, May 25-27, 2018, Proceedings. pp. 209-218 (2018), https://doi.org/10.1007/978-3-319-92007-8_18

10. Löffler, S., Liu, K., Hofstedt, P.: A meta constraint satisfaction optimization problem for the optimization of regular constraint satisfaction problems. In: Rocha, A.P., Steels, L., van den Herik, H.J. (eds.) Proceedings of the 11th International Conference on Agents and Artificial Intelligence, ICAART 2019, Volume 2, Prague, Czech Republic, February 19-21, 2019. pp. 435-442. SciTePress (2019), https://doi.org/10.5220/0007260204350442

11. Löffler, S., Liu, K., Hofstedt, P.: The regularization of small sub-constraint satisfaction problems. CoRR abs/1908.05907 (2019), http://arxiv.org/abs/1908.05907

12. Marriott, K.: Programming with Constraints - An Introduction. MIT Press, Cambridge (1998)

13. Pesant, G.: A filtering algorithm for the stretch constraint. In: Walsh, T. (ed.) Principles and Practice of Constraint Programming - CP 2001. Lecture Notes in Computer Science, vol. 2239, pp. 183-195. Springer (2001)

14. Pesant, G.: A regular language membership constraint for finite sequences of variables. In: Wallace, M. (ed.) Principles and Practice of Constraint Programming - CP 2004. Lecture Notes in Computer Science, vol. 3258, pp. 482-495. Springer (2004)

15. Prud'homme, C., Fages, J.G., Lorca, X.: Choco Documentation. TASC, INRIA Rennes, LINA CNRS UMR 6241, COSLING S.A.S. (2019), http://www.chocosolver.org/, last visited 2019-11-07

16. Rossi, F., Beek, P.v., Walsh, T.: Handbook of Constraint Programming. Elsevier, Amsterdam, First edn. (2006)

17. Schulte, C., Lagerkvist, M., Tack, G.: Gecode 6.2.0, 2019, https://www.gecode.org/, last visited 2019-11-22 (2019)

18. Tack, G., Stuckey, P.J.: Minizinc 2.3.2, 2019, monash university, https://www.minizinc.org/, last visited 2019-11-22 (2019)