## 4 The Algorithms
### The DSR-Fle Variant Algorithm
#### 4.2.1 Problem Formulation  
We use an integer programming (IP) to formulate the DSR-Fle problem where each order \(r_{j}\) has flexible drop-off time windows \([t_{j}^{\epsilon},\ t_{j}^{l}]\). The following decision variables are necessary:  
* \(x_{ij}\in\{0,1\}\), set to \(1\) if order \(r_{j}\) is served by the courier \(a_{i}\) as a first order;
* \(y_{kj}\in\{0,1\}\), set to \(1\) if order \(r_{j}\) is served immediately after \(r_{k}\);
* \(z_{j}\in\{0,1\}\), set to \(1\) if order \(r_{j}\) is served by a courier;
* \(\theta_{j}\in[t_{j}^{\epsilon},\ t_{j}^{l}]\), the drop-off period of order \(r_{j}\). Figure 2: An illustration on how CSN works. (**a**) The directed edge \((r_{j},\ r_{k})\) indicates that the order \(r_{k}\) can be finished immediately after \(r_{j}\); (**b**) the Hopcroft–Karp maximum-matching (red arrows); (**c**) the optimal delivery plans \(r_{1}\to r_{4}\) and \(r_{2}\to r_{3}\to r_{5}\). The following IP can be used to formulate the DSR-Fle. \[\max\sum_{\tau_{j}\in R}\sum_{a_{i}\in\mathcal{A}}x_{ij}+\sum_{\tau_ {k},\tau_{j}\in R}y_{kj} \tag{1}\] \[z_{j}=\sum_{a_{i}\in\mathcal{A}}x_{ij}+\sum_{\tau_{k}}y_{kj},\forall r _{j},\] (2) \[\sum_{\tau_{j}\in R}y_{kj}\leq z_{k},\forall r_{k},\] (3) \[\sum_{r_{j}\in R}x_{ij}\leq 1,\forall a_{i}, \tag{4}\]  
\[\left\{ \begin{array}{l}t_{j}^{e}\leq\theta_{j}\leq t_{j}^{l},\forall r_{j}, \\ \theta_{j}-\theta_{k}\geq\left(t_{j}^{e}-t_{k}^{l}\right)+(\tau_{kj}-(t_{j}^{e }-t_{k}^{l}))y_{kj},\forall r_{j},r_{k},\\ \theta_{j}\geq t_{j}^{e}+(\tau_{ij}-t_{j}^{e})x_{ij},\forall a_{i},r_{j}.\end{array} \right. \tag{5}\]  
Equation (1) is the object of maximizing the number of orders served. Constraint (2) ensures that the order \(r_{j}\) is served (i.e., \(z_{j}=1\)) if and only if a courier \(a_{i}\) serves him as the first customer order (i.e., \(x_{ij}=1\)) or after another order \(r_{k}\) (i.e., \(y_{kj}=1\)). Constraint (3) ensures that the order \(r_{j}\) that can be served after the order \(r_{k}\) iff \(r_{k}\) is served (_i.e., \(z_{k}=1\)_). Constraint (4) ensures that each courier can only serve one request as the first customer order. Finally, we enforce the drop-off time window constraints in Constraint (5): the first constraint ensures that the drop-off period \(\theta_{j}\) must lie in the window \([t_{j}^{e},\ t_{j}^{l}]\); the second constraint ensures that \(r_{j}\) can be served immediately after \(r_{k}\) iff there are long enough periods between \(\theta_{j}\) and \(\theta_{k}\) such that the courier can travel from the drop-off region of \(r_{k}\) to the pickup region of \(r_{j}\) and deliver \(r_{j}\) to its drop-off region, the third constraint ensures that the courier \(a_{i}\) can serve the order \(r_{j}\) as the first order iff there are long enough periods for \(a_{i}\) to travel from his region to the pickup and drop-off regions of \(r_{j}\) and \(\tau_{ij}=d_{v_{a_{i}}v_{j}^{p}}+d_{v_{j}^{p}v_{j}^{d}}\), \(\forall a_{i},r_{j}\), where \(v_{a_{i}}\) indicates the region where \(a_{i}\) starts from. The DSR-Fle problem is NP-hard. We show a reduction from the three-dimensional perfect matching problem (3 DM), which is known to be NP-hard [27]. Recall that 3 DM is as follows: given three finite and disjoint sets \(I\), \(J\) and \(K\), each of size \(n\), and a subset \(T\subseteq I\times J\times K\) with size \(m\geq n\) (i.e., \(T\) consists of triples \((i,j,k)\) such that \(i\in I\), \(j\in J\), and \(k\in K\)), the 3 DM problem asks if there exists a perfect matching with a subset \(M\subseteq T\) with \(n\) triples, such that every element in \(I\cup J\cup K\) occurs in exactly one triple of \(M\). For any 3 DM instance, \(\mathcal{I}=\langle I,J,K,T\rangle\). We construct a corresponding DSR-Fle instance as follows: for each element \(i\in I\), we create an order \(r_{i}\) with the fixed drop-off window \(t_{i}\). For each element \(j\in J\), we create an order \(r_{j}\), and, for each tuple \((\cdot,j,\cdot)\in T\), we create an available drop-off time \(t(\cdot,j,\cdot)\) for \(r_{j}\).