# Flow-Based Propagators for the SEQUENCE and Related Global Constraints

We propose new filtering algorithms for the SEQUENCE constraint and some extensions of the SEQUENCE constraint based on network flows. We enforce domain consistency on the SEQUENCE constraint in O(n^2) time down a branch of the search tree. This improves upon the best existing domain consistency algorithm by a factor of O( n). The flows used in these algorithms are derived from a linear program. Some of them differ from the flows used to propagate global constraints like GCC since the domains of the variables are encoded as costs on the edges rather than capacities. Such flows are efficient for maintaining bounds consistency over large domains and may be useful for other global constraints.

## Authors

• 9 publications
• 35 publications
• 8 publications
• 85 publications
• ### The AllDifferent Constraint with Precedences

We propose AllDiffPrecedence, a new global constraint that combines toge...
03/19/2011 ∙ by Christian Bessiere, et al. ∙ 0

• ### Conjunctions of Among Constraints

Many existing global constraints can be encoded as a conjunction of amon...
06/15/2017 ∙ by Victor Dalmau, et al. ∙ 0

• ### Bounds Arc Consistency for Weighted CSPs

The Weighted Constraint Satisfaction Problem (WCSP) framework allows rep...
01/15/2014 ∙ by Matthias Zytnicki, et al. ∙ 0

• ### The SeqBin Constraint Revisited

We revisit the SeqBin constraint. This meta-constraint subsumes a number...
07/07/2012 ∙ by George Katsirelos, et al. ∙ 0

• ### Set Intersection and Consistency in Constraint Networks

In this paper, we show that there is a close relation between consistenc...
10/10/2011 ∙ by R. H. C. Yap, et al. ∙ 0

• ### Domain Filtering Consistencies

Enforcing local consistencies is one of the main features of constraint ...
06/03/2011 ∙ by C. Bessiere, et al. ∙ 0

• ### Consistency Techniques for Flow-Based Projection-Safe Global Cost Functions in Weighted Constraint Satisfaction

Many combinatorial problems deal with preferences and violations, the go...
01/18/2014 ∙ by J. H. M. Lee, et al. ∙ 0

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Graph based algorithms play a very important role in constraint programming, especially within propagators for global constraints. For example, Regin’s propagator for the AllDifferent constraint is based on a perfect matching algorithm [1], whilst his propagator for the Gcc constraint is based on a network flow algorithm [2]. Both these graph algorithms are derived from the bipartite value graph, in which nodes represent variables and values, and edges represent domains. For example, the Gcc propagator finds a flow in such a graph in which each unit of flow represents the assignment of a particular value to a variable. In this paper, we identify a new way to build graph based propagators for global constraints: we convert the global constraint into a linear program and then convert this into a network flow. These encodings contain several novelties. For example, variables domain bounds can be encoded as costs along the edges. We apply this approach to the Sequence family of constraints. Our results widen the class of global constraints which can be propagated using flow-based algorithms. We conjecture that these methods will be useful to propagate other global constraints.

## 2 Background

A constraint satisfaction problem (CSP) consists of a set of variables, each with a finite domain of values, and a set of constraints specifying allowed combinations of values for subsets of variables. We use capital letters for variables (e.g. , and ), and lower case for values (e.g. and ). A solution is an assignment of values to the variables satisfying the constraints. Constraint solvers typically explore partial assignments enforcing a local consistency property using either specialized or general purpose propagation algorithms. A support for a constraint is a tuple that assigns a value to each variable from its domain which satisfies . A bounds support is a tuple that assigns a value to each variable which is between the maximum and minimum in its domain which satisfies . A constraint is domain consistent (DC) iff for each variable , every value in the domain of belongs to a support. A constraint is bounds consistent (BC) iff for each variable , there is a bounds support for the maximum and minimum value in its domain. A CSP is DC/BC iff each constraint is DC/BC. A constraint is monotone iff there exists a total ordering of the domain values such that for any two values , if then is substitutable for in any support for .

