### 2.3.3.2. Dynamic graph constraint

The purpose of a dynamic graph constraint is to enforce a condition on different subsets of variables, not known in advance. This situation occurs frequently in practice and is hard to express since one cannot use a classical constraint for which it is required to provide all variables right from the beginning. One good example of such global constraint is the $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ constraint where one wants to force the sum of some variables to be less than or equal to a given limit. In the context of the $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ constraint, each set of variables is defined by the height of the different tasks that overlap a given instant $i$. Since the origins of the tasks are not initially fixed, we do not know in advance which task will overlap a given instant and so, we cannot state any sum constraint initially.

A dynamic graph constraint is defined in exactly the same way as a simple graph constraint, except that we may omit the Graph property(ies) slot, and that we have to provide the two following additional slots:

• The Set slot denotes a generator of sets of vertices. Such a generator takes as argument a final graph and produces different sets of vertices. In order to have something tractable, we force the total number of generated sets to be polynomial in the number of vertices.

In practice each set of vertices is represented by a collection of items. The type of this collection corresponds either to the type of the items associated with the vertices, or to the type of a new derived collection. This is achieved by providing an expression of the form $\mathrm{𝚗𝚊𝚖𝚎}$ or $\mathrm{𝚗𝚊𝚖𝚎}$-$\mathrm{𝚍𝚎𝚛𝚒𝚟𝚎𝚍}_\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}$, where $\mathrm{𝚗𝚊𝚖𝚎}$ represents a formal parameter, and $\mathrm{𝚍𝚎𝚛𝚒𝚟𝚎𝚍}_\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}$ a declaration of a new derived collection (as specified in Section 2.3.2.1 on page 2.3.2.1).

• The Constraint(s) on sets slot provides a global constraint defined in the catalogue that has to hold for each set created by the previous generator.

We now describe the different generators of sets of vertices currently available:

• $\mathrm{𝖠𝖫𝖫}_\mathrm{𝖵𝖤𝖱𝖳𝖨𝖢𝖤𝖲}$ generates a single set containing all the vertices of the final graph. It is specified by a declaration of the form

$\mathrm{𝖠𝖫𝖫}_\mathrm{𝖵𝖤𝖱𝖳𝖨𝖢𝖤𝖲}>>\left[\mathrm{𝚟𝚎𝚛𝚝𝚒𝚌𝚎𝚜}\right]$

where $\mathrm{𝚟𝚎𝚛𝚝𝚒𝚌𝚎𝚜}$ represents all the vertices of the final graph.

• $\mathrm{𝖢𝖢}$ generates one set of vertices for each connected component of the final graph. These sets correspond to all the vertices of a given connected component. It is specified by a declaration of the form

$\mathrm{𝖢𝖢}>>\left[\mathrm{𝚌𝚘𝚗𝚗𝚎𝚌𝚝𝚎𝚍}_\mathrm{𝚌𝚘𝚖𝚙𝚘𝚗𝚎𝚗𝚝}\right]$

where $\mathrm{𝚌𝚘𝚗𝚗𝚎𝚌𝚝𝚎𝚍}_\mathrm{𝚌𝚘𝚖𝚙𝚘𝚗𝚎𝚗𝚝}$ represents the vertices of a connected component of the final graph.

• $\mathrm{𝖯𝖠𝖳𝖧}_\mathrm{𝖫𝖤𝖭𝖦𝖳𝖧}\left(L\right)$ generates all elementary pathsA path where all vertices are distinct is called an elementary path. of $L$ vertices of the final graph such that, discarding loops, all vertices of a path (except the last one) have no more than one successor in the final graph. It is specified by a declaration of the form

$\mathrm{𝖯𝖠𝖳𝖧}_\mathrm{𝖫𝖤𝖭𝖦𝖳𝖧}\left(L\right)>>\left[\mathrm{𝚙𝚊𝚝𝚑}\right]$

