In this analysis, three models were used to achieve global optimization of the problem. In the first, a modified version of the Dijkstra algorithm was used for the clustering problem. The second model was the wellknown traveling agent algorithm for calculating the transport paths in each section of the network. Finally, the third model is an instance of mixed integer linear programming for the selection of transport to be purchased. Below is the corresponding development of each model.
The Dijkstra modified algorithm to evaluate the clustering process
The first step in solving this problem was to create a clustering process that would group the nodes associated with each cluster. The selection of the integrating nodes should satisfy the time requirement of traversing the network must be less than or equal to the time window of the last node of the route. That is, the distance traveled from the DC to the cluster (route X) plus the distance traveled inside the nodes that make up the cluster (route Y) in any configuration, must be less than or equal to the time window of said cluster. In this sense, the cluster travel configurations can be in radial form and/or in peripheral. In the peripheral configuration the clinics are visited only once, one after the other following the sequence recommended by the traveling salesman algorithm. In the radial configuration, the transport leaves the shovel node, visits the selected clinic and returns to the shovel node again. This process is repeated until covering all the clinics of the cluster, Fig. 2. Naturally, the peripheral path consumes less time and/or distance, so this document only reports the result with this topology. Incredibly, The company cause of interest of this study uses both configurations.
For the clustering process the following algorithm was used.
Algorithm 1
(Modified Dijkstra algorithm)
To use this algorithm it will be assumed that it is known the time t required to travel the distance d using route r. The algorithm is as follows.
For each cluster path r:

1.
Build a cluster \(\mathfrak{C}\) by selecting a set of nearby nodes (clinics) at random.

2.
For each node \(n \in \mathfrak{C}\) evaluate the time required to traverse the distance from the CD to this. The candidate node \(n_{p}\) (pivot node) will be that whose travel time is minimum, i.e.
$$ t_{p} = \min \bigl\{ t ( \mathit{CD}, n_{s} ) , \forall n_{s} \in \mathfrak{C} \bigr\} , $$
(1)
where \(t ( a,b ) \) means the traverse time from a to b.

3.
Select the first normal node \(n_{1}\) in the cluster as the one to which it is raised in the shortest possible time starting from the pivot node.
$$ t_{1} = \min \bigl\{ t ( n_{p,} n_{s} ) , \forall n_{s} \in \mathfrak{C} \bigr\} . $$
(2)

4.
Select the rest of the nodes that make up the cluster by alternately adding the neighboring nodes that imply a minimum travel time from the previous nodes
$$ t_{j} = \min \bigl\{ t ( n_{j1,} n_{s} ) , \forall n_{s} \in \mathfrak{C} \bigr\} , \quad j=2, 3, \ldots. $$
(3)

5.
Continue the process of adding nodes alternatively in each branch of the tree while satisfying the following criteria
$$ T_{t} = \min \Biggl\{ ( t_{p} + t_{1} ) + \sum _{j=2}^{ \Omega } t_{j} \leq T_{wc} \Biggr\} . $$
(4)