We also give some background on flows. A flow network is a weighted directed graph where each edge has a capacity between non-negative integers and , and an integer cost . A feasible flow in a flow network between a source and a sink , -flow, is a function that satisfies two conditions: , and the flow conservation law that ensures that the amount of incoming flow should be equal to the amount of outgoing flow for all nodes except the source and the sink. The value of a -flow is the amount of flow leaving the sink . The cost of a flow is . A minimum cost flow is a feasible flow with the minimum cost. The Ford-Fulkerson algorithm can find a feasible flow in time. If , , then a minimum cost feasible flow can be found using the successive shortest path algorithm in time, where is the complexity of finding a shortest path in the residual graph. Given a -flow in , the residual graph is the directed graph , where is

 {e with cost w(e) and capacity 0..(u(e)−f(e)) | e=(u,v)∈E,f(e)
 {e with cost −w(e) and capacity 0..(f(e)−l(e)) | e=(u,v)∈E,l(e)

There are other asymptotically faster but more complex algorithms for finding either feasible or minimum-cost flows [3].

In our flow-based encodings, a consistency check will correspond to finding a feasible or minimum cost flow. To enforce DC, we therefore need an algorithm that, given a minimum cost flow of cost and an edge checks if an extra unit flow can be pushed (or removed) through the edge and the cost of the resulting flow is less than or equal to a given threshold . We use the residual graph to construct such an algorithm. Suppose we need to check if an extra unit flow can be pushed through an edge . Let be the corresponding arc in the residual graph. If , , then it is sufficient to compute strongly connected components (SCC) in the residual graph. An extra unit flow can be pushed through an edge iff both ends of the edge are in the same strongly connected component. If , , the shortest path between and in the residual graph has to be computed. The minimal cost of pushing an extra unit flow through an edge equals . If , then we cannot push an extra unit through . Similarly, we can check if we can remove a unit flow through an edge.

## 3 The Sequence Constraint

The Sequence constraint was introduced by Beldiceanu and Contejean [4]. It constrains the number of values taken from a given set in any sequence of variables. It is useful in staff rostering to specify, for example, that every employee has at least 2 days off in any 7 day period. Another application is sequencing cars along a production line (prob001 in CSPLib). It can specify, for example, that at most 1 in 3 cars along the production line has a sun-roof. The Sequence constraint can be defined in terms of a conjunction of Among constraints. holds iff . That is, between and of the variables take values in . The Among constraint can be encoded by channelling into 0/1 variables using and . Since the constraint graph of this encoding is Berge-acyclic, this does not hinder propagation. Consequently, we will simplify notation and consider Among (and Sequence) on 0/1 variables and . If , Among is an AtMost constraint. AtMost is monotone since, given a support, we also have support for any larger assignment [5]. The Sequence constraint is a conjunction of overlapping Among constraints. More precisely, holds iff for , holds. A sequence like is a window. It is easy to see that this decomposition hinders propagation. If , Sequence is an AtMostSeq constraint. Decomposition in this case does not hinder propagation. Enforcing DC on the decomposition of an AtMostSeq constraint is equivalent to enforcing DC on the AtMostSeq constraint  [5].

Several filtering algorithms exist for Sequence and related constraints. Regin and Puget proposed a filtering algorithm for the Global Sequencing constraint (Gsc) that combines a Sequence and a global cardinality constraint (Gcc[6]. Beldiceanu and Carlsson suggested a greedy filtering algorithm for the CardPath constraint that can be used to propagate the Sequence constraint, but this may hinder propagation [7]. Regin decomposed Gsc into a set of variable disjoint Among and Gcc constraints [8]. Again, this hinders propagation. Bessiere et al. [5] encoded Sequence using a Slide constraint, and give a domain consistency propagator that runs in time. van Hoeve et al. [9] proposed two filtering algorithms that establish domain consistency. The first is based on an encoding into a Regular constraint and runs in time, whilst the second is based on cumulative sums and runs in time down a branch of the search tree. Finally, Brand et al. [10] studied a number of different encodings of the Sequence constraint. Their asymptotically fastest encoding is based on separation theory and enforces domain consistency in time down the whole branch of a search tree. One of our contributions is to improve on this bound.

## 4 Flow-based Propagator for the Sequence Constraint

We will convert the Sequence constraint to a flow by means of a linear program (LP). We shall use as a running example. We can formulate this constraint simply and directly as an integer linear program:

 l≤ X1+X2+X3 ≤u, l≤ X2+X3+X4 ≤u, l≤ X3+X4+X5 ≤u, l≤ X4+X5+X6 ≤u

where . By introducing surplus/slack variables, and , we convert this to a set of equalities:

 X1+X2+X3−Y1=l, X1+X2+X3+Z1=u, X2+X3+X4−Y2=l, X2+X3+X4+Z2=u, X3+X4+X5−Y3=l, X3+X4+X5+Z3=u, X4+X5+X6−Y4=l, X4+X5+X6+Z4=u

where . In matrix form, this is:

 ⎛⎜ ⎜ ⎜ ⎜⎝111000−100000001110000100000001110000−100000011100000100000011100000−100000111000000100000111000000−1000011100000001⎞⎟ ⎟ ⎟ ⎟⎠⎛⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜⎝X1⋮X6Y1Z1⋮Y4Z4⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠=⎛⎜ ⎜⎝lulululu⎞⎟ ⎟⎠

This matrix has the consecutive ones property for columns: each column has a block of consecutive 1’s or ’s and the remaining elements are 0’s. Consequently, we can apply the method of Veinott and Wagner [11] (also described in Application 9.6 of  [3]) to simplify the problem. We create a zero last row and subtract the th row from th row for to . These operations do not change the set of solutions. This gives:

 ⎛⎜ ⎜ ⎜ ⎜ ⎜⎝111000−1000000000000011000000−1001000−1−100000000000001100000−10010000−1−10000000000000110000−100100000−1−1000000000000011000−1−1−10000000−1⎞⎟ ⎟ ⎟ ⎟ ⎟⎠⎛⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜⎝X1⋮X6Y1Z1⋮Y4Z4⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠=⎛⎜ ⎜ ⎜ ⎜ ⎜⎝lu−ll−uu−ll−uu−ll−uu−l−u⎞⎟ ⎟ ⎟ ⎟ ⎟⎠

This matrix has a single and in each column. Hence, it describes a network flow problem [3] on a graph (that is, it is a network matrix). Each row in the matrix corresponds to a node in and each column corresponds to an edge in . Down each column, there is a single row equal to 1 and a single row equal to -1 corresponding to an edge in the graph. We include a source node and a sink node in . Let

be the vector on the right hand side of the equation. If

is positive, then there is an edge that carries exactly amount of flow. If is negative, there is an edge that caries exactly amount of flow. The bounds on the variables, which are not expressed in the matrix, are represented as bounds on the capacity of the corresponding edges.

The graph for the set of equations in the example is given in Figure 1. A flow of value in the graph corresponds to a solution. If a feasible flow sends a unit flow through the edge labeled with then in the solution; otherwise . Each even numbered vertex represents a window. The way the incoming flow is shared between and reflects how many variables in the

’th window are equal to 1. Odd numbered vertices represent transitions from one window to the next (except for the first and last vertices, which represent transitions between a window and nothing). An incoming

edge represents the variable omitted in the transition to the next window, while an outgoing edge represents the added variable.

###### Theorem 4.1

For any constraint , there is an equivalent network flow graph with edges, vertices, a maximum edge capacity of , and an amount of flow to send equal to . There is a one-to-one correspondence between solutions of the constraint and feasible flows in the network.

The time complexity of finding a maximum flow of value is using the Ford-Fulkerson algorithm [12]. Faster algorithms exist for this problem. For example, Goldberg and Rao’s algorithm finds a maximum flow in time where is the maximum capacity upper bound for an edge [13]. In our case, this gives time complexity. We follow Régin [1, 2] in the building of an incremental filtering algorithm from the network flow formulation. A feasible flow in the graph gives us a support for one value in each variable domain. Suppose is in the solution that corresponds to the feasible flow where is either zero or one. To obtain a support for , we find the SCC of the residual graph and check if both ends of the edge labeled with are in the same strongly connected component. If so, has a support; otherwise can be removed from the domain of . Strongly connected components can be found in linear time, because the number of nodes and edges in the flow network for the Sequence constraint is linear in by Theorem 4.1. The total time complexity for initially enforcing DC is if we use the Ford-Fulkerson algorithm or if we use Goldberg and Rao’s algorithm.

Still following Régin [1, 2], one can make the algorithm incremental. Suppose during search is fixed to value . If the last computed flow was a support for , then there is no need to recompute the flow. We simply need to recompute the SCC in the new residual graph and enforce DC in time. If the last computed flow is not a support for , we can find a cycle in the residual graph containing the edge associated to in time. By pushing a unit of flow over this cycle, we obtain a flow that is a support for . Enforcing DC can be done in after computing the SCC. Consequently, there is an incremental cost of when a variable is fixed, and the cost of enforcing DC down a branch of the search tree is .

## 5 Soft Sequence Constraint

Soft forms of the Sequence constraint may be useful in practice. The ROADEF 2005 challenge [14], which was proposed and sponsored by Renault, puts forward a violation measure for the Sequence constraint which takes into account by how much each Among constraint is violated. We therefore consider the soft global constraint, . This holds iff:

 T ≥ n−k+1∑i=1\rm max(l−k−1∑j=0(Xi+j∈v),k−1∑j=0(Xi+j∈v)−u,0) (1)

As before, we can simplify notation and consider SoftSequence on 0/1 variables and .

We again convert to a flow problem by means of a linear program, but this time with an objective function. Consider . We introduce variables, and to represent the penalties that may arise from violating lower and upper bounds respectively. We can then express this SoftSequence constraint as follows. The objective function gives a lower bound on .

 Minimize4∑i=1(Pi+Qi) subject to: X1+X2+X3−Y1+Q1=l, X1+X2+X3+Z1−P1=u, X2+X3+X4−Y2+Q2=l, X2+X3+X4+Z2−P2=u, X3+X4+X5−Y3+Q3=l, X3+X4+X5+Z3−P3=u, X4+X5+X6−Y4+Q4=l, X4+X5+X6+Z3−P4=u

where , , and are non-negative. In matrix form, this is:

 Minimize 4∑i=1(Pi+Qi)    subject  to: ⎛⎜ ⎜ ⎜ ⎜⎝111000−1000000010000000111000010000000−100000001110000−1000000010000001110000010000000−100000011100000−1000000010000011100000010000000−100000111000000−1000000010000111000000010000000−1⎞⎟ ⎟ ⎟ ⎟⎠
 ⎛⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜⎝X1⋮X6Y1Z1⋮Y4Z4Q1P1⋮Q4P4⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠=⎛⎜ ⎜⎝lulululu⎞⎟ ⎟⎠

If we transform the matrix as before, we get a minimum cost network flow problem:

 Minimize 4∑i=1(Pi+Qi)    subject  to: ⎛⎜ ⎜ ⎜ ⎜ ⎜⎝111000−100000001000000000000011000000−1−1000000−1001000−1−100000011000000000000011000000−1−100000−10010000−1−100000011000000000000011000000−1−10000−100100000−1−100000011000000000000011000000−1−1000−1−1−10000000−100000001⎞⎟ ⎟ ⎟ ⎟ ⎟⎠
 ⎛⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜⎝X1⋮X6Y1Z1⋮Y4Z4Q1P1⋮Q4P4⎞⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟⎠=⎛⎜ ⎜ ⎜ ⎜ ⎜⎝lu−ll−uu−ll−uu−ll−uu−l−u⎞⎟ ⎟ ⎟ ⎟ ⎟⎠

The flow graph for this system is presented in Figure 2. Dashed edges have cost , while other edges have cost . The minimal cost flow in the graph corresponds to a minimal cost solution to the system of equations

###### Theorem 5.1

For any constraint , there is an equivalent network flow graph. There is a one-to-one correspondence between solutions of the constraint and feasible flows of cost less than or equal to .

Using Theorem 5.1, we construct a DC filtering algorithm for the SoftSequence constraint. The SoftSequence constraint is DC iff the following conditions hold:

• value belongs to , iff there exists a feasible flow of cost at most that sends a unit flow through the edge labeled with .

• value belongs to , iff there exists a feasible flow of cost at most that does not send any flow through the edge labeled with .

• there exists a feasible flow of cost at most .

The minimal cost flow can be found in time [3]. Consider the edge in the residual graph associated to variable and let be its residual cost. If the flow corresponds to an assignment with , pushing a unit of flow on results in a solution with . Symmetrically, if the flow corresponds to an assignment with , pushing a unit of flow on results in a solution with . If the shortest path in the residual graph between and is , then the shortest cycle that contains has length . Pushing a unit of flow through this cycle results in a flow of cost which is the minimum-cost flow that contains the edge . If , then no flows containing the edge exist with a cost smaller or equal to . The variable must therefore be fixed to the value taken in the current flow. Following Equation 1, the cost of the variable must be no smaller than the cost of the solution. To enforce BC on the cost variable, we increase the lower bound of to the cost of the minimum flow in the graph .

To enforce DC on the variables efficiently we can use an all pairs shortest path algorithm on the residual graph [15]. This takes time using Johnson’s algorithm [12]. This gives an time complexity to enforce DC on SoftSequence. The penalty variables used for SoftSequence arise directly out of the problem description and occur naturally in the LP formulation. We could also view them as arising through the methodology of [16], where edges with costs are added to the network graph for the hard constraint to represent the softened constraint.

## 6 Generalized Sequence Constraint

To model real world problems, we may want to have different size or positioned windows. For example, the window size in a rostering problem may depend on whether it includes a weekend or not. An extension of the Sequence constraint proposed in  [9] is that each Among constraint can have different parameters (start position, , , and ). More precisely, holds iff for where . Whilst the methods in Section 4 easily extend to allow different bounds and for each window, dealing with different windows is more difficult. In general, the matrix now does not have the consecutive ones property. It may be possible to re-order the windows to achieve the consecutive ones property. If such a re-ordering exists, it can be found and performed in time, where is the number of non-zero entries in the matrix [17]. Even when re-ordering cannot achieve the consecutive ones property there may, nevertheless, be an equivalent network matrix. Bixby and Cunningham [18] give a procedure to find an equivalent network matrix, when it exists, in time. Another procedure is given in [19]. In these cases, the method in Section 4 can be applied to propagate the Gen-Sequence constraint in time down the branch of a search tree.

Not all Gen-Sequence constraints can be expressed as network flows. Consider the Gen-Sequence constraint with , identical upper and lower bounds ( and ), and 4 windows: [1,5], [2,4], [3,5], and [1,3]. We can express it as an integer linear program:

 ⎛⎜ ⎜ ⎜ ⎜⎝11111−1−1−1−1−1011100−1−1−100011100−1−1−111100−1−1−100⎞⎟ ⎟ ⎟ ⎟⎠⎛⎜⎝X1X2X3X4X5⎞⎟⎠≥⎛⎜ ⎜ ⎜⎝l−ul−ul−ul−u⎞⎟ ⎟ ⎟⎠ (2)

Applying the test described in Section 20.1 of [19] to Example 2, we find that the matrix of this problem is not equivalent to any network matrix.

However, all Gen-Sequence constraint matrices satisfy the weaker property of total unimodularity. A matrix is totally unimodular iff every square non-singular submatrix has a determinant of or . The advantage of this property is that any totally unimodular system of inequalities with integral constants is solvable in iff it is solvable in .

###### Theorem 6.1

The matrix of the inequalities associated with Gen-Sequence constraint is totally unimodular.

In practice, only integral values for the bounds and are used. Thus the consistency of a Gen-Sequence constraint can be determined via interior point algorithms for LP in time. Using the failed literal test, we can enforce DC at a cost of down the branch of a search tree for any Gen-Sequence constraint. This is too expensive to be practical. We can, instead, exploit the fact that the matrix for each Gen-Sequence constraint has the consecutive ones property for rows (before the introduction of slack/surplus variables). Corresponding to the row transformation for matrices with consecutive ones for columns is a change-of-variables transformation into variable for matrices with consecutive ones for rows. This gives the dual of a network matrix. This is the basis of an encoding of Sequence in [10] (denoted there ). Consequently that encoding extends to Gen-Sequence. Adapting the analysis in [10] to Gen-Sequence, we can enforce DC in time down the branch of a search tree.

In summary, for a compilation cost of , we can enforce DC on a Gen-Sequence constraint in down the branch of a search tree, when it has a flow representation, and in when it does not.

## 7 A SlidingSum Constraint

The SlidingSum constraint [20] is a generalization of the Sequence constraint from Boolean to integer variables, which we extend to allow arbitrary windows. SlidingSum holds iff holds where is, as with the generalized Sequence, a window. The constraint can be expressed as a linear program called the primal where is a matrix encoding the inequalities. Since the constraint represents a satisfaction problem, we minimize the constant 0. The dual is however an optimization problem.

 min0⎡⎢ ⎢ ⎢⎣W−WI−I⎤⎥ ⎥ ⎥⎦X≥⎡⎢ ⎢ ⎢⎣l−ua−b⎤⎥ ⎥ ⎥⎦⎫⎪ ⎪ ⎪ ⎪ ⎪ ⎪⎬⎪ ⎪ ⎪ ⎪ ⎪ ⎪⎭P min[−lu−ab]Y[WT−WTI−I]Y=0Y≥0⎫⎪⎬⎪⎭D (3)

Von Neumann’s Strong Duality Theorem states that if the primal and the dual problems are feasible, then they have the same objective value. Moreover, if the primal is unsatisfiable, the dual is unbounded. The SlidingSum constraint is thus satisfiable if the objective function of the dual problem is zero. It is unsatisfiable if it tends to negative infinity.

Note that the matrix has the consecutive ones property on the columns. The dual problem can thus be converted to a network flow using the same transformation as with the Sequence constraint. Consider the dual LP of our running example:

 Minimize −4∑i=1liYi+4∑i=1uiY4+i−5∑i=1aiY8+i+5∑i=1biY13+i    subject  to: ⎛⎝1001−100−110000−100001101−1−10−1010000−10001111−1−1−1−10010000−1001110−1−1−1000010000−101010−10−10000010000−1⎞⎠(Y1⋮Y18)=(0⋮0)

Our usual transformation will turn this into a network flow problem:

 Minimize −4∑i=1liYi+4∑i=1uiY4+i−5∑i=1aiY8+i+5∑i=1biY13+i    subject  to:

The flow associated with this example is given in Figure 3. There are nodes labelled from 1 to where node is connected to node with an edge of cost and node is connected to node with an edge of cost . For each window , we have an edge from to with cost and an edge from to with cost . All nodes have a null supply and a null demand. A flow is therefore simply a circulation i.e., an amount of flow pushed on the cycles of the graph.

###### Theorem 7.1

The SlidingSum constraint is satisfiable if and only there are no negative cycles in the flow graph associated with the dual linear program.

###### Proof

If there is a negative cycle in the graph, then we can push an infinite amount of flow resulting in a cost infinitely small. Hence the dual problem is unbounded, and the primal is unsatisfiable. Suppose that there are no negative cycles in the graph. Pushing any amount of flow over a cycle of positive cost results in a flow of cost greater than zero. Such a flow is not optimal since the null flow has a smaller objective value. Pushing any amount of flow over a null cycle does not change the objective value. Therefore the null flow is an optimal solution and since this solution is bounded, then the primal is satisfiable. Note that the objective value of the dual (zero) is in this case equal to the objective value of the primal. ∎

Based on Theorem 7.1 we build a BC filtering algorithm for the SlidingSum constraint. The SlidingSum constraint is BC iff the following conditions hold:

• value is the lower bound of a variable , iff is the smallest value in the domain of such that there are no negative cycles through the edge weighted with and labeled with the lower bound of .

• value is the upper bound of a variable , iff is the greatest value in the domain of such that there are no negative cycles through the edge weighted with and labeled with the upper bound of

The flow graph has nodes and edges. Testing whether there is a negative cycle takes time using the Bellman-Ford algorithm. We find for each variable the smallest (largest) value in its domain such that assigning this value to does not create a negative cycle. We compute the shortest path between all pairs of nodes using Johnson’s algorithm in time which in our case gives time. Suppose that the shortest path between and has length , then for the constraint to be satisfiable, we need . Since is a value potentially taken by , we need to have . We therefore assign . Similarly, let the length of the shortest path between and be . For the constraint to be satisfiable, we need . Since is a value potentially taken by , we have . We assign . It is not hard to prove this is sound and complete, removing all values that cause negative cycles. Following [10], we can make the propagator incremental using the algorithm by Cotton and Maler [21] to maintain the shortest path between pairs of nodes in time upon edge reduction. Each time a lower bound is increased or an upper bound is decreased, the shortest paths can be recomputed in time.

## 8 Experimental Results

To evaluate the performance of our filtering algorithms we carried out a series of experiments on random problems. The experimental setup is similar to that in [10]. The first set of experiments compares performance of the flow-based propagator on single instance of the Sequence constraint against the propagator111We would like to thank Willem-Jan van Hoeve for providing us with the implementation of the algorithm. (the third propagator in [9]), the encoding of [10], and the Among decomposition () of Sequence. The second set of experiments compares the flow-based propagator for the SoftSequence constraint and its decomposition into soft Among constraints. Experiments were run with ILOG 6.1 on an Intel Xeon 4 CPU, 2.0 Ghz, 4G RAM. Boost graph library version was used to implement the flow-based algorithms.

### 8.1 The Sequence constraint

For each possible combination of , , , we generated twenty instances with random lower bounds in the interval . We used random value and variable ordering and a time out of sec. We used the Ford-Fulkerson algorithm to find a maximum flow. Results for different values of are presented in Tables 12 and Figure 4. Table 1 shows results for tight problems with and Table 2 for easy problems with . To investiage empirically the asymptotic growth of the different propagators, we plot average time to solve 20 instances against the instance size for each combination of parameters and in Figure 4. First of all, we notice that the encoding is the best on hard instances () and the decomposition is the fastest on easy instances (). This result was first observed in  [10]. The propagator is not the fastest one but has the most robust performance. It is sensitive only to the value of and not to other parameters, like the length of the window() or hardness of the problem(). As can be seen from Figure 4, the propagator scales better than the other propagators with the size of the problem. It appears to grow linearly with the number of variables, while the propagator display quadratic growth.

### 8.2 The Soft Sequence constraint

We evaluated performance of the soft Sequence constraint on random problems. For each possible combination of , , and (where is the number of Sequence constraints), we generated twenty random instances. All variables had domains of size 5. An instance was obtained by selecting random lower bounds in the interval . We excluded instances where

to avoid unsatisfiable instances. We used a random variable and value ordering, and a time-out of

sec. All Sequence constraints were enforced on disjoint sets of cardinality one. Instances with are hard instances for Sequence propagators [10], so that any DC propagator could solve only few instances. Instances with are much looser problems, but they are still hard do solve because each instance includes four overlapping Sequence constraints. To relax these instances, we allow the Sequence constraint to be violated with a cost that has to be less than or equal to of the length of the sequence. Experimental results are presented in Table 3. As can be seen from the table, the algorithms is competitive with the decomposition into soft Among constraints on relatively easy problems and outperforms the decomposition on hard problems in terms of the number of solved problems.

We observed that the flow-based propagator for the SoftSequence constraint () is very slow. Note that the number of backtracks of is three order of magnitudes smaller compared to . We profiled the algorithm and found that it spends most of the time performing the all pairs shortest path algorithm. Unfortunately, this is difficult to compute incrementally because the residual graph can be different on every invocation of the propagator.