The Connected P-Median Problem on Cactus Graphs

This study deals with the facility location problem of locating a set Vp of p facilities on a graph such that the subgraph induced by Vp is connected. We consider the connected p-median problem on a cactus graph G whose vertices and edges have nonnegative weights. The aim of a connected p-median problem is to minimize the sum of weighted distances from every vertex of a graph to the nearest vertex in Vp. We provide an O(n2p2) time algorithm for the connected p-median problem, where n is the number of vertices.


Introduction
e p-median and p-center problems are central to the field of location theory and logistics and are now well studied in operations research. Applications of the two problems include the location of industrial plants, warehouses, distribution centers, and public service facilities in transportation networks, as well as the location of various facilities in telecommunication networks [1,2].
To determine the backup sites or to balance the workloads among the center vertices in real networks effectively, Yen and Chen [3] originally proposed the connected p-center problem and showed that the connected p-center problem is NP-hard on both bipartite graphs and split graphs. Yen [4] studied the connected p-center problem on block graphs. Bai et al. [5,6] considered the connected p-center problem on cactus graphs and devised an O(n 2 p 2 ) algorithm.
Similar to the connected p-center problem, Shan et al. [7] introduced the connected p-median problem and considered the connected p-median problems on interval and circular-arc graphs. Kang et al. [8] studied the connected p-median problem on block graphs and proved that the problem is linearly solvable on block graphs which have unit edge lengths.
In this study, we consider the problem of finding the optimal location of connected p-median on a cactus graph. e study is organized as follows. In the next section, we formally introduce the notations and the problem that we studied in this study. In Section 3, we study the connected p-median problem on a cactus graph and devise an algorithm with time complexity of O(n 2 p 2 ). Finally, we conclude this study.