where $\mathrm{𝚙𝚊𝚝𝚑}$ represents the vertices of an elementary path, ordered according to their occurrences in the path.

• $\mathrm{𝖯𝖱𝖤𝖣}$ generates the non-empty sets corresponding to the predecessors of each vertex of the final graph. It is specified by a declaration of the form

$\mathrm{𝖯𝖱𝖤𝖣}>>\left[\mathrm{𝚙𝚛𝚎𝚍𝚎𝚌𝚎𝚜𝚜𝚘𝚛},\mathrm{𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗}\right]$

where $\mathrm{𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗}$ represents a vertex of the final graph and $\mathrm{𝚙𝚛𝚎𝚍𝚎𝚌𝚎𝚜𝚜𝚘𝚛}$ its predecessors.

• $\mathrm{𝖲𝖴𝖢𝖢}$ generates the non-empty sets corresponding to the successors of each vertex of the final graph. It is specified by a declaration of the form

$\mathrm{𝖲𝖴𝖢𝖢}>>\left[\mathrm{𝚜𝚘𝚞𝚛𝚌𝚎},\mathrm{𝚜𝚞𝚌𝚌𝚎𝚜𝚜𝚘𝚛}\right]$

where $\mathrm{𝚜𝚘𝚞𝚛𝚌𝚎}$ represents a vertex of the final graph and $\mathrm{𝚜𝚞𝚌𝚌𝚎𝚜𝚜𝚘𝚛}$ its successors.

As an illustrative example of dynamic graph constraint we now consider the $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ constraint.

EXAMPLE: The $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂},\mathrm{𝙻𝙸𝙼𝙸𝚃}\right)$ constraint, where $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ is a collection of the form $\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathrm{𝚍𝚟𝚊𝚛},\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathrm{𝚍𝚟𝚊𝚛},\mathrm{𝚎𝚗𝚍}-\mathrm{𝚍𝚟𝚊𝚛},$ $\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathrm{𝚍𝚟𝚊𝚛}\right)$, and where $\mathrm{𝙻𝙸𝙼𝙸𝚃}$ is a non-negative integer, holds if, for any point the cumulated height of the set of tasks that overlap that point, does not exceed $\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

The first graph constraint of $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ forces for each task of the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection the equality $\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}+\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}=\mathrm{𝚎𝚗𝚍}$. We focus on the second graph constraint, which uses a dynamic graph constraint described by the following items:

Arc input(s)       :

$\mathrm{𝚃𝙰𝚂𝙺𝚂}\mathrm{𝚃𝙰𝚂𝙺𝚂}$

Arc generator     :

$\mathrm{𝑃𝑅𝑂𝐷𝑈𝐶𝑇}↦\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1},\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}\right)$

Arc arity          :

2

Arc constraint(s)   :

$\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}>\mathtt{0}$

$\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\le \mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$

$\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\le \mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}.\mathrm{𝚎𝚗𝚍}$

Sets              :

$\mathrm{𝖲𝖴𝖢𝖢}>>$

$\left[\mathrm{𝚜𝚘𝚞𝚛𝚌𝚎},$

$\mathrm{𝚟𝚊𝚛𝚒𝚊𝚋𝚕𝚎𝚜}-\mathrm{𝚌𝚘𝚕}\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}-\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚍𝚟𝚊𝚛}\right),$

$\left[\mathrm{𝚒𝚝𝚎𝚖}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\right)\right]\right)\right]$

Constraint(s) on sets:

$\mathrm{𝚜𝚞𝚖}_\mathrm{𝚌𝚝𝚛}$$\left(\mathrm{𝚟𝚊𝚛𝚒𝚊𝚋𝚕𝚎𝚜},\le ,\mathrm{𝙻𝙸𝙼𝙸𝚃}\right)$

The second graph constraint is defined by:

• To each item of the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection correspond two vertices of the initial graph.

• The arity of the arc constraint is 2.

