I am trying to solve an optimization problem in which there is a set of tasks, $S$, where $s_i$ and $e_i$ are the starting and ending time of task $i \in S$. Each task $i $ must be done within its own time window $[a_i, b_i]$: \begin{equation} a_i \le s_i, \forall i \in S \end{equation} \begin{equation} e_i \le b_i, \forall i \in S \end{equation}
I would like to compute the time between all the pairs of tasks. That is, $s_j-e_i$ (if $i$ is scheduled before $j$) or $s_i-e_j$ (if $j$ is scheduled before $i$).
The objective is to minimize the times between all the pairs of tasks. How can I define it?