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]$$: $$$$a_i \le s_i, \forall i \in S$$$$ $$$$e_i \le b_i, \forall i \in S$$$$

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?

• Do you have a single resource or multiple ones? Is there any relationship between the tasks? Nov 15, 2023 at 11:41
• Only one resource is considered. Furthermore, tasks are independent. Nov 17, 2023 at 16:35

What you could do is the following: Introduce variable $$t_{ij}$$ that is the time between tasks $$i$$ and $$j$$. This variable is only defined for once per pair $$ij$$, therefore the $$j >i$$. Then, you can write:
\begin{align} \ & \min \sum_{i \in S}\sum_{j \in S, j>i} t_{ij} \; \\ \end{align}
\begin{align} & s_j - e_i \leq t_{ij} & \forall i,j \in S, j>i \tag1 \\ & s_i - e_j \leq t_{ij} & \forall i,j \in S, j>i \tag2 \\ \end{align}