Sei sulla pagina 1di 31

EEL706 SOFT COMPUTING

A COMPARATIVE STUDY ON PARTICLE SWARM OPTIMIZATION AND GENETIC ALGORITHMS FOR TRAVELLING SALESMAN PROBLEMS

Ankit Nayan (2009EE50474) Ashok Meghwal (2009EE50478) Iftikar Ansari (2009EE50482) Priyanshu Jain (2009EE50485)

INTRODUCTION
This project deals with a performance evaluation of particle swarm optimization (PSO) and genetic algorithms (GA) for travelling salesman problem (TSP). This problem is known to be NP-hard, and consists of the solution containing N! permutations. The objective of the project is to compare the ability to solve the large-scale and other benchmark problems for both algorithms. The travelling salesman problem (TSP), which is known to be NP-hard in the field of discrete or combinatorial optimization, is concerned with finding an optimum path of travel in pre-located cities which are characterized using the coordinates on a map while minimizing the total cost associated with the path Also, it has been expressed as a non-deterministic polynomial (NP-hard) problem. In this project, a large-scale travelling salesman problem is solved by PSO and GA over multiple runs. In addition, these algorithms are compared to determine which one produced better results. The results show that PSO has a good convergence property (i.e., average generation) compared to GA, but in terms of the effectiveness of solutions, it is not as good as GA. Both algorithms for addressing problems can obtain solutions in similar execution time.

TRAVELLING SALESMAN PROBLEM


Formally, TSP can be defined as follows A travelling salesman who is required to visit N cities exactly one time returns to the starting node with the shortest distance. This can be admitted as a permutation problem that aims at finding the shortest distance (the minimum cost) on cities or the node to be visited. The Given N cities or nodes, a cost matrix C=[Cij] is searched for a permutation :

where Cij represents the cost of the travel from city i to j, which minimizes the distance, f( ,C).

PARTICLE SWARM OPTIMIZATION


Particle swarm optimization, which is a population-based algorithm like GAs, is an optimization technique which is based on social intelligence which exists in biological population. Social intelligence exhibits adaptive capabilities of people and animals by implementing an information sharing approach, furthermore also contributes to the creation, facilitation, and maintenance of critical behaviours.

The PSO Algorithm for TSP


Wang et al. (2003) introduced the concepts of Swap operator and Swap sequence redefining PSO operators for TSP problems. Here, we have briefly explained the discrete PSO algorithm. A normal solution sequence of TSP with n nodes is assumed as follows: S=(bi), i =1,2,,n

GENETIC ALGORITHMS
Genetic Algorithms are stochastic search techniques that are based on the ideas of selection of the fittest, crossing, and mutation in nature. They have been used successfully for solving a wide variety of different problems, including the TSP. A population of chromosomes, which is represented with different codes such as binary, real, and permutation, is changed by probabilistic application of the genetic operators (i.e., selection, crossover, and mutation) in each generation.

The fitness of chromosomes is measured by the objective function. As a class of stochastic methods, GAs are different from random search methods. While GAs carry out a multidirectional search by maintaining a population of potential solution, random methods consisting of a combination of iterative search methods and simple random search methods can find a solution for a given problem. One of the GAs most attractive features is that GA has the ability to explore the search space by considering the entire population of the chromosomes. The basic steps of the genetic algorithm are given in the following: (1) generate the initial population (2) evaluate the fitness of each individual (3) apply selection for individuals (4) apply crossover and mutation selected individuals
(5) evaluate and introduce the reproduced individuals. In TSP, GA is implemented in the following way.

Initial Population and Encoding


The initial population is randomly generated and each chromosome in the population represents a solution to the problem (i.e., a tour). The fitness of the chromosome means the tour length that is coded into it and depends on the ordering of the cities. The GA searches the space of solutions to obtain a best approximate tour. For instance, the chromosome shown in the following represents the path representation of a tour with eight cities.

Evaluation of Fitness
The evaluation function is an important indicator and is used to decide how good a chromosome is under environmental conditions. The fitness of each individual is calculated using Equation (1).

Selection
The selection is applied to the population by using alternative technique such as a roulette wheel tournament. In general, the selection is dependent upon the fitness level of the individuals actually existing in the population. In this study, tournament selection, which is based on a tournament among a few individuals chosen at random from the population, is used. That is, an individual is chosen for transferring into the next generation if he has better fitness value than other individuals of the population.

Crossover and Mutation