6.
Select the group with the shortest time \(T_{t}\).
Equation (4) ensures that the time allocated to the cluster path starting from the DC satisfies the time window assigned to it. Here, \(T_{wc}\) is the time window (in days) associated to the cluster \(\mathfrak{C}\), and \(\theta = \Omega +2\) is the final number of nodes included in this (Fig. 3).
Note that Algorithm 1 can be conveniently modified to evaluate distance rather than time by substituting d instead t, \(D_{t}\) instead \(T_{t}\), \(D_{w}\) (distance traveled within of \(T_{w}\)) instead \(T_{w}\), and modifying the meaning of the equation \(t(a,b)\) by \(d(a,b)\) which now means the distance.
The process of routing within clusters
The next step to solve the problem is to define the path that the transports should follow from the transfer node to the rest of the cluster nodes. For this, the wellknown traveling salesman algorithm was use. Let \(\mathcal{S}\) denote a subset of the θ clinics and let S denote the number of clinics in this subset, then given a set of clinics \(\mathfrak{C}=\{ k_{1}, k_{2},\ldots, k_{\theta } \} \) that form the newly created cluster, a set of transports has to visit the θ clinics, starting and finishing in the pivot node (shovel node), with as objective to minimize the total travel time. The model and the adjustments made to it are as follows
$$ \begin{gathered} \text{Minimize }\sum_{i=1}^{\theta } \sum_{j=i+1}^{\theta } t_{ij} u_{ij} \\ \text{Subject to: } \\ \sum_{j=1}^{i1} u_{ji} \sum _{j=i+ 1}^{\theta } u_{ij} =2, \quad i=1, \ldots, \theta , \\ t_{p} + \sum_{i=1}^{\theta } \sum _{j=i+1}^{\theta } t_{ij} \leq T_{wc}, \\ \sum_{ i\in S}\sum_{ j\in K, j >i} u_{ij} \leq S, \quad \text{for every }S, S\neq \emptyset , \\ u_{ij} \in \{ 0,1 \} , \quad \text{for every }i < j, \end{gathered} $$
(5)
where the binary variable \(u_{ij}\) is equal to 1 if the route is made from the origin i to the destination j; and it is 0 otherwise. Note that for the set of classical Eqs. (5) the inequality given by \(t_{p} + \sum_{i=1}^{\theta } \sum_{j=i+ 1}^{\theta } t_{ij} \leq T_{wc}\) has been added which reinforces the time window guarantee expressed in Eq. (4).
The calculation of vehicles in the system (program MILP)
To determine the optimal quantity of vehicles to be purchased, as well as the shiploads and volumes they would carry, a mixed linear mathematical programming model was used. The strategy is to apply the following model to calculate the optimal number of transports that will circulate in each selected cluster, the program was applied in the totality of clusters. For each cluster \(\mathfrak{C}\) in the system the following set of indicators is defined: (a) For products \(\mathrm{I} =\{i:i=1,\ldots,I\}\), (b) For transport \(\mathfrak{J}=\{ j:j=1,\ldots, J\}\), (c) For clinics \(\mathrm{K} = \{ k:k=1,\ldots, K \} \).
Notation
$$\begin{aligned}& \mathit{Of}_{i} \equiv \text{Offer of the product } i \text{ (in pieces)}, \\& C_{j} \equiv \text{Cost of acquisition of transport } j \text{ (in USD)}, \\& d_{ik} \equiv \text{Demand of product } i \text{ in clinic } k \text{ (in pieces)}, \\& \begin{aligned} x_{ij} &\equiv \text{Quantity of pieces of product } i \text{ send monthly by using the transport } j \\ &\quad \text{ (in pieces)}, \end{aligned} \\& \begin{aligned} y_{ijk} &\equiv \text{Quantity of pieces of product } i \text{ send monthly by using the transport } j \\ &\quad \text{ towards node (clinic) } k \text{ (in pieces)}, \end{aligned} \\& v_{i} \equiv \text{Volume of product } i \text{ (in cubic meters)}, \\& w_{i} \equiv \text{Weight of product } i \text{ (in kilograms)}, \\& \mathcal{Q} x_{j} \equiv \text{Total amount of transport type } j \text{ to be purchased to circulate in route } X , \\& \mathcal{Q} y_{j} \equiv \text{Total amount of transport type } j \text{ to be purchased to circulate in route } Y , \\& \mathit{Stx}_{j} \equiv \text{Total shipload moved on route } X \text{ by transport } j \text{ (in kilograms)}, \\& \mathit{Sty}_{j} \equiv \text{Total shipload moved on route } Y \text{ by transport } j \text{ (in kilograms)}, \\& \mathit{Vtx}_{j} \equiv \text{Total volume moved on route } X \text{ by transport } j \text{ (in cubic meters)}, \\& \mathit{Vty}_{j} \equiv \text{Total volume moved on route } Y \text{ by transport } j \text{ (in cubic meters)}, \\& \vartheta _{j} \equiv \text{Carrying capacity of transport } j \text{ (in kilograms)}, \\& \varsigma _{j} \equiv \text{Volume capacity of transport } j \text{ (in cubic meters)}. \end{aligned}$$
The objective function
We proceed to formalize the following objective function.
$$ \text{Minimize }f ( G ) = \sum_{j\in \mathfrak{J}} C_{j} ( \mathcal{Q} x_{j} + \mathcal{Q} y_{j} ). $$
(6)
Technological constraints
Supply
In this model it will be assumed that all the medicines required are always available, that is, the supply is infinite. Likewise, all shipments are made to the selected shovel node, that is, just exists a final node.
$$ \sum_{j\in \mathfrak{J}} x_{ij}  \mathit{Of}_{i} = \infty , \quad \forall i \in \mathrm{I}. $$
(7)
Balance equations
All products entering to the shovel node must be sent to the destination clinics
$$ \sum_{j\in \mathfrak{J}} \sum_{i\in \mathrm{I}} x_{ij}  \sum_{k \in \mathrm{K}} \sum _{j\in \mathfrak{J}} \sum_{i\in \mathrm{I}} y_{ijk} = 0. $$
(8)
Demand
The most usual probability distributions to represent the demand of a product may vary according to the nature of it, the cyclicity of its sales and its distribution costs. The most usual models are: (a) exponential for a lumpy demand, (b) normal for a stochastic demand and negative values are discarded (c) uniform for a cyclical demand, [24, 25].
In this proposal we use the normal distribution.
The demand for each i product must be met at each clinic included in the cluster
$$ \sum_{j\in \mathfrak{J}} \sum_{i\in \mathrm{I}} y_{ijk}  d_{ik} = 0, \quad \forall k \in \mathrm{K}. $$
(9)
Level of customer service
This quantity is defined as the probability of delivering the quantity requested by the customer on time and with a high level of quality. To ensure that the delivered quantity satisfies a reliability level of \(( 1 \alpha ) \), \(\alpha \in (0,1)\) percent and assuming that the demand for product i is a random variable normally distributed \(d_{i} \sim N( \mu_{di}, \sigma _{di} )\) we have that \(\forall k \in \mathrm{K}\).
$$ \boldsymbol{P} \biggl[ d_{i} \leq \sum_{j\in \mathfrak{J}} \sum_{i \in \mathrm{I}} \biggr] = \frac{1}{\sqrt{2 \pi }} \int_{\infty }^{\xi } e^{ z_{i} ^{2}} \,dz_{i} = \Phi ( \xi_{i} ) =1 \alpha, $$
(10)
where
$$ \xi_{i} = \frac{\sum_{j\in \mathfrak{J}} \sum_{i \in \mathrm{I}} ( y_{ij}  \mu _{di} )}{\sigma_{di}}, \quad \hat{\mu }_{di} \approx \overline{\mathcal{X}} _{di}, \hat{\sigma }_{di} \approx \overline{\mathcal{S}}_{di}. $$
Here, \(\overline{\mathcal{X}}_{di}\) and \(\overline{\mathcal{S}}_{di} \) represent the sample mean and standard deviation of the product i in the clinic k. Hence, Eq. (10) becomes easily deterministic by solving for [25].
$$ \Phi^{1} ( \alpha ) = ( 2\alpha 1 ) \bigl( \operatorname{erf} ^{1} \bigr) \sqrt{2}, \quad\quad \operatorname{erf} ( \xi ) = \frac{1}{\sqrt{2 \pi }} \int_{0}^{\xi } e^{ \varrho } \,d\varrho ,\quad \alpha \in (0,1). $$
Shipload and volumes
The variables \(\mathit{Stx}_{j}\), \(\mathit{Vtx}_{j}\), \(\mathit{Sty}_{j}\), \(\mathit{Vty} _{j}\), are created to represent the shipload and the volume transported by route respectively.

