## 5.297. sliding_time_window_sum

 DESCRIPTION LINKS GRAPH
Origin
Constraint

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

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

For any time window of size $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$, the sum of the points of the tasks of the collection $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ that overlap that time window do not exceed a given limit $\mathrm{𝙻𝙸𝙼𝙸𝚃}$.

Example
$\left(\begin{array}{c}9,16,〈\begin{array}{ccc}\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-10\hfill & \mathrm{𝚎𝚗𝚍}-13\hfill & \mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}-2,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-5\hfill & \mathrm{𝚎𝚗𝚍}-6\hfill & \mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}-3,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-6\hfill & \mathrm{𝚎𝚗𝚍}-8\hfill & \mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}-4,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-14\hfill & \mathrm{𝚎𝚗𝚍}-16\hfill & \mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}-5,\hfill \\ \mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}-2\hfill & \mathrm{𝚎𝚗𝚍}-4\hfill & \mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}-6\hfill \end{array}〉\hfill \end{array}\right)$

The lower part of Figure 5.297.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.297.1 shows the different time windows and the respective contribution of the tasks in these time windows. A line with two arrows depicts each time window. The two arrows indicate the start and the end of the time window. At the right of each time window we give its occupation. Since this occupation is always less than or equal to the limit 16, the $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}_\mathrm{𝚜𝚞𝚖}$ constraint holds.

##### Figure 5.297.1. Time windows of the $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\mathrm{𝚝𝚒𝚖𝚎}_\mathrm{𝚠𝚒𝚗𝚍𝚘𝚠}_\mathrm{𝚜𝚞𝚖}$ constraint Symmetries
• $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$ can be decreased.

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

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

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

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

Usage

This constraint may be used for timetabling problems in order to put an upper limit on the cumulated number of points in a shift.

Reformulation

The $\mathrm{𝚜𝚕𝚒𝚍𝚒𝚗𝚐}_\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 $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}$ if $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right]$ intersects the time window ${𝒲}_{i}$ of size $\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴}$ that starts at instant $\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}$, or 0 otherwise:

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

• ${\mathrm{𝑃𝑜𝑖𝑛𝑡}}_{ij}=\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}$.

• If $i\ne j$ and $\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}=min\left(1,max\left(0,min\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}+\mathrm{𝚆𝙸𝙽𝙳𝙾𝚆}_\mathrm{𝚂𝙸𝚉𝙴},\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚎𝚗𝚍}\right)-max\left(\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[i\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗},\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\right)\right)\right)·\mathrm{𝚃𝙰𝚂𝙺𝚂}\left[j\right].\mathrm{𝚗𝚙𝚘𝚒𝚗𝚝}$.

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}+...+{\mathrm{𝑃𝑜𝑖𝑛𝑡}}_{i|\mathrm{𝚃𝙰𝚂𝙺𝚂}|}\le \mathrm{𝙻𝙸𝙼𝙸𝚃}$.

See also

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

Keywords
Arc input(s)

$\mathrm{𝚃𝙰𝚂𝙺𝚂}$

Arc generator
$\mathrm{𝑆𝐸𝐿𝐹}$$↦\mathrm{𝚌𝚘𝚕𝚕𝚎𝚌𝚝𝚒𝚘𝚗}\left(\mathrm{𝚝𝚊𝚜𝚔𝚜}\right)$

Arc arity
Arc constraint(s)
$\mathrm{𝚝𝚊𝚜𝚔𝚜}.\mathrm{𝚘𝚛𝚒𝚐𝚒𝚗}\le \mathrm{𝚝𝚊𝚜𝚔𝚜}.\mathrm{𝚎𝚗𝚍}$
Graph property(ies)
$\mathrm{𝐍𝐀𝐑𝐂}$$=|\mathrm{𝚃𝙰𝚂𝙺𝚂}|$

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{𝚂𝙸𝚉𝙴}-1$
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 generate an arc from a task ${t}_{1}$ to a task ${t}_{2}$ if task ${t}_{2}$ does not end before the end of task ${t}_{1}$ and if task ${t}_{2}$ intersects the time window that starts at the last instant of task ${t}_{1}$. Each set generated by $\mathrm{𝖲𝖴𝖢𝖢}$ corresponds to all tasks that intersect in time the time window that starts at instant $\mathrm{𝚎𝚗𝚍}-1$, where $\mathrm{𝚎𝚗𝚍}$ is the end of a given task.

Parts (A) and (B) of Figure 5.297.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 both do not end before the $\mathrm{𝚎𝚗𝚍}$ of task $t$, and intersect the time window that starts at the $\mathrm{𝚎𝚗𝚍}-1$ of task $t$.

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

Consider the first graph constraint. Since we use the $\mathrm{𝑆𝐸𝐿𝐹}$ arc generator on the $\mathrm{𝚃𝙰𝚂𝙺𝚂}$ collection the maximum number of arcs of the final graph is equal to $|\mathrm{𝚃𝙰𝚂𝙺𝚂}|$. Therefore we can rewrite $\mathrm{𝐍𝐀𝐑𝐂}=|\mathrm{𝚃𝙰𝚂𝙺𝚂}|$ to $\mathrm{𝐍𝐀𝐑𝐂}\ge |\mathrm{𝚃𝙰𝚂𝙺𝚂}|$ and simplify $\underline{\overline{\mathrm{𝐍𝐀𝐑𝐂}}}$ to $\overline{\mathrm{𝐍𝐀𝐑𝐂}}$.