Two Efficient Algorithms for Weighted P-Median Problem

In this paper, we propose two different algorithms for a facility location problem which is well-known as a p-median problem. This is a combinatorial optimization problem wellknown to be NP-hard [1], [2] and [3] The goal of the problem is to select locations of p facilities to serve n demand points so as to minimize the total travel between the facilities and the demand points. This is a combinatorial optimization problem known as an NP-hard problem. The first of the proposed algorithms is a classical deterministic exchanged algorithm and the second is a genetic algorithm. Genetic algorithms are heuristic search methods that are designed to solve some optimization problems by the use of mimicking the evolution process. New solutions are produced from old solutions in ways that are reminiscent of the interaction of genes. Genetic algorithms have been applied successfully to problems with very complex objective functions. Our genetic algorithm is presented in some modification ways to find the best solution as far as possible.


Introduction
In this paper, we propose two different algorithms for a facility location problem which is well-known as a p-median problem. This is a combinatorial optimization problem wellknown to be NP-hard [1], [2] and [3] The goal of the problem is to select locations of p facilities to serve n demand points so as to minimize the total travel between the facilities and the demand points. This is a combinatorial optimization problem known as an NP-hard problem.
The first of the proposed algorithms is a classical deterministic exchanged algorithm and the second is a genetic algorithm.
Genetic algorithms are heuristic search methods that are designed to solve some optimization problems by the use of mimicking the evolution process. New solutions are produced from old solutions in ways that are reminiscent of the interaction of genes. Genetic algorithms have been applied successfully to problems with very complex objective functions.
Our genetic algorithm is presented in some modification ways to find the best solution as far as possible.

Model of the problem
There are given the following items: p is a number of centers placed I is a set of customers J is a set of candidates for the center placements c i is the price of i-th customer d ij is a distance from the-th customer to the -th center.
Decision variables x j =1 if candidate is used, 0 otherwise y ij =1 if the requirement is fulfilled by-thcenter, 0 otherwise.

Objective function
The first condition means that each customer will be served by just one center. The second condition implies p built service centers. The third condition ensures that the customer cannot be operated where the center will not be built. The task is therefore to deploy some habitat service centers so that the sum of the distances from each customer to designated centers is minimal. the other vertices according to the shortest distances and calculate v u c d , where is the candidate of i-th row and j-th column of the matrix P and d ij,l is the shortest distance from the l-th vertex to the nearest candidate u ij and is the number of the vertices allocated to the u ij candidate and j = 1,2,...,p. Subsequently, compute where j = 1,2,...,p, i = 1,2,...,k. a =^h . If the parents have some common gene (some common candidate) then this gene has entered inthe chain offspring. Remaining genes consequently create one set. , 1 a a a a = " ,. Consequently, genes are gradually excluded. The exclusion takes place according to which gene has the smallest value v uiĵ h as long as the number of genes drops down to p. This way, it creates offspring b that inherits properties of their parents. It may be that the offspring inherits the genes only from one parent as these genes are more dominant than the other parent's genes. If : , h then reject the new offspring from the process and put r := r + 1. 8. Go to 7 and repeat the process until a condition of termination is satisfied. 9. After the completion of the cycle we often obtain a population in which individuals are very similar and even identical. We declare the best individual as the best solution of the p-median problem and the corresponding value of objective function as the best rate of availability of covered vertices.

Classical deterministic replaceable algorithm
The following strategy is used in the proposed algorithm. At first it selects vertices with the greatest costs and assigns the closest vertices to the chosen ones. Then a vertex is chosen when the product of its cost and the distance is worst. It becomes a new candidate for covering while the original vertex moves temporarily to the back up. Then we state new assignment and compare it to the original. The better of these two is chosen, the worse is neglected. The algorithm then selects a new vertex with the worst assignment and the process repeats until the set of the vertices with the 'worst' assignment is empty.
This algorithm is published in [4] where is better explained together with the demonstration examples.

Genetic algorithm
First, we create an initial population of solutions. Consequently, in the executing phase good properties of these solutions are combined to obtain better solutions. If the algorithm is not able to find a better solution after the predetermined time then the cycle stops.