(a)
Thus, for the route X
$$\begin{aligned}& \mathit{Stx}_{j} = \sum_{k \in \mathrm{K}} \sum _{i\in \mathrm{I}} w_{i} x_{ijk}, \quad \forall j\in \mathfrak{J} , \end{aligned}$$
(11)
$$\begin{aligned}& \mathit{Vtx}_{j} = \sum_{k \in \mathrm{K}} \sum _{i \in \mathrm{I}} v_{i} x_{ijk}, \quad \forall j \in \mathfrak{J}. \end{aligned}$$
(12)

(b)
For the route Y
$$\begin{aligned}& \mathit{Sty}_{j} = \sum_{k \in \mathrm{K}} \sum _{i\in \mathrm{I}} w_{i} y_{ijk}, \quad \forall j\in \mathfrak{J}, \end{aligned}$$
(13)
$$\begin{aligned}& \mathit{Vty}_{j} = \sum_{k \in \mathrm{K}} \sum _{i \in \mathrm{I}} v_{i} y_{ijk}, \quad \forall j \in \mathfrak{J}. \end{aligned}$$
(14)
Total amount of transport required per route

(a)
For the route X
$$\begin{aligned}& \mathit{Tsx}_{j} = \frac{\mathit{Stx}_{j}}{\vartheta_{j}} = \frac{\sum_{k \in \mathrm{K}} \sum_{i\in \mathrm{I}} w_{i} x_{ijk}}{\vartheta_{j}}, \quad\quad \mathit{Tsx} _{j} \in \mathbb{N}\cup 0, \quad \forall j\in \mathfrak{J}, \end{aligned}$$
(15)
$$\begin{aligned}& \mathit{Tvx}_{j} = \frac{\mathit{Vtx}_{j}}{\zeta_{j}} = \frac{\sum_{k \in \mathrm{K}} \sum_{i \in \mathrm{I}} v_{i} x_{ijk}}{\zeta_{j}}, \quad\quad \mathit{Tvx}_{j} \in \mathbb{N}\cup 0,\quad \forall j \in \mathfrak{J}. \end{aligned}$$
(16)