Problem Formulation
Let G � (V, E, w, l) be a connected graph with vertex set V(|V| � n) and edge set E(|V| � n), where each vertex v ∈ V (or v i ∈ V) has a weight w(v) ≥ 0 (or w i ≥ 0) and each edge e ∈ E has a certain length l(e). For any two vertices u, v, let P [u, v] be the shortest path from u to v, and d (u, v) be the length of P [u, v]. A p-vertex set X p is called a connected p-vertex set if the induced subgraph of X p is connected.
A cycle is a sequence (v 1 , . . . , v s , v s+1 � v 1 ) of s (s ≥ 3) clockwise indexed vertices, such that (v i , v i+1 ) is an edge, 1 ≤ i ≤ s. A graph G is called a cactus graph if any two cycles of G have at most one vertex in common. e vertex set of a cactus graph G can be divided into three disjoint subsets: G-vertices, C-vertices, and hinges. A vertex is called a C-vertex if it is in a cycle of G and its degree is 2 in G. A vertex is called a hinge if it is in a cycle of G and its degree is at least three. A vertex is called a G-vertex if it is not in a cycle of G.
Given a cactus graph G, a subtree is a connected subgraph of G induced by some G-vertices and hinges that does not contain any cycle. A subtree is called as a graft if it is maximal and without two hinges belonging to the same cycle. A cycle or a graft is called a block of G.
For convenience, we use a tree T G to represent the skeleton of G (Figure 1). en, we convert T G into a rooted tree as follows: select an arbitrary block, e.g., B 0 , as the "root" Problem 1. Find a connected p-vertex set X p in G, such that F G (X p ) is minimized. is problem is known as the connected p-median problem (CpM). e optimal solution X * p is called a connected p-median of G. Given a graft B h of G and an integer k, 1 ≤ k ≤ p, for each vertex v ∈ B h , the aim of the problem P( Given a cycle B h of s indexed vertices v 1 � h, v 2 , . . . , v s and an integer k, 1 ≤ k ≤ p, for any two vertices Given a subgraph G h and an integer k, 1 ≤ k ≤ p for each hinge of G h , the aim of the problem P (G h For all subcacti G B,h of G, denote by V 1 (respectively, ). For all hinges h of G, denote by V 3 the possible h-restricted connected p-medians V(G h , h, p). e following lemma establishes a significant relationship between the CpM problems on G h 0 and all restricted p-median problems.

Lemma 1. Given a cactus graph
en, v could be a G-vertex, a C-vertex, or a hinge. We distinguish three cases.
is a feasible solution to the CpM problem, that is, On the other hand, since X p is also a v-restricted connected p-vertex of G B,h , we have Computational Intelligence and Neuroscience Case 3. For the case v � h is a hinge, we distinguish three subcases.
e neighbor of h is a cycle B h , and and From the discussion above, there exists a vertex-restricted connected p-median whose sum of weighted distances of G h 0 is equal to the sum of weighted distances of a connected p-median of G h 0 .
In view of Lemma 1, we will design an algorithm to find all the restricted connected p-medians in V 1 ∪ V 2 ∪ V 3 . e algorithm uses the idea of dynamic programming. Traverse the tree T G "upward," from the vertices (block or hinge) with higher levels to the vertices with lower levels. An arbitrary order is defined when vertices are with the same levels. In each loop, we select a block B h or a hinge h. If B h is a graft, we calling program GRAFT (B, h) to deal with the problem on G B,h ; otherwise, we call program CYCLE (B, h). When it comes to G h , we call program HINGE (G, h). For the further computations, all useful data are transferred to h. When the block B h 0 has been checked, these data can be used to find a connected p-median V * p of G.

e Program GRAFT (B,h).
In this subsection, for each graft B h of G and each possible positive integer k, our task is to find all restricted connected k-medians V(G B,h , v, k). Denote by T the given graft B h . Assume that T is rooted at the hinge h. Denote by L ′ � max v∈V(T) lev(v). For each vertex v ≠ h, we can obtain two subtrees of T by deleting the last edge of the path from h to v. Let T v be the subtree that Computational Intelligence and Neuroscience be the subgraphs of G h corresponding to T v and T c v , respectively.
For each vertex v ∈ T, let E(v) be the edges of T v that are incident with v, and let s(v) � |E(v)|. After sorting the edges of E(v) in an arbitrary order, the l th edge is denoted by e(v, l). If e(v, l) � (v, v l ), then v is called as the farther far(v l ) of v l and v l is called as the l th son of v. Let son(v) be all sons of v. For the subtree T v , let T e(v,l) be the maximal connected subtree that contains v but not any edge e(v, j) for j > l.
For the subgraph G B,v , let G B,e(v,l) be the subgraph induced by all vertices of T e(v,l) and all subcacti hanging from it. For the subgraph G B,e(v,l) , let V(e(v, l), k) be the connected k-vertex set that contains v but not any vertex v j ∈ son(v) for j > l. We define the sum of weighted distances of V(e(v, l), k) over G B,e(v,l) as follows.
Definition 1. Given a subgraph G B,e(v,l) , the optimal value of V(e(v, l), k) is defined as Once we obtain all values f * (V(e(v, s(v))), k) and For the block B h , we first deal with all vertices in leaf(T). For each G-vertex v ∈ leaf(T), let For each hinge vertex v ∈ leaf(T), let If v is a hinge such that v ≠ h, we start by assigning Assuming that, for all l ′ < l, the values f * (V(e(v, l ′ ), k)) have been calculated. en, the value f * (V(e(v, l), k)) can be calculated as follows: For the right side of the above formula, the minimal value of the set inside corresponds to the case v l ∈ V * (e(v, l), k), while the value behind corresponds to the case v l ∉ V * (e(v, l), k) ( Figure 2).
If v l ∈ V * (e(v, l), k), set where V * (e(v, l − 1), k ″ ) and V * (e(v l , s(v l )), k − k ″ ) are the corresponding subsets to f * (V(e(v, l − 1), k ″ )) and f * (V(e(v l , s(v l )), k − k ″ )), respectively. Otherwise, set 4 Computational Intelligence and Neuroscience Note that there are at most |V(T)|p values f * (V(e(v, l), k)) which can be calculated by traversing the edges in T. Each calculation contains finding the minimum in at most 2k terms. en, all the values f * (V(e(v, l), k)) can be computed in O(|V(T)|p 2 ) time.

e Calculation of f G c B,v (v).
We start by assigning After  (V(G B,h , v, k)) can be computed by formula (7) in O(|V(T)|p 2 ) time. CYCLE (B,h)

e Program
and all subcacti hanging from it, and let For each integer k, 1 ≤ k ≤ min p, |G B,,v i ,v j | , and the sum of the weighted dis- Suppose that the midpoint of the path C v j ,v i lies in the edge e m(j,i) . In particular, if the midpoint is a vertex, assume it coincides with v m(j,i) . By deleting e m (j,i) (j,i) and v m(j,i)+1 , respectively. Next, we define to denote the partial sum of the weighted distances to v j and v i , respectively. Once all the values defined above have been computed, we can calculate the sum of the weighted distances of Computational Intelligence and Neuroscience If v i is a hinge that is not equal to h, we start by assigning (20) Since C v i ,v j is a graft, for all j ≥ i and possible numbers k, e computation of the values For the sake of simplicity, we only describe the calculation of f * 2 (V( v i , v j , k)), while the values of f * 3 (V( v i , v j , k)) can be calculated in a similar way. Note that, for all pair v i , v j of C, the corresponding middle edges can be found by the method similar as in [5] in all pairs of vertices of C whose middle edge is e m , where l 1 ≥ l 2 ≥ · · · ≥ l t .
By traversing all vertices in V, for l 1 ≥ l k ≥ l t , all values f * 2 (V( v r k , v l k , k)) can be calculated by the following formula:

e Program HINGE (G h , h).
In this subsection, we are given a hinge h and the relevant subcactus G h ; for all possible positive integers k, our task is to find the restricted connected k-medians V (G h , h, k).
Assume that h is a hinge of G.  e(h, l). For each subgraph G h , denote by G e(h,l) the maximal connected subgraph that contains h and all subcacti hanging from it but not any block B j for j > l. Particularly, G e(h,0) � h and G e(h,s(h)) � G h (Figure 3).
For each subgraph G e(h,l) , denote by V (e(h, l), k) the connected k-vertex set that contains h but not any vertex of B j ∈ son(h) for j > l. Next, we define the optimal value of V (e(h, l), k) over G e (h,l) .
Once we obtain the values f * (e(h, s(h)), k), the sum of weighted distances from vertices of G h to V(G h , h, k) can be calculated as We assign V(G h , h, k) � V * (e(h, s(h)), k). According to our assumption, we obtain and assign  , l), k)) and V * (e(h, l), k).
Suppose that, when the phase j begins, the value  , s(h))), k) by the following method, and then, go to the next hinge with level L m − j.
Assuming that, for all l ′ < l, the values f * (V(e(h, l ′ ), k)) have been calculated. en, the value f * (V(e(h, l), k)) can be calculated as follows: if B l is graft, otherwise, If B l is graft, set otherwise, set where (h, l), k)) which can be calculated by traversing the edges in T G . Each calculation contains finding the minimum in at most 2k terms. en, all the values f * (V(e(h, l), k)) can be com- Suppose that far(h) � B ′ in T G and the hinge of B ′ is h ′ (Figure 3). en, F G c h (h) can be computed as follows: Note that all values F G c h (h) and W(G c h ) can be calculated by traversing all vertices of T G "downward." e total calculations take O(|V(T G )|) time.

