{'fraction_non_alphanumeric': 0.03434291138148244, 'fraction_numerical': 0.01190784364483562, 'mean_word_length': 4.394228531533628, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Integer programming models for the semi-obnoxious p-median problem

The p-median problem concerns the location of facilities so that the sum of distances between the demand points and their nearest facility is minimized. We study a variant of this classic location problem where minimum distance constraints exist both between the facilities and between the facilities and the demand points. This specific type of problem can be used to model situations where the facilities to be located are semi-obnoxious. But despite its relevance to real life scenarios, it has received little attention within the vast literature on location problems. We present twelve ILP models for this problem, coupling three formulations of the p-median problem with four formulations of the distance constraints. We utilize Gurobi Optimizer v9.0.3 in order to compare these ILP models on a large dataset of problems. Experimental results demonstrate that the classic p-median model proposed by ReVelle \&Swain and the model proposed by Rosing et al. are the best performers.


Introduction
Facility location problems are among the most widely studied problems in OR, AI, computational geometry, and other disciplines. Most such problems include "pull" objectives, where clients wish to have the facility sites (e.g., pharmacies and stores) located close to them. For instance, the p-median problem concerns the location of p facilities so that the sum of (weighted) distances between the demand points and their nearest facility is minimized.
Another widely studied class includes problems with "push" objectives, where we seek to place the facility sites away from demand points, and in some cases from each other. Such facilities are known as obnoxious (or undesirable) because they have hazardous properties (i.e., dump sites for chemicals, prisons, etc.). In between, we have the class of semi-obnoxious (or semi-desirable) location problems where the facilities have both desirable and undesirable properties, meaning that both pull and push objectives are present [16]. In this case, clients wish to have facilities located close to them, but not too close. For example, the residents of a suburb wish to have restaurants and bars situated near them, but not too close because of the noise and traffic associated with such facilities. One way to model the requirements that arise when trying to locate semiobnoxious facilities is by placing minimum allowed distance constraints between facilities and/or between facilities and demand points [16]. For instance, gas stations (which are typical semi-obnoxious facilities) need to be at a minimum distance from one another and also from residencies, for safety reasons. At the same time, they must not be placed too far away from residencies for practical reasons. Such a scenario can be captured as a p-median problem with distance constraints.
The p-median problem, which is N P-hard on general networks for an arbitrary p, was originally proposed by Hakimi [14,15]. In 1970 ReVelle & Swain [19] presented the first IP for the p-median problem. They utilized a structure proposed by Balinski [1] in a plant location problem. Despite the large number of variables and constraints of this problem, it has many integer-friendly properties.
In 1979 Rosing et al. [20] proposed a formulation by using fewer Balinski constraints and adding a constraint used by Efroymson & Ray [13] in a plant location problem. This model reduces the number of constraints needed while retaining many of the integer-friendly properties of the ReVelle & Swain formulation. In 2003 Church [6] proposed a new formulation of the p-median problem by building upon the Rosing et al. model and reducing variables based upon a property of "equivalent assignment conditions". There are also other works that propose reformulations of the classic p-median problem [9,10]. For a thorough literature review on formulations of the p-median problem, see [6].
Location problems with distance constraints have received little attention within the vast literature on location problems in OR and related areas. There are some early works that considered maximum distance constraints between the demand nodes and the facility locations [7,8,21]. Moon and Chaudhry were the first to systematically study location problems with distance constraints [17]. Among the problems studied was the Median/l/l, in their terminology, where we seek to minimize the sum of the distances between the clients and their closest facility (as in p-median) subject to constraints that impose lower bounds (hence the l) in the distance between any two facilities and also between any facility and any client. This is the problem that we revisit in this paper, simply calling it p-median with distance constraints.
This specific problem has not received attention since then, but other location problems with distance constraints have been studied [5,18,3,11,12]. In a work that is relevant to ours, Berman & Huang [3] presented various formulations for the minimum weighted covering location problem aiming to minimize the total demand covered subject to the condition that no two facilities are allowed to be closer than a pre-specified distance. Interestingly, they were the first to experimentally compare four, increasingly more elaborate, models for the distance constraints in a location problem.
In this work we make a detailed study of the p-median problem with distance constraints for the first time. Given that the ILP modeling of this problem is based on two decisions: how to model the p-median objective and how to model the distance constraints, we develop and compare 12 different formulations by combining the three main formulations of the p-median problem with the four formulations of the distance constraints presented by Berman & Huang [3], extending them to include minimum distance constraints between facilities and clients.
To compare these ILP models, we utilize Gurobi Optimizer v9.0.3 and apply the solver on a set of instances generated using as basis the standard p-median benchmark dataset [2]. The experimental evaluation shows that the classic pmedian model proposed by ReVelle & Swain and the model proposed by Church are the best performers. Regarding the distance constraint formulations, there is no clear winner. An interesting conjencture that can be made based on our results is that simple models that were considered inefficient in the past are quite competitive on our studied problem due to the advancements in ILP solver technology.

Problem definition
We assume that p homogeneous facilities are to be placed on a weighted network G = {V, E} embedded on a plane, where a set I of demand points (clients) are already located. We also assume that the set J of nodes in G where facilities can potentially be located is known. Hence, we deal with a discrete/network location problem. The weight w ij on an edge (i, j) ∈ E denotes the symmetric service cost (typically the distance) between nodes i and j.
Between each pair of facilities i and j there is a distance constraint Euc d (i, j) > d 1 specifying that the Euclidean distance between the nodes where the facilities i and j are located must be greater than d 1 , where d 1 is a real constant. Also, between each facility i and client k there is a distance constraint Euc d (i, k) > d 2 specifying that the Euclidean distance between the node where facility i is located and node where client k is located must be greater than d 2 , where d 2 is a real constant. The constants d 1 and d 2 are common for all facilities and clients since we consider the homogeneous case in this work.
At this point let us clarify that the Euclidean distance Euc d (i, j) between two nodes i and j should not be confused with the minimum distance between the two nodes in the network, which is given by the sum of weights of the edges that belong to the shortest path between i and j. It is natural to model the costs of service between i and j through the cost of the paths between the two nodes, but we believe that any distance constraint established due to, say, safety reasons, should consider a metric like the Euclidean distance instead.
The goal is to minimize the sum of distances between each demand point and its nearest facility subject to the satisfaction of all the distance constraints. The existence of distance constraints between clients and facility locations means that, in contrast to the standard p-median problem where all nodes in the network are clients, in our case the set of potential facility sites is discrete from the set of client nodes.

ILP models
In this section, we present various binary ILP models for solving the homogeneous p-median problem with distance constraints so that the sum of distances between the demand points and their nearest facility is minimized. The following notation is used: -I: set of demand nodes.
-J: set of candidate facility sites.
p: the number of facilities to be located. -s ij : the shortest distance between any two nodes (demand nodes or facility sites). -d 1 : the minimum distance between each pair of facilities (i, j), where i ∈ J and j ∈ J. -d 2 : the minimum distance between each facility i ∈ J and all demand nodes.
x j = 1 if a facility is located at facility site j ∈ J and 0 otherwise.
y ij = 1 if a demand node i ∈ I is assigned to facility site j ∈ J and 0 otherwise.
In subsection 3.1 we present the three p-median formulations used in this work, while subsection 3.2 includes the four distance constraint models.

p-median models
We can formulate the p-median model proposed by ReVelle & Swain [19] as: min i∈I j∈J The objective function 1 aims at minimizing the sum of the shortest distances between the demand points and their nearest open facility. Constraint 2 specifies that p facilities are to be opened, while Constraint 3 ensures that each demand node will be served by one facility site. Constraint 4, i.e., the Balinski constraints, guarantees that each demand node will be served by a facility site that is opened.
This model has |J| + |I| × |J| variables and |I| + |I| × |J| + 1 constraints. Although it was almost impossible to solve problems of large size using this model in the past, ILP solvers have become significantly faster and capable of solving very large problems in the last two decades.
Rosing et al. [20] noticed that the Balinski constraints make the constraint set too large and they could use the Efroymson & Ray constraints instead: This constraint form adds only |I| constraints to the model, whereas the Balinski form adds |I| × |J| constraints. However, the Efroymson & Ray constraints are not integer-friendly, requiring many time consuming branch and bound operations. Rosing where r is the Balinski constraint rank-cutoff level, F i is the set of all facility sites except the p−1 furthest sites from client i, and K ir is the set of the r-closest sites to client i.
This model is the same as the original formulation except that: (i) Efroymson & Ray constraints 12 have been included for each facility site, (ii) Balinski constraints 11 are included for only the r-closest facility sites to each client, and (iii) p − 1 assignments to each client are eliminated. This model has |J| + |I| × (|J| − p + 1) variables and 2 |I| + r |I| + 1 constraints.
Church [6] built upon Rosing et al. model and introduced a new formulation by reducing variables based upon a property of "equivalent assignment conditions". The proposed model is the following: where: k: index that refers to the closest facility site order.
-O ik : index of the k ∈ J closest facility site to a client i ∈ I.
the set of facility sites that comprise the k ∈ J closest facility sites to client i ∈ I.
-A = {(i, j) | variable x ij is included in the model}, after variable substitution and eliminating any assignment to the furthest p − 1 facility sites for a given client i ∈ I.
Each constraint in this model mirrors the associated constraint in the Rosing et al. model. The additional notation used to formulate this model is associated with the concept of equivalent variables and their substitution. For every equivalent assignment condition present in the model, a variable is eliminated and a constraint is eliminated when that variable was present in a Balinski constraint. This model is no larger than the Rosing et al. model.

Distance constraints
We now present four formulations for the minimum distance constraints between each pair facilities as used by Berman & Huang [3] for the minimum weighted covering location problem. We modify these formulations and use them to model the p-median problem with distance constraints. Let us introduce two new sets: s.t. facilities cannot be in facility sites i and j because i and j are not in a safe distance between each other.
-N = {(j) | j ∈ J, ∃k ∈ I, Euc d (j, k) ≤ d 2 } , ∀j ∈ J: a facility cannot be placed in facility site j because there exists a demand node k that is not in safe distance from j.
Using this notation the first, and simplest, distance constraint that can be added to the p-median models is the following: Constraint 22 states that two facilities cannot be established if the distance between them is less than d 1 .
Another possible formulation for the distance constraint between two facilities is the following: If a facility site is opened at j ∈ M , x k must take a value of 0 for all k ∈ Q j . When x j = 0, at most p facilities can be sited in Q j . This constraint was originally proposed by Moon & Chaudhry [17] to formulate the anti-covering location problem. Constraint set 23 has fewer constraints than constraint set 22.
The third formulation for this distance constraint is the following: where n j is the minimum coefficient necessary to impose spatial restrictions between members of the set Q j . In order to calculate n j a complementary problem needs to be solved. Let us denote the graph G ′ = (N ′ , L ′ ), where N ′ = M and L ′ = {(j, k) ∈ M | Euc d (j, k) ≤ d 1 , j = k}. Let G ′ j be the subgraph of G ′ induced by Q j ∪ j and q j is the cardinality of the maximum independent set of G ′ j . Although the maximum independent set problem is N P-complete, G ′ j is usually a small graph. In this work we calculate q j with the second version of the Bron & Kerbosch algorithm [4]. Once q j is calculated, the value of n j can be determined by n j = min (p, q j ). Constraint 24 is tighter than constraint 23.
The fourth formulation for the distance constraint between two facility sites is the following: where H j is a maximal clique which includes node j of G ′ , Q ′ j is the subset of Q j ∪ j after removing all elements in H j . L 1 is the set of all H j (j ∈ M ) and L 2 the set of all nonempty Q ′ j (j ∈ M ). In order to obtain n ′ j the following ILP problem needs to be solved: Since Q ′ j is usually small, the solution of the ILP model needs only a very small amount of time compared to the solution of the p-median problem.
Finally, we also consider a distance constraint between each facility and each client, where all clients should be at a safe distance (d 2 ) for all opened facilities. This constraint can be formulated as: This constraint set ensures that each demand node is on a safe distance from each facility site if it is opened. Instead of setting variables x j , where (j) ∈ N , equal to 0, these variables can be removed from the model.
Coupling the three formulations of the p-median problem presented in subsection 3.1 with the four formulations of the distance constraints presented in this subsection, we get twelve different formulations of the p-median problem with distance constraints.

Computational study
As this is the first time that a computational study of the p-median problem with distance constraints is performed, there is a lack of benchmarks for this problem, and location problems with distance constraints in general. Hence, we experimented with random instances. We first describe the random generation model, then we give results from the twelve formulations. Computations were performed on an Intel i7 CPU 8700 with 16 GB of main memory, a clock of 3.2 GHz, an L1 cache of 348 KB, an L2 cache of 2 MB, and an L3 cache of 12 MB, running under CentOS 8.4. The ILP models were solved using Gurobi v9.0.3.

Random generation model
The random generator takes as input the p-median benchmark dataset [2], which consists of 40 problems with a set V of 100-900 nodes and a value of p between 5 and 200. We present results from twelve selected problems that were reasonably hard for the presented formulations. In the classical p-median problem, all nodes are considered to be clients. However, in our case, there is a minimum distance constraint between facilities and clients. Therefore, we select |J| < |V | nodes to be candidate facilities, while the remaining nodes |I| = |V | − |J| are clients. We have considered two cases: 1. We start by randomly selecting 80% of the nodes as candidate facility sites and the remaining 20% as clients. In case the resulting candidate facility sites is less than or equal to p, then we progressively increase the number of candidate facility sites until |J| > p. Also, in case the generated instances are infeasible, we again increase the number of candidate facilities (while decreasing the number of clients) until we get feasible instances. 2. We start by selecting 20% of the nodes as candidate facility sites and the remaining 80% as clients. Similarly to the previous case, we progressively increase the number of candidate facility sites until |J| > p and the generated instances are feasible.
In order to select the parameter d 1 , we find the minimum and maximum distance between all pairs of candidate facility sites and we set d 1 equal to a randomly generated number in the range [min, min +(max − min)/10]. This interval generated feasible problems in most cases. We perform a similar procedure to select the parameter d 2 . In this case, we calculate the minimum and maximum distance between all candidate facility sites and all clients.
Finally, the p-median benchmark problems include only the distance for each edge in the graph. We used Dijkstra's algorithm to calculate the shortest path s ij , i ∈ V, j ∈ V between each pair of nodes. We set the Euclidean distance between each pair of nodes to a random number in the interval [s ij /2, s ij ].

Experimental results
Tables 1 -2 present the execution times of the twelve ILP formulations for cases 1 and 2 described above. We use the following abbreviations: (i) RS1 -RS4: the ReVelle & Swain formulation using the distance constraints in 22, 23, 24, and 25 -26, respectively, (ii) RRR1 -RRR4: the Rosing et al. formulation using the constraints in 22, 23, 24, and 25 -26, respectively, and (iii) CHU1 -CHU4: the Church formulation using the constraints in 22, 23, 24, and 25 -26, respectively. Results from the best method in each class are given in bold.
All formulations were executed on ten instances for each of the problems. Tables 1 -2 present the average execution times. As the Rosing et al. and Church formulations require as input the parameter r, i.e., the Balinski constraint rankcutoff level, we ran these models for values of r starting from 10 to 60 with a step of 10. As there is no value for r that gives the best results on all problem classes, Tables 1 -2 report the results for r = 50, which resulted in the best results on most classes. But in the two rows giving the average execution times we also include, in parentheses, the average execution times obtained by running the two models on each problem class with the best r value for the specific class.
The average results show that the ReVelle & Swain formulation is the best one for problem of Case 1 (Table 1). This is contrary to the literature, since computational studies on p-median formulations concluded that the ReVelle & Swain cannot be used in practice due to its size [6]. However, current state-ofthe-art ILP solvers have become much faster and are able to solve very large instances, using sophisticated preprocessing routines to greatly reduce the size of the problems. The main reason for the superiority of the classic p-median problems in the first case is that it performs much fewer simplex iterations that the other p-median formulations.
When we customize the value of r for each problem class, the Church formulation is the best one on problems of Case 2 (Table 2). However, the other two formulations are not far off. But given that the customization of r would require extensive experimentation, the results from the case where r is set to a good overall value (50 in this case) give a more accurate picture. Case 2 problem instances are harder on average and the Rosing et al. formulation is the best performer in this case. Case 2 instances is harder than Case 1 because they are much larger in size (both in terms of variables and constraints), thus leading to more explored nodes in the branch-and-bound tree and more simplex iterations.
Overall, if we consider only relatively hard problem instances that all formulations need more than 10 seconds to solve, then RS3 is 1.51 -1.90 times faster than all Rosing et al. and Church formulations in Case 1 problems, whereas RRR2 is 1.07 -1.37 times faster than all ReVelle & Swain and Church formulations in Case 2 ones. Note that some of the generated instances are quite hard. The most difficult instance of Case 1 (resp. Case 2) required 1, 548 (resp. 1, 666) seconds.
Regarding the distance constraints, there is no clear winner, indicating that the more complex formulations do not always pay off. Most best execution times are achieved by the distance constraints in 22, 24 and 25-26. The distance constraint in 24 leads to better average execution times with the Rosing et al. and Church formulations both in Case 1 problems and with the ReVelle & Swain and Church formulations in Case 2 problems. Therefore, distance constraint in 24 can be regarded as the best candidate for most cases on average.

Conclusion
We have investigated for the first time a variant of the p-median problem which concerns the location of semi-obnoxious facilities in the presence of distance constraints between facilities and also between facilities and demand points. We have presented twelve ILP models, coupling three formulations of the pmedian problem with four formulations of the distance constraints. Experiments have demonstrated that, perhaps surprisingly, the classic p-median formulation coupled with a simple model for the distance constraints is quite competitive as it is the best one in problems with more candidate facility sites than clients, and it is not far off the the best performer (i.e. the Rosing et al.) in problems with more clients than candidate facility sites.
As future work we would like to consider specialized branch-and-bound algorithms for this problem and extend our study to the case where the facilities are not homogeneous. We can also extend/modify the proposed techniques to related types of location problems, and of course we can investigate the applicability of the methods to real-world problems.