(b)
For the route Y
$$\begin{aligned}& \mathit{Tsy}_{j} = \frac{\mathit{Sty}_{j}}{\vartheta_{j}} = \frac{\sum_{k \in \mathrm{K}} \sum_{i\in \mathrm{I}} w_{i} y_{ijk}}{\vartheta_{j}}, \quad\quad \mathit{Tsy} _{j} \in \mathbb{N}\cup 0, \quad \forall j\in \mathfrak{J}, \end{aligned}$$
(17)
$$\begin{aligned}& \mathit{Tvy}_{j} = \frac{\mathit{Vty}_{j}}{\zeta_{j}} = \frac{\sum_{k \in \mathrm{K}} \sum_{i \in \mathrm{I}} v_{i} y_{ijk}}{\zeta_{j}}, \quad\quad \mathit{Tvy}_{j} \in \mathbb{N}\cup 0, \quad \forall j \in \mathfrak{J}. \end{aligned}$$
(18)
Final purchasing criterion
The final criterion for deciding which transport to buy is given in the comparison between weight and volume, i.e.,
$$\begin{aligned}& \mathcal{Q} x_{j} \max \{ \mathit{Tsy}_{j}, \mathit{Tvy}_{j} \} \quad \forall j \in \mathfrak{J}, \end{aligned}$$
(19)
$$\begin{aligned}& \mathcal{Q} Y_{j} = \max \{ \mathit{Tsx}_{j}, \mathit{Tvx}_{j} \} \quad \forall j \in \mathfrak{J}. \end{aligned}$$
(20)
The integrator path of the shovel nodes
Now, it is necessary to integrate all the shovel nodes in a route that links to most of them respecting the time window of their associated clusters. The objective of this exercise is to integrate the largest number of pivot nodes in a route that allows the transports of greater capacity to walk the route between them leaving here the product that will be pulverized in the respective clusters associated to such nodes. The clustering process is repeated, this time on a larger scale. We are now interested in grouping the pivot nodes located in the previous step. Subsequently, optimum routing is recalculated using the traveling salesman algorithm. Let \(Tc_{i}\) be the time windows (in days) associated with each cluster \(\mathfrak{C}_{i}\) on the path, also assume that each path is made up of \(\upsilon_{i}\) pivot nodes (shovel nodes), and each cluster \(\mathfrak{C}_{i}\) is integrated of \(\theta_{i}\) components. Then, to guarantee the time window of each cluster we now consider the set of constraints given by Fig. 4.
For the first cluster on the route
$$ t_{1} + ( t_{11} + t_{12} + \cdots+ t_{1{\theta_{1}}} ) = \sum_{j=1}^{\theta_{1}} t_{1j} \leq Tc_{1}. $$
For the second cluster on the route
$$ t_{1} + t_{2} + ( t_{21} + t_{22} + \cdots +t_{2{\theta_{2}}} ) = \sum_{j=1}^{\theta_{1}} t_{2j} \leq Tc_{2}. $$
In general for the cluster \(\upsilon 1\) on the route, we have
$$ \begin{aligned}[b] & t_{1} + t_{2} + \cdots + t_{\upsilon 1} + ( t_{21} + t_{22} + \cdots+ t_{\upsilon 1, \theta_{\upsilon 1}} ) \\ &\quad = \sum_{r=1}^{ \upsilon 1} t_{r} + \sum_{j=1}^{\theta_{\upsilon 1}} t_{\upsilon 1, j} \leq Tc_{\upsilon 1}. \end{aligned} $$
(21)
Equation (21) is equivalent to the inequality \(t_{p} + \sum_{i=1} ^{\theta } \sum_{j=i+1}^{\theta } t_{\upsilon 1,j} \leq T _{wc} \) which was included in the system of Eqs. (5). This also ensures that the travel times in the X path preserve the condition of the time windows of the clinics associated with the system clusters. This should be appended to the corresponding version of the traveling sales algorithm for the routing of vehicles in route X. It only remains to apply again the program MILP to this new instance.
The minimizing process of the mileage traveled
The problem of minimizing the mileage traveled by the transport in the route X was solved by sending the transports of greater draft to circulate in the route without violating the condition of accessibility. Note that, it is preferable to send a single large truck and spend less mileage with a single vehicle than to send several small vehicles that would spend much more kilometers. In order to control the typology of vehicles assigned to the system, Eqs. (10) to (13) were used (see Algorithm 2).
The integrator algorithm
The models described above are integrated in a sequence of operations that allows obtaining the optimal value of the global problem. The algorithm is as follows (Fig. 5).
Algorithm 2
(Calculation of transport requirements)

1.
For each cluster

(a)
Obtain a set of μ feasible neighboring clusters using the modified Dijkstra algorithm.

(b)
If the time window in each cluster is satisfied, go to step 1(c). Else, exchange clinics between neighboring clusters until this condition is met (remove nodes from one cluster and add them to another).

(c)
Obtain the routing sequence for each cluster by applying the traveling salesman algorithm.

2.
For all clusters

(a)
Apply the entire mixed linear programming instance to calculate the number of transports required to travel on the routes X and Y.

(b)
Evaluate the accessibility conditions to the route of the selected transports in all the nodes that make up each cluster.

(c)
If for some \(j ' \in \mathfrak{J}\), the transport is not feasible, equalize Eqs. (11) to (14) to zero for said \(j '\). Else go to step 2(d).

(d)
Obtain the suggested number of transports as well as the loads and volumes assigned to them.
The integrator algorithm is applied holistically and aims to achieve the unification of the three proposed models. At the end of this, we will have a solution consisting of three minimum values: (a) The travel times from the DC to the transfer node plus the travel times inside the system cluster, (b) the minimum acquisition and operation costs of transportation and (c) the exact number of vehicles required to move the required load and volume.