Crossover and mutation are highly efficient evolutionary operators to successful applications of GAs. Crossover can maintain good common genes in the parents, and also search new possibilities of recombining non common genes to converge to an optimal solution. The two parents are randomly recombined to create a new offspring which will be inserted into a new population in the next generation. Although it is said that mutation increases the diversity of the population by exploring the entire solution space, rather than diversity it is used to rectify infeasible chromosomes generated by a crossover operator.

In this study, cycle crossover (CX) and swap mutation (EM) were used. A schematic illustration of how these genetic operators work is given in Figure 1. For instance, assuming an 8-city TSP, (ACEBFDGH) corresponds to a tour starting from city A, visiting C, E, B, F, D, G, H in that order and returning back to A. In the CX crossover, the recombination is performed under the constraint that each gene comes from one parent or the other. The CX crossover operator is as shown.

The cycle that is defined in a manner similar to an algebraic permutation group always starts from the first position. Symbols in the cycle ofParent1 are copied into the same positions ofChild1, and these symbols are removed from the Parent2. The residual symbols of the parent are copied into the Child1. By changing the roles of parents, the same procedure is applied to generate the second child. The EM is shown in Figure 1(b). In the EM, the two genes selected randomly along the chromosome are swapped. So the genes coded into phenotype are to rearrange in a way.

Termination Criterion
The termination criterion can be selected in different ways: reaching the predefined fitness value, the number of generations, or a non-existing difference in the fitness value of each generation. In this article, a fixed generation number is used as the termination criterion.

EXPERIMENTAL RESULTS
Because GA and PSO are accepted as the random search algorithm, different results may be obtained at the end of every run. Therefore, multiple independent runs having different random seeds were performed to achieve a good solution.

RESULTS AND DISCUSSIONS


The relative error, which indicates how close the solution is to the known global solution, is considered in the performance measurement and calculated by:

Where Av is the average fitness value for the total number of runs under each problem, Op is the best known solution so far. Table 1 shows the known solution, average length, and relative error for the problems with synthetic data. After the program is run 30 times, the results are noted. In Table 1, the known solution is the found best solution; average length is the average length of 30 running. Figure 3 shows the relative errors according to average length for the problems with synthetic data. In this test, the computational effort of PSO and the GA was especially investigated for the same parameter settings. Also the effectiveness in terms of the solutions found by the algorithms was evaluated with respect to

known solutions for the test problems.

As can be seen in Table 1, in general, PSO converges to a solution in less generation than that of the GA. Regarding the average generation, PSO is better than the GA. However, in terms of the average length, the relative error, and computational time, it can be easily argued that the GA is more successful than the PSO. The optimum paths found by both algorithms is close to each other in this case.

CONCLUSIONS
Particle Swarm Optimization is a relatively recent heuristic search method based on social behaviour of bird flocking or fish schooling in searching for food, which is sometimes referred to as an evolutionary algorithm because of similarities. Particle swarm optimization and Gas are population-based search methods, and provide the information-sharing among their population members by moving in a search space using a combination of deterministic and probabilistic rules. The obtained results showed that PSO has rapidly converged to a solution but could get stuck on local minimum. Considering the optimum path and the relative error in terms of quality of solution, the GA has a better performance compared to PSO. It should also be noted that today the performance improvement studies for the PSO-based approach are conducted by scientists so that a global solution or a near-global optimal solution are obtained in TSPs.

REFERENCES
[1] Ozcan, E. and Erenturk, M. 2004. A brief review of memetic algorithms for solving Euclidean 2D travelling salesrep problem.Proc. of the 13th Turkish Symposium on Artificial Intelligence and Neural Networks99 108. [2] Shi, X. H., Zhou, Y., Wang, L. M., Wang, O. X., and Liang, L. C. 2006. A discrete particle swarm optimization algorithm for travelling salesman problem. Computational Methods10631068. [3] zsa glam, M. Y. 2008. Application of particle swarm optimization algorithm to travelling salesman problem and its performance investigation. Master thesis, Selcuk University, Konya, Turkey. [4] Oliver, I. M., Smith, D. J., and Holland, J. R. C. 1987. A study of permutation crossover operators on the travelling salesman problem.Proceedings of the Second International Conference on Genetic Algorithms and their Applications, Hillsdale, NJ, 224230.

[5] Al-Dulaimi, B. F. and Ali, H. A. 2008. Enhanced travelling salesman problem solving by genetic algorithm technique. Proceedings of World Academy of Science, Engineering and Technology28: 296 302. [6] Bhattacharyya, M. and Bandyopadhyay, A. K. 2009. Comparative study of some solution methods for travelling salesman problem using genetic algorithms. Cybernetics and Systems40: 124.

