• No results found

2.6 Costraint Programming

2.6.2 Modeling

CP has powerful modeling syntax. With CP it is possible to model classical unary and binary constraint as in MILP (e.g. A > 3 and A > B) but also nonlinear constraints such as A 6= B. Moreover, CP introduces the concept of global constraints [113]. A global constraint is a constraint that involves a set of variables and it encapsulates a set of different constraints. An example of global constraint is the AllDif f erent(X). This constraint target a set of variables X and can be formally expressed as in equation2.2.

20 Chapter 2. Related work

Suppose X = {X1, X2, X3} with X1 ∈ 1, 2, 3 and X2, X3 ∈ 1, 2, the con-

straints generated by the global constraint AllDif f erent(X) will be:

X1 6= X2, X1 6= X3, X2 6= X3 (2.3)

Modeling these constraints with binary constraints and enforcing Arc Con- sistency [114] no value can be excluded from the variable domain. However, it can be noticed that X2 and X3 can assume only values 1 and 2. Thus,

these values can be deleted by the domain of X1. This is achieved by by the

AllDif f erentconstraint due to the fact that global constraints have a wider knowledge of the problem while binary constraints only consider two vari- ables at time.

The difference between CP and CSP relies on the possibility to add an objective function to the model. This function tells how a solution, among all the feasible solutions, is good. Considering the previous example, in which we have to assign a different value to a set of three variables, each one with a domain [1, . . . , 4], we can for example model a problem in which the best solution is the one with the highest possible values as result. This problem will be modeled as in equation2.4.

X = {X1, X2, X3} x = [1, 2, 3, 4] ∀x ∈ X AllDif f erent(X) maximize : X x∈X x (2.4)

One of the optimal results obtainable from this model is X1 = 4, X2 =

2, X3 = 3.

CP modeling for scheduling problems

In this section, we will discuss the CP modeling for scheduling problems. The problem we target here is the scheduling on non-preemptive jobs (i.e. each started job cannot be stopped until its termination), with fixed durations and fixed resources requirement, on a set of resources with fixed capacity (i.e. cumulative resources).

To explain this we introduce the concept of interval variable [115]. An inter- val variable is a variable that models an activity (or job). This kind of variable contains several different decisional variables. For sake of simplicity, we can say that an interval variables a is composed by a decisional variable for its starting time a.st, a decisional variable for its duration a.d, a decisional vari- able for its end time a.et and a decisional variable for its presence a.p. If an interval is present, all the constraints on this variable propagate otherwise this variables do not propagate. The interval variable has also implicit con- straints that model its consistency (e.g. the end time is equal to the start time

2.6. Costraint Programming 21

FIGURE2.4: Example of cumulative

plus the duration). These constraints are formally explained in equation2.5

where inf is the highest number representable in the used architecture. a.et = a.st = a.d = [−inf, . . . , inf ]

a.p = [−1, . . . , 1]

(a.p == 1) × (a.et = a.st + a.d)

(2.5)

Now we explain some of the most used constraints in scheduling and also in this thesis.

Synchronize The synchronize constraint synchronize(a, b) is designed to synchronize two different interval variables. This means that the variable assumes the same start time, end time, duration and presence.

NoOverlap The no-overlap constraint N oOverlap(a, b) is designed to set two activities to do not be active at the same time. Formally speaking, the interval variable a can start after the end of b or the variable a have to end before the start of b (Equation2.6).

a.st ≥ b.et ∨ a.et ≤ b.st (2.6)

Cumulative The cumulative constraint Cumulative(A, U, l) (Figure 2.4) is designed to schedule a set of activities, that requires a certain amount of re- sources, to never overpass the resource capacity. Formally speaking, having a set of interval variable A = {a1, . . . , an} each one with a resource require-

ment U = {u1, . . . , un} and a physical resource capacity l, the constraint hold

iff the resource utilization of the resources never overpass the capacity in any time instant.

This constraint is used in HPC scheduling to limit the utilization within a single node resource.

22 Chapter 2. Related work

Alternative The alternative constraint Alternative(a, B, n) is designed to select n elements from the set of activities B to be synchronized with a. For- mally speaking, a is a present alternative variable, B is a set with cardinality ≥ n of optional interval variables, and n is an integer. The constraint holds iff there are exactly n variables in B that can be set as present and synchronized with a (i.e. they assume the same start time, duration and end time). The remaining variables in B are set as not present.

Element The element constraint c = Element(a, B) is designed to select an element c from the array B on the basis of the decisional variable a used as index of the array. This constraint simply select the a element from the array Bbut this selection is done at solving time, this means that a changes during the search phase of the solving engine and the variable a can be connected to other constraints. The element is then returned to c.