Algorithm for the CpM Problem.
According to Lemma 1, we can find a connected p median V * p from V 1 ∪ V 2 ∪ V 3 . e sum of weighted distance from vertices of G to X * p can be calculated as Next, we design Algorithm 1 to solve the CpM problem. For a given cactus graph G, as a preprocessing of Algorithm 1, first, the distance-matrix of the cactus will be calculated. en, we construct the rooted skeleton graph of the cactus and calculate maximum level L m . is preprocessing will be finished in O(n 2 ) time.
Since there are at most O(n 2 ) elements in V 1 ∪ V 2 ∪ V 3 , the calculation of F G (V * p ) takes O(n 2 ) time. en, we can use the following theorem to end this section.

Theorem 1.
On the cactus graph with n vertices, the CpM problem can be solved in O(n 2 p 2 ) time.
Input: A cactus graph G, the corresponding rooted skeleton T G , and the maximum level L m Output: A connected p median V * p and the sum of weighted distance to V * (4) if v represents a graft B then (5) Find the companion hinge of B in T G , assuming it to h, and calculate the level L′ (6) Call GRAFT (B, h) to calculate the values F G B,h (V(G B,h , v, k)) and find V(G B,h , v, k) for v ∈ B h of level j and all possible integers k, and set V 1 � V 1 + V(G B,h , v, p) . (7) end (8) if v represent a cycle B then (9) Find the companion hinge of B in T G , assuming it to h (10) Call

Concluding Remarks
In this article, we consider the connected p-median problem on cactus graph and design an algorithm with time complexity O(n 2 p 2 ) for it. In the following, it is meaningful to consider the connected p-median problems on other classes of graphs, such as planar graphs, interval graphs, and circular-arc graphs.

Data Availability
All the datasets used to support the findings of this study are available from the authors upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.