2.JAVA PROGRAM AND RESULTS FOR TRAVELLING SALESMAN PROBLEM USING PARTICLE SWARM ORGANISATION ALGORITHM

package tspusepso; import java.util.ArrayList; import java.util.Random; public class Main { public static class Swarm_Ex2b { private static final int PARTICLE_COUNT = 8; private static final int V_MAX = 4; // Maximum velocity change allowed. private static final int MAX_EPOCHS = 1000; private static ArrayList<Particle> particles = new ArrayList<Particle>(); private static ArrayList<cCity> map = new ArrayList<cCity>(); private static final int CITY_COUNT = 8; private static final double TARGET = 86.63; // Number for algorithm to find. //(30, 5), (40, 10), (40, 20), (29, 25), (19, 25), (9, 19), (9, 9), (20, 5) private static int XLocs[] = new int[] {30,40,40,29,19,9,9,20}; private static int YLocs[] = new int[] {5,10,20,25,25,19,9,5}; private static void initializeMap() { for(int i = 0; i < CITY_COUNT; i++) { cCity city = new cCity(); city.x(XLocs[i]); city.y(YLocs[i]); map.add(city); } return; } private static void PSOAlgorithm() { Particle aParticle = null; int epoch = 0; boolean done = false; initialize(); while(!done) { // Two conditions can end this loop: // if the maximum number of epochs allowed has been reached, or, // if the Target value has been found. if(epoch < MAX_EPOCHS){ for(int i = 0; i < PARTICLE_COUNT; i++)

{
aParticle = particles.get(i); System.out.print("Route: "); for(int j = 0; j < CITY_COUNT; j++)

{ System.out.print(aParticle.data(j) + ", "); } // j getTotalDistance(i); System.out.print("Distance: " + aParticle.pBest() + "\n"); if(aParticle.pBest() <= TARGET){ done = true; } } // i bubbleSort(); // sort particles by their pBest scores, best to worst. getVelocity(); updateparticles(); System.out.println("epoch number: " + epoch); epoch++; }else{ done = true; } } return; } private static void initialize() { for(int i = 0; i < PARTICLE_COUNT; i++) { Particle newParticle = new Particle(); for(int j = 0; j < CITY_COUNT; j++) { newParticle.data(j, j); } // j particles.add(newParticle); for(int j = 0; j < 10; j++) { randomlyArrange(particles.indexOf(newParticle)); } getTotalDistance(particles.indexOf(newParticle)); } // i return; } private static void randomlyArrange(final int index) { int cityA = new Random().nextInt(CITY_COUNT); int cityB = 0;

boolean done = false; while(!done) { cityB = new Random().nextInt(CITY_COUNT); if(cityB != cityA){ done = true; } }
int temp = particles.get(index).data(cityA); particles.get(index).data(cityA,

particles.get(index).data(cityB)); particles.get(index).data(cityB, temp); return; } private static void getVelocity() { double worstResults = 0; double vValue = 0.0;
// after sorting, worst will be last in list. worstResults = particles.get(PARTICLE_COUNT - 1).pBest();

for(int i = 0; i < PARTICLE_COUNT; i++) { vValue = (V_MAX * particles.get(i).pBest()) / worstResults;


if(vValue > V_MAX){ particles.get(i).velocity(V_MAX); }else if(vValue < 0.0){ particles.get(i).velocity(0.0); }else{ particles.get(i).velocity(vValue);

} } return; } private static void updateparticles() { // Best is at index 0, so start from the second best. for(int i = 1; i < PARTICLE_COUNT; i++) { // The higher the velocity score, the more changes it will need. int changes = (int)Math.floor(Math.abs(particles.get(i).velocity())); System.out.println("Changes for particle " + i + ": " + changes); for(int j = 0; j < changes; j++){ if(new Random().nextBoolean()){ randomlyArrange(i); } // Push it closer to it's best neighbor. copyFromParticle(i - 1, i); } // j
// Update pBest value.

getTotalDistance(i); } // i

return; } private static void printBestSolution() { if(particles.get(0).pBest() <= TARGET){ // Print it. System.out.println("Target reached."); }else{ System.out.println("Target not reached"); } System.out.print("Shortest Route: "); for(int j = 0; j < CITY_COUNT; j++) { System.out.print(particles.get(0).data(j) + ", "); } // j System.out.print("Distance: " + particles.get(0).pBest() + "\n"); return; } private static void copyFromParticle(final int source, final int destination) { // push destination's data points closer to source's data points. Particle best = particles.get(source); int targetA = new Random().nextInt(CITY_COUNT); // source's city to target. int targetB = 0; int indexA = 0; int indexB = 0; int tempIndex = 0; // targetB will be source's neighbor immediately succeeding targetA (circular). int i = 0; for(; i < CITY_COUNT; i++) { if(best.data(i) == targetA){ if(i == CITY_COUNT - 1){ targetB = best.data(0); // if end of array, take from beginning. }else{ targetB = best.data(i + 1); } break; } } // Move targetB next to targetA by switching values. for(int j = 0; j < CITY_COUNT; j++) { if(particles.get(destination).data(j) == targetA){ indexA = j; }

if(particles.get(destination).data(j) == targetB){ indexB = j; } } // get temp index succeeding indexA. if(indexA == CITY_COUNT - 1){ tempIndex = 0; }else{ tempIndex = indexA + 1; } // Switch indexB value with tempIndex value. int temp = particles.get(destination).data(tempIndex); particles.get(destination).data(tempIndex, particles.get(destination).data(indexB)); particles.get(destination).data(indexB, temp); return; } private static void getTotalDistance(final int index) { Particle thisParticle = null; thisParticle = particles.get(index); thisParticle.pBest(0.0); for(int i = 0; i < CITY_COUNT; i++) {
if(i == CITY_COUNT - 1){ thisParticle.pBest(thisParticle.pBest() +

getDistance(thisParticle.data(CITY_COUNT - 1), thisParticle.data(0))); // Complete trip. }else{ thisParticle.pBest(thisParticle.pBest() + getDistance(thisParticle.data(i), thisParticle.data(i + 1))); } } return; } private static double getDistance(final int firstCity, final int secondCity) { cCity cityA = null; cCity cityB = null; double a2 = 0; double b2 = 0; cityA = map.get(firstCity); cityB = map.get(secondCity); a2 = Math.pow(Math.abs(cityA.x() - cityB.x()), 2); b2 = Math.pow(Math.abs(cityA.y() - cityB.y()), 2); return Math.sqrt(a2 + b2); } private static void bubbleSort() {

boolean done = false; while(!done) { int changes = 0; int listSize = particles.size(); for(int i = 0; i < listSize - 1; i++) { if(particles.get(i).compareTo(particles.get(i + 1)) == 1){ Particle temp = particles.get(i); particles.set(i, particles.get(i + 1)); particles.set(i + 1, temp); changes++; } } if(changes == 0){ done = true; } } return; } private static class Particle implements Comparable<Particle> {
private int mData[] = new int[CITY_COUNT]; private double mpBest = 0;

private double mVelocity = 0.0; public Particle() { this.mpBest = 0; this.mVelocity = 0.0; } public int compareTo(Particle that) { if(this.pBest() < that.pBest()){ return -1; }else if(this.pBest() > that.pBest()){ return 1; }else{ return 0; } } public int data(final int index) { return this.mData[index]; } public void data(final int index, final int value) { this.mData[index] = value; return; }
public double pBest()

{ return this.mpBest; } public void pBest(final double value) { this.mpBest = value; return; } public double velocity() { return this.mVelocity; } public void velocity(final double velocityScore) { this.mVelocity = velocityScore; return; } } // Particle private static class cCity { private int mX = 0; private int mY = 0; public int x() { return mX; } public void x(final int xCoordinate) { mX = xCoordinate; return; } public int y() { return mY; } public void y(final int yCoordinate) { mY = yCoordinate; return; } } // cCity public static void main(String[] args) { initializeMap(); PSOAlgorithm(); printBestSolution(); return; }

} }

RESULTS:
Changes for particle 1: 2 Changes for particle 2: 2 Changes for particle 3: 3 Changes for particle 4: 3 Changes for particle 5: 3 Changes for particle 6: 3 Changes for particle 7: 4 epoch number: 1 Target reached. Shortest Route: 0, 7, 6, 5, 4, 3, 2, 1, Distance: 86.62998956150375 BUILD SUCCESSFUL (total time: 2 seconds)

1.MATLAB PROGRAM AND RESULTS FOR TRAVELLING SALESMAN PROBLEM USING GENETIC ALGORITHM

Potrebbero piacerti anche