-6

If I have a network of nodes, how can I use genetic algorithms to calculate the shortest path between any two nodes?

BryanH
  • 5,826
  • 3
  • 34
  • 47
jordan11
  • 43
  • 1
  • 1
  • 3
    Why would you use a genetic algorithm for this? What's wrong with an ordinary one? – Stephen C Dec 13 '09 at 07:21
  • @Stephen C: It's probably what his teacher requires. – cherouvim Dec 13 '09 at 07:33
  • You need to post a sample of your data and some code of what you've tried so far for this to be a meaningful question. Otherwise, the generic "[STFW](https://encrypted.google.com/search?q=how+can+I+use+genetic+algorithms+to+calculate+the+shortest+path), maybe?" applies. – BryanH Sep 25 '12 at 14:10
  • I dont know why this question got negative votes :). @StephenC: Travelling Salesman Problem which is an NP Hard problem & can be solved well with Genetic Programming or even Ant Colony Optimization giving sub optimal solutions. – Yavar May 19 '13 at 15:48
  • @Yavar - the TSP etc can be "solved" lots of ways if you want a suboptimal solution. It is only NP Hard to find an optimal solution. (Or to put it another way, a non-optimal solution is not a solution to the TSP at all.) Like I say, what is wrong with an ordinary algorithm? – Stephen C May 19 '13 at 21:29
  • I guess that the reason you got so many downvotes are: 1) a lot a people think that GA's are a fundamentally bad way to **solve** this kind of problem. Especially when there is a good deterministic solution to the OP's problem. 2) The OP is really asking for a tutorial on GA's ... applied to a specific question. He'd be better served by reading a book or something. 3) No sign of any attempt by the OP to figure it out himself ... before asking. – Stephen C May 19 '13 at 21:37
  • Look at the pseudo code section [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra's_algorithm) OK then have a look at [A Genetic Algorithm Approach to Solve the Shortest Path Problem for Road Maps](http://www.ent.mrt.ac.lk/iml/ICIA2005/Papers/SL008CRC.pdf) or [Solving Travelling Salesman Problems Using Genetic Algorithms](http://ai-depot.com/Articles/51/TSP.html) – Adriaan Stander Dec 13 '09 at 07:04

1 Answers1

3

How about using GA to solve the TSP problem?

TSP is a NP complete problem. That is it is not possible to find a solution to the TSP problem in Polynomial time. However, given a solution it can be verified if it is a solution in polynomial time.

Meta-heuristic methods such as Genetic Algorithms can be investigated as a tool to solve a TSP problem because of the population based approach they operate. This way they can "process" a huge number of solutions in on run of the algorithm. To solve any problem using GAs we need to define the following:

  • Fitness function
  • Individual chromosome
  • Crossover operator
  • Mutation

Fitness function: Here the fitness function is easy to define. It should be the distance that the salesman has to traverse for a certain tour of the cities possible. We seek to minimize this in TSP.

Chromosome: A chromosome can be defined simply as following- Suppose we have five cities A,B,C,D and E. Then imagine a chromosome of length 5, with each "slot" of the chromosome containing either of the 5 cities. For eg, A,C,D,B,E is a valid chromosome in our case.

Crossover operator: A crossover operator is used in a GA to "mix" two parents with the hope to get fitter children. Various crossover operators are available in GA literature with each having a different way to achieve the same thing. For eg, consider the single point crossover. It randomly selects a crossover point and then interchanges the bits between the two. Without getting into other specialized crossover operators, let us see what would be a good crossover operator for us. In our case, two parent chromosomes will each have a permutation of A,B,C,D,E. Whatever crossover method we choose, we have to take care of one fact here: the crossover operator should not create a child in which one city is present more than once, that is a invalid chromosome. One such crossover operator is the "Order Crossover " (OX) which can be used here.

Mutation: Mutation can be as simple as simply swapping two positions in a single chromosome here.

Overall this is how a TSP using GA would work:

  • You create a population of individuals with each being of size 5, and containing a permutation of A,B,C,D,E (there will be lots of repetitions of the same permutation)

  • You start the GA and in every run, you evaluate each individual on the basis of the fitness function by calculating the distance using the distance parameters given to you

  • Crossover, Mutation improves the individuals and finally the best solution would be the individual with the best tour, ie. the optimal permutation of A,B,C,D,E.

Hope that helps!