• The arcs of the initial graph are constructed with the $\mathrm{𝑃𝑅𝑂𝐷𝑈𝐶𝑇}$ arc generator between the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection and the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection. Therefore, each vertex associated with a task is linked to all the vertices related to the different tasks.

• The arc constraint that is associated with an arc between a task $\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}$ and a task $\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}$ is an overlapping constraint that holds if both, the duration of $\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}$ is strictly greater than zero, and if the origin of $\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}$ is overlapped by task $\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}$.

• The set generator is $\mathrm{𝖲𝖴𝖢𝖢}$. The final graph will consist of those tasks for which the origin is covered by at least one task and of those corresponding tasks.

• The dynamic constraint on a set forces the sum of the heights of the tasks that belong to a successor set to not exceed $\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

##### Figure 2.3.6. Initial and final graph of an instance of the $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ constraint Parts (A) and (B) of Figure 2.3.6 respectively show the initial and the final graph corresponding to the following instance:

$\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$$\left(〈\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathtt{1}\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathtt{3}\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathtt{1},$

$\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathtt{2}\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathtt{9}\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathtt{2},$

$\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathtt{3}\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathtt{10}\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathtt{1},$

$\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathtt{6}\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathtt{6}\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathtt{1},$

$\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathtt{7}\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-\mathtt{2}\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathtt{3}〉,\mathtt{8}\right).$

We label the vertices of the initial and final graph by giving the $\mathrm{𝚔𝚎𝚢}$$\mathrm{𝚔𝚎𝚢}$ is an implicit attribute corresponding to the position of an item within a collection that was introduced in Section 2.2.2 on page 2.2.2. of the corresponding task. On both graphs the edges are oriented from left to right. On the final graph we consider the sets that consist of the successors of the different vertices; those are the sets of tasks $\left\{1\right\}$, $\left\{1,2\right\}$, $\left\{1,2,3\right\}$, $\left\{2,3,4\right\}$ and $\left\{2,3,4,5\right\}$. Since the $\mathrm{𝖲𝖴𝖢𝖢}$ set generator uses a derived collection that only considers the $\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}$ attribute of a task, these sets respectively correspond to the following collection of items:

• $〈\mathrm{𝚟𝚊𝚛}-\mathtt{1}〉$,

• $〈\mathrm{𝚟𝚊𝚛}-\mathtt{1},\mathrm{𝚟𝚊𝚛}-\mathtt{2}〉$,

• $〈\mathrm{𝚟𝚊𝚛}-\mathtt{1},\mathrm{𝚟𝚊𝚛}-\mathtt{2},\mathrm{𝚟𝚊𝚛}-\mathtt{1}〉$,

• $〈\mathrm{𝚟𝚊𝚛}-\mathtt{2},\mathrm{𝚟𝚊𝚛}-\mathtt{1},\mathrm{𝚟𝚊𝚛}-\mathtt{1}〉$,

• $〈\mathrm{𝚟𝚊𝚛}-\mathtt{2},\mathrm{𝚟𝚊𝚛}-\mathtt{1},\mathrm{𝚟𝚊𝚛}-\mathtt{1},\mathrm{𝚟𝚊𝚛}-\mathtt{3}〉$.

The $\mathrm{𝚌𝚞𝚖𝚞𝚕𝚊𝚝𝚒𝚟𝚎}$ constraint holds since, for each successors set, the corresponding constraint holds:

The $\mathrm{𝚜𝚞𝚖}_\mathrm{𝚌𝚝𝚛}$$\left(\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂},\mathrm{𝙲𝚃𝚁},\mathrm{𝚅𝙰𝚁}\right)$ constraint holds if the sum $𝚂$ of the variables of the $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}$ collection satisfies $𝚂\mathrm{𝙲𝚃𝚁}\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}$, where $\mathrm{𝙲𝚃𝚁}$ is a comparison operator.