The Soft Cumulative Constraint Thierry Petit
Emmanuel Poder
[email protected]
[email protected]
arXiv:0907.0939v2 [cs.AI] 7 Jul 2009
´ Research report TR09/06/info, Ecole des Mines de Nantes, LINA UMR CNRS 6241.
Abstract This research report presents an extension of Cumulative of Choco constraint solver, which is useful to encode over-constrained cumulative problems. This new global constraint uses sweep and task interval violation-based algorithms.
1
Introduction
The Cumulative global constraint provides a pruning algorithm which takes account of all activities at the same time, which has been proved to be much more efficient than CP approaches considering a conjunction of more primitive constraints. This representation as a global constraint has been widely studied in the literature and integrated into many constraint systems [1, 2, 3, 4, 5]. Definition 1 Let A = {a1 , . . . , an } denote a set of n non-preemptive activities. For each a ∈ A, • start[a] is the variable representing its starting point in time. • dur[a] is the variable representing its duration. • end[a] ∈ end is the variable representing its ending point in time. • res[a] is the variable representing the discrete amount of resource consumed by a, also denoted the height of a. Definition 2 Consider one resource with a limit of capacity max capa and a set A of n activities.PAt each point in time t, the cumulated height ht of the set of activities overlapping t is ht = a∈A,start[a]≤t max capa then ]δ−min(D(dur[a])), δ ′ [ can be removed from D(start[a]). Time complexity of the sweep technique is O(n ∗ log(n)). Please refer to the paper for more details w.r.t. this algorithm [4]. 2.1.2
Energy reasoning on Task Intervals [8, 2, 9]
The principle of the energy reasoning is to compare the resource necessarily required by a set of activities within a given interval of points in time with the available resource within this interval. Relevant intervals are obtained from starts and ends of activities (“task intervals”). This section presents the rules implemented in Choco. Notation 1 Given ai and aj two activities (possibly the same) s.t. min(D(start[ai ])) < max(D(end[aj ])), we denote by: 3
• I(ai ,aj ) the interval [min(D(start[ai ])), max(D(end[aj ]))[. • S(ai ,aj ) the set of activities whose time-windows intersect I(ai ,aj ) and such that their earliest start is in I(ai ,aj ) , that is, S(ai ,aj ) = {a ∈ A s.t. min(D(start[ai ])) ≤ min(D(start[a])) < max(D(end[aj ]))}. • Area(ai ,aj ) the number of free resource units in I(ai ,aj ) , that is, Area(ai ,aj ) = (max(D(end[aj ])) − min(D(start[ai ]))) ∗ max capa. Definition 5 A lower bound W(ai ,aj ) (a) of the number of resource units consumed by a ∈ S(ai ,aj ) on I(ai ,aj ) is W(ai ,aj ) (a) = min(D(res[a])) ∗ min[min(D(dur[a])), max(0, max(D(end[aj ])) − max(D(start[a])))] P Feasibility Rule 1 If a∈S(a ,a ) W(ai ,aj ) (a) > Area(ai ,aj ) then fail. i
j
Algorithm The principle is to browse, by increasing due date, activities aj ∈ A and for a given aj to browse, by decreasing release date, activities ai ∈ A such that min(D(start[ai ])) < max(D(end[aj ])). Hence, at each new choice of ai or aj more activities are considered. For each couple (ai , aj ), the algorithm applies the feasibility rule 1. Suppose the activities sorted by increasing release date i.e. min(D(start[a1 ])) ≤ min(D(start[a2 ])) ≤ · · · ≤ min(D(start[an ])), then: • If min(D(start[ai−1 ])) = min(D(start[ai ])) then S(ai−1 ,aj ) = S(ai ,aj ) and therefore P 1 a∈S(a ,a ) W(ai−1 ,aj ) (a). i
P
a∈S(ai−1 ,aj )
W(ai−1 ,aj ) (a)
=
j
• Else We have S(ai−1 ,aj ) = S(ai ,aj ) ∪ {ak ∈ A, k ≤ i − 1 ∧ min(D(start[ak ])) = min(D(start[ai−1 ]))} i.e. Pwe add all activities with same release date than P W (a) = activity ai−1 . Hence, (ai−1 ,aj ) a∈S(ai ,aj ) W(ai ,aj ) (a) + a∈S(ai−1 ,aj ) P {k≤i−1∧min(D(start[ak ]))=min(D(start[ai−1 ]))} W(ai ,aj ) (a). Therefore, the complexity for handling all intervals I(ai ,aj ) is O(n2 ).
2.2
Pruning Related to Relaxation
Specific constraints on over-loads exist in real-world applications. To express them, it is mandatory to discretize time, while keeping a reasonable time complexity for pruning. These specific constraints are externalized because they are ad-hoc to each application. On the other hand, the following constraints capture the generic core of this class of problems. 1 By
definition, W(ai ,aj ) (a) is independent of ai so W(ai−1 ,aj ) (a) = W(ai ,aj ) (a).
4
• SoftCumulative extends Cumulative of Choco by maintaining over-loads variables at each point in time, and by pruning activities according to maximal available capacities given by upper bounds of these variables instead of simply considering max capa. This constraint can be used with various objective criteria. • The SoftCumulativeSum extends the SoftCumulative. It is defined to deal more efficiently with a particular criterion: minimize the sum of over-loads. 2.2.1
SoftCumulative Constraint
Definition 6 Let A be a set of activities scheduled between time 0 and m, each consuming a positive amount of the resource. SoftCumulative augments Cumulative with a second limit of resource ideal capa ≤ max capa, and for each point in time t < m an integer variable costV ar[t]. It enforces: • C1 and C2 (see Definition 2). • C3: For each point in time t, costV ar[t] = max(0, ht − ideal capa) costVar[t]: maximum values of domains
max_capa
ideal_capa 0 costVar[i] lower bounds:
m 2
2
2
0
0
0 0 0
Figure 3: Example of a SoftCumulative constraint. Example 2 Figure 3 depicts an example of a cumulative profile CumP where at each point in time t the height of CumP at t does not exceed the maximum value in the domain of its corresponding violation variable costV ar[t]. Time points 1, 2, 3 are such that CumP exceeds ideal capa by two. Therefore, for each point, the minimum value of the domain of the correspondong variable in costV ar should be updated to value 2. Next paragraph details how the classical sweep procedure can be adapted to the SoftCumulative constraint. Revised Sweep pruning procedure. The limit of resource is not max capa as in the Cumulative constraint. It is mandatory to take into account upper-bounds of variables in costV ar. One may integrate reductions on upper bounds within the profile, as new fixed activities. However, our discretization of time can be very costly with this method : the number of events may grow significantly. The profile would not be computed only from activities but also from each point in time.
5
We propose a relaxed version where for each rectangle we consider the maximum costV ar upper bound. This entails less pruning but the complexity is amortized: the number of time points checked to obtain maximum costV ar upper bounds for the whole profile is m, by exploiting the sort on events into the sweep procedure. Pruning rule 2 reduce domains of start variables from the current maximum allowed over-load in a rectangle.2 Pruning Rule 2 Let a ∈ ActT oP rune, which has no compulsory part recorded within the current rectangle. If sumh +min(D(res[a])) > ideal capa+maxt∈[δ,δ′ [ (max(D(costV ar[t]))) then ]δ − min(D(dur[a])), δ ′ [ can be removed from D(start[a]). Proof: For any activity which overlaps the rectangle, the maximum capacity is upper-bounded by ideal capa + max(D(costV ar[t]), t ∈ [δ, δ ′ [).
Time complexity is O(n ∗ log(n) + m), where m is the maximum due date. Revised task Intervals energy reasoning. This paragraph describes the extension of the principle of section 2.1.2 to the SoftCumulative global constraint. Feasibility Rule 2 Area(ai ,aj ) = X
ideal capa + max(D(costV ar[t]))
t∈[min(D(start[ai ])),max(D(end[aj ]))[
If
P
a∈S(ai ,aj )
W(ai ,aj ) (a) > Area(ai ,aj ) then fail.
Proof: At each time point t there is ideal capa + max(D(costV ar[t])) available units.
Efficiency of rule 1 can be improved by this new computation of Area(ai ,aj ) (the previous value was an over-estimation). Since activities ai are considered by decreasing release date, it is possible to compute incrementally Area(ai ,aj ) . Each upper bound of a variable in costV ar are considered once for each aj . Time complexity is O(n2 + n ∗ m), where m is the maximum due date. Next paragraph explains how minimum values of domains of variables in costV ar are updated during the search process. Update costVar lower-bounds. Update of costV ar lower bounds can be directly performed within the sweep algorithm, while the profile is computed. Pruning Rule 3 Consider the current rectangle in the profile, [δ, δ ′ [. For each t ∈ [δ, δ ′ [, if sumh − ideal capa > min(D(costV ar[t])) then [min(D(costV ar[t])), sumh − ideal capa[ can be removed from D(costV ar[t]). Proof: From Definitions 3 and 4. 2 The upper bound max(D(costV ar[t])) is the maximum value in the domain D(costV ar[t]). Since these variables may be involved in several constraints, especially side constraints, the maximum value of a domain can be reduced during the search process.
6
Usually the constraint should not be associated with a search heuristic that forces to assign to a given variable in costV ar a value which is greater than the current lower bound of its domain. Indeed, such a search strategy would consist of imposing at this point in time a violation although solutions with lower over-loads at this point in time exist (or even solutions with no over-load). However, it is required to take into account this eventuality and to ensure that our constraint is valid with any search heuristic. If a greater value is fixed to a variable in costV ar, until more than a very few number of unfixed activities exist, few deductions can be made in terms of pruning and they may be costly (for a quite useless feature). Therefore, we implemented a check procedure that fails when all start variables are fixed and one variable in costV ar is higher than the current profile at this point in time. This guarantees that ground solutions will satisfy the constraint in any case, with a constant time complexity. 2.2.2
SoftCumulativeSum Constraint
Definition 7 SoftCumulativeSum augments SoftCumulative with an integer variable cost. It enforces: • C1 and C2 (see Definition 2), and C3 (see Definition 6). P • The following constraint: cost = t∈{0,...,m−1} costV ar[t] Pruning procedures and consistency checks of SoftCumulative remain valid for SoftCumulativeSum. Additionally, we aim at dealing with the sum constraint efficiently by exploiting the semantics. We compute lower bounds of the sum expressed by cost variable. Classical back-propagation of this variable can be additionally performed as if the sum constraint was defined separately. Example 3 The term back-propagation is used to recall that propagation of events is not only performed from the decision variables to the objective variable but also from the objective variable to decision variables. For instance, let x1 , x2 and x3 be 3 variables with the same domain: ∀i ∈ {1, 2, 3}, D(xi ) = {1,P 2, 3}. Let sum be a variable, D(sum) = {3, 4, . . . , 9}, and the following constraint sum = i∈{1,2,3} xi . Assume that 2 is removed from all D(xi ). The usual propagation removes values 4, 6 and 8 from D(sum). Assume now that all values greater than or equal to 5 are removed from D(sum). Back-propagation removes value 3 from all D(xi ). Sweep based global lower bound. Within our global constraint, a lower bound for the cost variable is directly given by summing the lower bounds of all variables in costV ar, which are obtained by pruning rule 3. These minimum values of domains were computed from compulsory parts, not only from fixed activities. X min(D(costV ar[t])) LB1 = t∈{0,...,m−1}
LB1 can be computed with no increase in complexity within the sweep algorithm. P Interval based global lower bound. The quantity a∈S(a ,a ) W(ai ,aj ) (a) used in feasii j bility rule 1 provides the required energy for activities in the interval I(ai ,aj ) . This quantity
7
may exceed the number of time points in I(ai ,aj ) multiplied by ideal capa. We can improve LB1 , provided we remove from the computation over-loads yet taken into account in the cost variable. In our implementation, we first update variables in costV ar (by rule 3), and compute LB1 to update cost. In this way, no additional incremental data structure is required. To obtain the new lower bound we need to compute lower-bounds of cost which are local to each interval I(ai ,aj ) . P Definition 8 lb1(ai ,aj ) = t∈I(a ,a ) min(D(costV ar[t])) i
j
Then, next proposition is related to the free available number of resource units within a given interval. Proposition 1 The number FreeArea(ai ,aj ) of free resource units in I(ai ,aj ) s. t. no violation is entailed is (max(D(end[aj ])) − min(D(start[ai ]))) ∗ ideal capa. Proof: From Definition 7.
From Definition 8 and Proposition 1, FreeArea(ai ,aj ) + lb1(ai ,aj ) is the number of time units that can be used without creating any new over-load into the interval I(ai ,aj ) compared with over-loads yet taken into account in lb1(ai ,aj ) . P Definition 9 Inc(ai ,aj ) = a∈S(a ,a ) W(ai ,aj ) (a)−FreeArea(ai ,aj ) − lb1(ai ,aj ) i
j
Inc(ai ,aj ) is the difference between the required energy and this quantity. Even if one variable in costV ar has a current lower bound higher that the value obtained from the profile, the increase Inc(ai ,aj ) is valid (smaller, see Definition 8). We are now able to improve LB1 . LB2 = LB1 + max(ai ,aj )∈A2 (Inc(ai ,aj ) ) Another lower bound can be computed from a partition P P of [0, m[ in disjoint intervals obtained from pairs of activities (ai , aj ): LB(P ) = LB1 + I(a ,a ) ∈P Inc(ai ,aj ) . Obvii j ousy LB2 ≤ LB(P ) . However, time complexity of the algorithm deduced from rule 2 in the SoftCumulative constraint is O(n2 + n ∗ m). This complexity should reasonably not be increased. Computing LB2 can be directly performed into this algorithm without any increase in complexity.3 Pruning Rule 4 If LB2 > min(D(cost)) then [min(D(cost)), LB2 [ can be removed from D(cost). Proof: From Definition 7, LB1 is a lower bound of cost. Since intervals are disjoint, by Definition 9 the quantity LB(P ) is a lower bound of cost. LB2 ≤ LB(P ) . Therefore LB2 is a lower bound of cost. The pruning rule holds.
Aggregating local violations. Once the profile is computed, if some activities having a null compulsory part cannot be scheduled without creating new over-loads, then LB1 can be augmented with the sum of minimum increase of each activity. This idea is inspired from generic solving methods for over-constrained CSPs, e.g., Max-CSP [10]. Our experiments shown that there is quite often a way to place any activity without creating a new violation. This entails a null lower bound. Therefore, we removed that computation from our implementation. We inform the reader that we described the procedure in a preliminary technical report [11]. 3 On the contrary, determining a relevant partition P from the activities would force to use an independent algorithm, which can be costly depending on the partition we search for. Finally, we decided to use only LB2 .
8
Instance
cost value
1 2 3 4 5 6 7 8
0 2 10 2 6 0 10 6
SoftCumulative + external sum 92 (0.07 s) 417 (0.29 s) > 30 s 1301 (0.59 s) 19506 (13.448 s) 53 (0.00 s) > 30 s > 30 s
SoftCumulativeSum 92 (0.01 s) 94 (0.01 s) 63 (0.01 s) 194 (0.06 s) 97 (0.01 s) 53 (0.00 s) 90 (0.01 s) 152 (0.07 s)
Table 1: Number of nodes of optimum schedules with n = 9, m = 9, durations between 1 and 4, resource consumption between 1 and 3, ideal capa = 3, max capa = 7.
2.2.3
Implementation
Constraints were implemented to work with non fixed durations and resource consumptions. Table 1 compares the two constraints on small problems when the objective is to minimize cost. Results show the main importance of LB2 when minimizing cost.
3
Extension
The global constraint presented in this research report can be tailored to be suited to some other classes of applications. If the time unit is tiny compared with the makespan, e.g., one minute in a one-year schedule, the same kind of model may be used by grouping time points. For example, each violation variable may correspond to one half-day. Imposing a side constraint between two particular minutes into a one-year schedule is generally not useful. For this purpose, the SoftCumulative constraint can be generalized, to be relaxed with respect to its number of violation cost variables.
3.1
RelSoftCumulative constraint
Notation 2 To define RelSoftCumulative we use the following notations. Given a set of activities scheduled between 0 and m, • mult ∈ {1, 2, ..., m} is a positive integer multiplier of the unit of time. • Starting from 0, the number of consecutive discrete intervals of length mult that are included in the interval [0, ..m[ is ⌈m/mult⌉. J = {0, 1, . . . , ⌈m/mult⌉ − 1} is the set of indexes of such intervals. Hence, to each j ∈ J corresponds the interval [j ∗mult, j ∗ mult + 1, . . . (j + 1) ∗ mult − 1]. Definition 10 Let A be a set of activities scheduled between time 0 and m, each consuming a positive amount of the resource. RelSoftCumulative augments Cumulative with • A second limit of resource ideal capa ≤ max capa, • The multiplier mult ∈ {1, 2, . . . , m}, • For each j ∈ J an integer variable costV ar[j].
9
It enforces: • C1 and C2 (see Definition 2). • C4: For each j ∈ J , costV ar[j] =
P(j+1)∗mult−1 t=j∗mult
max(0, ht − ideal capa)
Example 4 We consider a cumulative over-constrained problem with n activities scheduled minute by minute over one week. The makespan is m = 2940. Assume that a user formulates a side constraint related to the distribution of over-loads of resource among ranges of one hour (mult = 60) in the schedule, for instance ”no more than one hour violated each half-day”. The instance of RelSoftCumulative related to this problem is defined with ⌈2940/60⌉, i.e., 49 violation variables, J = {0, 1, . . . , 48}. For each range indexed by j ∈ J , the constraint (j+1)∗60−1 max(0, ht − ideal capa). The side constraint is then C3 is: costV ar[j] = sumt=j∗60 simply expressed by cardinality constraints over each half-day, that is, each quadruplet of violation variables: {costV ar[0], · · · , costV ar[3]}, {costV ar[4], · · · , costV ar[7]}, etc. It is possible to reformulate rules of section 2.2 to make them suited to RelSoftCumulative. Firstly, rule 2 can be re-written for the constraint RelSoftCumulative. Pruning Rule 5 Let a ∈ ActT oP rune, which has no compulsory part recorded within the current rectangle. If sumh + min(D(res[a])) > ideal capa + max(max(D(costV ar[j]), j/[δ, δ ′ [∩J (j) 6= ∅))4 then ]δ − min(D(dur[a])), δ ′ [ can be removed from D(start[a]). Similarly, rule 2 is reformulated as follows: Feasibility Rule 3 Area(ai ,aj ) = X If
P
ideal capa + max(D(costV ar[⌊t/mult⌋]))
t∈[min(D(start[ai ])),max(D(end[aj ]))[ a∈S(ai ,aj )
W(ai ,aj ) (a) > Area(ai ,aj ) then fail.
To update minimum values of domains of variables in costV ar in RelSoftCumulative, we simply have to update for each violation variable, during the sweep, the current sum of over-loads of its time points. This may be done only by maintaining one value and one index, but for sake of clarity we use the following notation. Notation 3 Given a set of ranges in time indexed by J = {0, 1, . . . , ⌈m/mul⌉ − 1}, costarray is an array of integers. All of them are initially set to 0. They are one-toone mapped with elements in J . Next rule reformulates rule 3 for RelSoftCumulative. Pruning Rule 6 Consider the current rectangle in the profile, [δ, δ ′ [. For each t ∈ [δ, δ ′ [, if sumh − ideal capa > 0 then: 1. costarray[⌊t/mult⌋] ← costarray[⌊t/mult⌋] + sumh − ideal capa 2. if costarray[⌊t/mult⌋] > min(D(costV ar[⌊t/mult⌋])) then: The range [min(D(costV ar[⌊t/mult⌋])), costarray[⌊t/mult⌋][ can be removed from D(costV ar[⌊t/mult⌋]). 4 The range of index j in J corresponding to time point t is ⌊t/mult⌋. Hence, the set of j such that [δ, δ′ [∩J (j) 6= ∅)) is {⌊δ/mult⌋, . . . , ⌊(δ′ − 1)/mult⌋}.
10
3.2
RelSoftCumulativeSum constraint
Definition 11 RelSoftCumulativeSum augments RelSoftCumulative with an integer variable cost. It enforces: • C1 and C2 (see Definition 2), and C4 (see Definition 10). P • The following constraint: cost = j∈J costV ar[j] Sweep based global lower bound. as for the SoftCumulativeSum constraint presented in section 2.2.2, a lower bound for the cost objective variable is given by summing the lower bounds of all variables in costV ar, without any increase in complexity in the sweep algorithm. X LB1 = min(D(costV ar[j])) j∈J
Interval based global lower bound. The task interval energetic reasoning presented in section 2.2.2 remains the same, except the evaluation of the quantity lb1 , which corresponds to over-loads expressed by variables in costV ar array (see definition 8). Within the filtering algorithm of the SoftCumulativeSum constraint, lb1 is the sum of min(costV ar[t]) over all points int time t within each considered interval, providing that, in the implementation, all variables in costV ar array are updated before computing lb1 . With respect to the RelSoftCumulative constraint, by definition 11, if mult is greater than or equal to two then it is not possible to evaluate at each point in time t the exact over-load at t. Under-estimating lb1 would be false because this leads to a over-estimation of task interval based lower bounds (see Definition 9). Therefore, we compute an over-estimation of lb1 , the tightest possible according to the definition of the constraint. Notation 4 Let I = [a, b] be an interval of points in time included in [0, m[, and the set of indexes for intervals in time J = {0, 1, . . . , ⌈m/mul⌉ − 1}. For each j ∈ J, #(I, j) is the number of time points in common between the range indexed by j and I: #(I, j) = |[a, b] ∩ J (j)| We can now reformulate Definition 8 for the RelSoftCumulative. The idea is to evaluate for each J (j) intersecting the current interval I(ai ,aj ) , the minimum value between min(D(costV ar[j])) and the maximum possible over-load in I ∩ J (j), which is equal from Definition 11 to #(I, j) ∗ (max(D(costV ar[j])) − ideal capa). Definition 12 Let I(ai ,aj ) be a task interval, and J = {j ∈ J , #j(I(ai ,aj ) ) > 0}. X lb1 = min(min(D(costV ar[j])), #(I, j) ∗ (max(D(costV ar[j])) − ideal capa)) j∈J
4
Conclusion
This report proposed several filtering procedures for a global Cumulative constraint which is relaxed w.r.t. to its capacity at some points in time. We provided the extension of our global constraint for the case where side constraints are related to ranges in time which are larger than one time unit. 11
References [1] Aggoun, A., Beldiceanu, N.: Extending CHIP in order to solve complex scheduling and placement problems. Mathl. Comput. Modelling 17(7), 57–73 (1993) [2] Caseau, Y., Laburthe, F.: Cumulative scheduling with task intervals. Proc. JICSLP (Joint International Conference and Symposium on Logic Programming) pp. 363–377 (1996) [3] Carlsson, M., Ottosson, G., Carlson, B.: An open-ended finite domain constraint solver. Proc. PLILP pp. 191–206 (1997) [4] Beldiceanu, N., Carlsson, M.: A new multi-resource cumulatives constraint with negative heights. Proc. CP pp. 63–79 (2002) [5] Mercier, L., Hentenryck, P.V.: Edge finding for cumulative scheduling. INFORMS Journal on Computing 20(1), 143–153 (2008) [6] Choco: A Java library for CSPs, constraint programming and explanation-based constraint solving. URL: http://choco.sourceforge.net/ (2007) [7] Lahrichi, A.: The notions of Hump, Compulsory Part and their use in Cumulative Problems. C.R. Acad. sc. t. 294, 209–211 (1982) [8] Lopez, P., Erschler, J., Esquirol, P.: Ordonnancement de tˆ aches sous contraintes : une approche ´energ´etique. Automatique, Productique, Informatique Industrielle 26:5-6, 453–481 (1992) [9] Baptiste, P., Le Pape, C., Nuitjen, W.: Satisfiability tests and time-bound adjustments for cumulative scheduling problems. Annals of Operations Research 92, 305–333 (1999) [10] Larrosa, J., P.Meseguer: Exploiting the use of DAC in Max-CSP. Proc. CP pp. 308–322 (1996) [11] Petit, T.: Propagation of practicability criteria. Research report TR0701/info, Ecole des Mines de Nantes (2007)
12