## 5.352. sliding_time_window

Origin

N. Beldiceanu

Constraint

$\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}\left(\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴},\mathrm{𝙻𝙸𝙼𝙸𝚃},\mathrm{𝚃𝙰𝚂𝙺𝚂}\right)$

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

For any time window of size $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$, the intersection of all the tasks of the collection $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ with this time window is less than or equal to a given limit $\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

Example
$\left(\begin{array}{c}9,6,〈\begin{array}{cc}\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-10\hfill & \mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-3,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-5\hfill & \mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-1,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-6\hfill & \mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-2,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-14\hfill & \mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-2,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-2\hfill & \mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}-2\hfill \end{array}〉\hfill \end{array}\right)$

The lower part of Figure 5.352.1 indicates the different tasks on the time axis. Each task is drawn as a rectangle with its corresponding identifier in the middle. Finally the upper part of Figure 5.352.1 shows the different time windows and the respective contribution of the tasks in these time windows. Note that we only need to focus on those time windows starting at the start of one of the tasks. A line with two arrows depicts each time window. The two arrows indicate the start and the end of the time window. At the left of each time window we give its occupation. Since this occupation is always less than or equal to the limit 6, the $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}$ constraint holds.

##### Figure 5.352.1. Time windows and their use for the five tasks of the Example slot Typical
 $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}>1$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}>0$ $\mathrm{𝙻𝙸𝙼𝙸𝚃}<$$\mathrm{𝚜𝚞𝚖}$$\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}\right)$ $|\mathrm{𝚃𝙰𝚂𝙺𝚂}|>1$ $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}>0$
Symmetries
• $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$ can be decreased.

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

• Items of $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ are permutable.

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

• $\mathrm{𝚃𝙰𝚂𝙺𝚂}.\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}$ can be decreased to any value $\ge 0$.

Arg. properties

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

Usage

The $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}$ constraint is useful for timetabling problems in order to put an upper limit on the total work over sliding time windows.

Reformulation

The $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}$ constraint can be expressed in term of a set of ${|\mathrm{𝚃𝙰𝚂𝙺𝚂}|}^{2}$ reified constraints and of $|\mathrm{𝚃𝙰𝚂𝙺𝚂}|$ linear inequalities constraints:

1. For each pair of tasks $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right],\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ $\left(i,j\in \left[1,|\mathrm{𝚃𝙰𝚂𝙺𝚂}|\right]\right)$ of the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection we create a variable ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{ij}$ which is set to the intersection of $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ with the time window ${𝒲}_{i}$ of size $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$ that starts at instant $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$:

• If $i=j$ (i.e., $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right]$ and $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ coincide):

• ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{ij}=min\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗},\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}\right)$.

• If $i\ne j$ and $\overline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}}+\overline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}}<\underline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}}$ (i.e., $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ for sure ends before the time window ${𝒲}_{i}$):

• ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{ij}=0$.

• If $i\ne j$ and $\underline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}}>\overline{\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}}+\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}-1$ (i.e., $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ for sure starts after the time window ${𝒲}_{i}$):

• ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{ij}=0$.

• Otherwise (i.e., $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ can potentially overlap the time window ${𝒲}_{i}$):

• ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{ij}=max\left(0,min\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}+\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴},\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}+\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗}\right)-max\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗},\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\right)\right)$.

2. For each task $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right]$ $\left(i\in \left[1,|\mathrm{𝚃𝙰𝚂𝙺𝚂}|\right]\right)$ we create a linear inequality constraint ${\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{i1}+{\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{i2}+\cdots +{\mathrm{𝐼𝑛𝑡𝑒𝑟}}_{i|\mathrm{𝚃𝙰𝚂𝙺𝚂}|}\le \mathrm{𝙻𝙸𝙼𝙸𝚃}$.

related: $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}_\mathrm{𝚜𝚞𝚖}$ (sum of intersections of tasks with sliding time window replaced by sum of the points of intersecting tasks with sliding time window).

Keywords
Arc input(s)

$\mathrm{𝚃𝙰𝚂𝙺𝚂}$

Arc generator
$\mathrm{𝐶𝐿𝐼𝑄𝑈𝐸}$$↦\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1},\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}\right)$

Arc arity
Arc constraint(s)
 $•\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\le \mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$ $•\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{2}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-\mathrm{𝚝𝚊𝚜𝚔𝚜}\mathtt{1}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}<\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$
Sets
$\mathrm{𝖲𝖴𝖢𝖢}↦\left[\mathrm{𝚜𝚘𝚞𝚛𝚌𝚎},\mathrm{𝚝𝚊𝚜𝚔𝚜}\right]$

Constraint(s) on sets
$\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}_\mathrm{𝚏𝚛𝚘𝚖}_\mathrm{𝚜𝚝𝚊𝚛𝚝}$$\left(\begin{array}{c}\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴},\hfill \\ \mathrm{𝙻𝙸𝙼𝙸𝚃},\hfill \\ \mathrm{𝚝𝚊𝚜𝚔𝚜},\hfill \\ \mathrm{𝚜𝚘𝚞𝚛𝚌𝚎}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\hfill \end{array}\right)$
Graph model

We generate an arc from a task ${t}_{1}$ to a task ${t}_{2}$ if task ${t}_{2}$ does not start before task ${t}_{1}$ and if task ${t}_{2}$ intersects the time window that starts at the origin of task ${t}_{1}$. Each set generated by $\mathrm{𝖲𝖴𝖢𝖢}$ corresponds to all tasks that intersect in time the time window that starts at the origin of a given task.

Parts (A) and (B) of Figure 5.352.2 respectively show the initial and final graph associated with the Example slot. In the final graph, the successors of a given task $t$ correspond to the set of tasks that do not start before task $t$ and intersect the time window that starts at the origin of task $t$.

##### Figure 5.352.2. Initial and final graph of the $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}$ constraint  (a) (b)