## 5.198. interval_and_sum

Origin
Constraint

$\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}\left(\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},\mathrm{𝚃𝙰𝚂𝙺𝚂},\mathrm{𝙻𝙸𝙼𝙸𝚃}\right)$

Arguments
 $\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}$ $\mathrm{𝚒𝚗𝚝}$ $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ $\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathrm{𝚍𝚟𝚊𝚛},\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-\mathrm{𝚍𝚟𝚊𝚛}\right)$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}$ $\mathrm{𝚒𝚗𝚝}$
Restrictions
 $\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}>0$ $\mathrm{𝚛𝚎𝚚𝚞𝚒𝚛𝚎𝚍}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂},\left[\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗},\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\right]\right)$ $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\ge 0$ $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\ge 0$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}\ge 0$
Purpose

A maximum resource capacity constraint: We have to fix the origins of a collection of tasks in such a way that, for all the tasks that are allocated to the same interval, the sum of the heights does not exceed a given capacity. All the intervals we consider have the following form: $\left[k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1\right]$, where $k$ is an integer.

Example
$\left(\begin{array}{c}5,〈\begin{array}{cc}\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-1\hfill & \mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-2,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-10\hfill & \mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-2,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-10\hfill & \mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-3,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-4\hfill & \mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}-1\hfill \end{array}〉,5\hfill \end{array}\right)$

Figure 5.198.1 shows the solution associated with the example. The constraint $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$ holds since the sum of the heights of the tasks that are located in the same interval does not exceed the limit 5. Each task $t$ is depicted by a rectangle $r$ associated with the interval to which the task $t$ is assigned. The rectangle $r$ is labelled with the position of $t$ within the items of the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection. The origin of task $t$ is represented by a small black square located within its corresponding rectangle $r$. Finally, the height of a rectangle $r$ is equal to the height of the task $t$ to which it corresponds.

##### Figure 5.198.1. The $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$ solution to the Example slot with the use of each interval Typical
 $\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}>1$ $|\mathrm{𝚃𝙰𝚂𝙺𝚂}|>1$ $\mathrm{𝚛𝚊𝚗𝚐𝚎}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\right)>1$ $\mathrm{𝚛𝚊𝚗𝚐𝚎}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\right)>1$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}<$$\mathrm{𝚜𝚞𝚖}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\right)$
Symmetries
• Items of $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ are permutable.

• One and the same constant can be added to the $\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$ attribute of all items of $\mathrm{𝚃𝙰𝚂𝙺𝚂}$.

• An occurrence of a value of $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$ that belongs to the $k$-th interval, of size $\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}$, can be replaced by any other value of the same interval.

• $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}$ can be decreased to any value $\ge 0$.

• $\mathrm{𝙻𝙸𝙼𝙸𝚃}$ can be increased.

Arg. properties

Contractible wrt. $\mathrm{𝚃𝙰𝚂𝙺𝚂}$.

Usage

This constraint can be use for timetabling problems. In this context the different intervals are interpreted as morning and afternoon periods of different consecutive days. We have a capacity constraint for all tasks that are assigned to the same morning or afternoon of a given day.

Reformulation

Let $K$ denote the index of the last possible interval where the tasks can be assigned: $K=⌊\frac{{max}_{i\in \left[1,|\mathrm{𝚃𝙰𝚂𝙺𝚂}|\right]}\left(\overline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}}\right)+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1}{\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}}⌋$. The $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$$\left(\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},\mathrm{𝚃𝙰𝚂𝙺𝚂},\mathrm{𝙻𝙸𝙼𝙸𝚃}\right)$ constraint can be expressed in term of a set of reified constraints and of $K$ arithmetic constraints (i.e., $\mathrm{𝚜𝚌𝚊𝚕𝚊𝚛}_\mathrm{𝚙𝚛𝚘𝚍𝚞𝚌𝚝}$ constraints).

1. For each task $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right]$ $\left(i\in \left[1,|\mathrm{𝚃𝙰𝚂𝙺𝚂}|\right]\right)$ and for each interval $\left[k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1\right]$ $\left(k\in \left[0,K\right]\right)$ we create a 0-1 variable ${B}_{ik}$ that will be set to 1 if and only if the origin of task $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right]$ is assigned within interval $\left[k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1\right]$:

${B}_{ik}⇔\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\ge k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}\wedge$

$\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\le k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1$

2. Finally, for each interval $\left[k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻},k·\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}+\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}-1\right]$ $\left(k\in \left[0,K\right]\right)$, we impose the sum $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[1\right].\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}·{B}_{1k}+\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[2\right].\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}·{B}_{2k}+\cdots +\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[|\mathrm{𝚃𝙰𝚂𝙺𝚂}|\right].\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}·{B}_{|\mathrm{𝚃𝙰𝚂𝙺𝚂}|k}$ to not exceed the maximum allowed capacity $\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

assignment dimension removed: $\mathrm{𝚜𝚞𝚖}_\mathrm{𝚌𝚝𝚛}$ (assignment dimension corresponding to intervals is removed).

Keywords
Arc input(s)

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

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

Arc arity
Arc constraint(s)
$\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}/\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}=\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}/\mathrm{𝚂𝙸𝚉𝙴}_\mathrm{𝙸𝙽𝚃𝙴𝚁𝚅𝙰𝙻}$
Sets
$\begin{array}{c}\mathrm{𝖲𝖴𝖢𝖢}↦\hfill \\ \left[\begin{array}{c}\mathrm{𝚜𝚘𝚞𝚛𝚌𝚎},\hfill \\ \mathrm{𝚟𝚊𝚛𝚒𝚊𝚋𝚕𝚎𝚜}-\mathrm{𝚌𝚘𝚕}\left(\begin{array}{c}\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}-\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚍𝚟𝚊𝚛}\right),\hfill \\ \mathrm{𝚒𝚝𝚎𝚖}\left(\mathrm{𝚟𝚊𝚛}-\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}\right)\right]\hfill \end{array}\right)\hfill \end{array}\right]\hfill \end{array}$

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

We use a bipartite graph where each class of vertices corresponds to the different tasks of the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection. There is an arc between two tasks if their origins belong to the same interval. Finally we enforce a $\mathrm{𝚜𝚞𝚖}_\mathrm{𝚌𝚝𝚛}$ constraint on each set $𝒮$ of successors of the different vertices of the final graph. This put a restriction on the maximum value of the sum of the $\mathrm{𝚑𝚎𝚒𝚐𝚑𝚝}$ attributes of the tasks of $𝒮$.

Parts (A) and (B) of Figure 5.198.2 respectively show the initial and final graph associated with the Example slot. Each connected component of the final graph corresponds to items that are all assigned to the same interval.

##### Figure 5.198.2. Initial and final graph of the $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$ constraint  (a) (b)
Automaton

Figure 5.198.3 depicts the automaton associated with the $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$ constraint. To each item of the collection $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ corresponds a signature variable ${S}_{i}$ that is equal to 1.

##### Figure 5.198.3. Automaton of the $\mathrm{𝚒𝚗𝚝𝚎𝚛𝚟𝚊𝚕}_\mathrm{𝚊𝚗𝚍}_\mathrm{𝚜𝚞𝚖}$ constraint 