Construction
where is a number of vertices, is a number of edges, is a number of medians, is a length of each edge and is the evaluation of vertices. 2. Construct a matrix of the shortest distances D (nxn) where an element in i-th row and in j-th column represents the shortest distance between i-th and j-th vertices. Obviously, the matrix is symmetrical and the elements on the leading diagonal are zeroes. Construct a matrix of evaluated edges ID(nxn) where the edges are represented by incident vertices v i and v j , i.e.
4. Create an initial population P of feasible solutions. The initial population P represents the matrix of k rows and p columns where every row represents an individual, i.e. candidates (covered vertices) for some feasible solutions of the problem. 5. Define the objective function and assign values of the objective function to each individual in the population as follows: in i-th row of the matrix P allocate for the candidates The algorithm of any subsequent modification includes features of previous modifications.

Results and evaluations
Algorithms were tested in various graphs with various ranges, and we knew the optimal solutions. The results are presented in separate tables.

Results of classical deterministic replaceable algorithm
In Table 1, the first column represents the number of vertices of the graph and the number of medians, i.e. the number of vertices which must be covered. The second column represents the optimal and exact solution. The third column represents the solution found by this algorithm. The fourth column represents the time it took the algorithm to find the solution. The last, fifth column, shows the percentage difference between the exact solution and the solution found by this algorithm.  Table 2 shows the results of our initial genetic algorithm. This algorithm was realized 100 times for each set of entry data. Because the algorithm works with random processes, it gives different results for entry data. The column Number of finding the optimum shows how many times the algorithm was able to find the optimum (exact) solution in 100 trials. The column Average solution shows the arithmetic average of all 100 achieved results.

Modifications
First modification First, we tried to set a criterion which stated which genes will be inherited by the individual and which will not. The best variant was to select the best combination of genes, but this process is possible only with smaller tasks because the evaluation of each combination is very time consuming. In the end, we decided for a variant in which each vertex of the graph is assigned to a gene according to the shortest distance and the individual will inherit those genes which are assigned by most vertices. This method is not time consuming and offers better results than a genetic operator in the initial algorithm.

Second modification
We found out that the process of algorithm also influences the selection of the primary population which is randomly generated at the beginning. For this reason we decided for an alternative where the primary population is selected according to a certain system, not randomly, so that a gene is covered at least twice.

Third modification
While observing the algorithm, we noticed that in the process of substitution there were situations when a "good" gene was contained in an overall weak chromosome and so it was substituted by a better offspring. This caused that genes which could have been parts of the optimal solution were disappearing from the population. To prevent this from happening, we doubled the population where one half of the population, which contained all possible genes in sufficient amount, was not substituted, but kept unchanged until the end of algorithm. The other half is then step by step substituted by better offsprings. In this way, any individual from the population can enter the genetic operator by the process of random selection.

Fourth modification
The last modification can be described as the "arrival of immigrants" into population. Those were developed independently, which increases the biodiversity. In case they are crossed with other individuals from the population, unexpectedly able individuals can be created. In our case it means that the population is broadened by two randomly selected individuals and in each tenth generation, these two are changed for a new pair of randomly selected individuals. represents the percentage difference of the optimum and the arithmetic average. Other columns are obvious. It is obvious from the results in the table that the algorithm works fast but the results are not reliable. It was able to find the exact solution only with the simple practice task.
The last column Difference shows two percentage results. The first value shows the difference between the optimum solution and the best solution found by the algorithm. The other value Table 3 represents the results after the first modification. We changed the criterion of the selection of inherited genes and the result shows an obvious improvement. Table 4 represents the results after the second modification. This modification of creating the primary population on the bases of certain system brought improvement only in the practice task and one other task. Table 5 represents the results after the third modification. After the third modification where we kept the primary population, we can see a great improvement. The best solutions were achieved with accuracy up to 1% in two cases and in the other three cases we reached the optimum. The average solutions were up to 2.2%. Table 6 represents results after the fourth modification [6]. previous results it is very probable that the results were very close to the optimum. The results of a deterministic replaceable algorithm are not the worst. It is a deterministic algorithm and it gives only one solution for each set of entry data and depending on the nature of this data we can find a situation where the solution will be far from the optimum and, therefore, it is not reliable.