# Visualisation of Genetic Algorithms for the Traveling Salesman Problem in Java

### by Johannes Sarg

This thesis of diploma has been implemented in Java 1.1 in March 1998.

## The Traveling Salesman Problem (TSP)

Find the shortest trip through n towns where each town must be visited exactly once.

In the following we define that from each town all other towns can be visited. The costs to visit a town from another are represented by their euklidic distance. Therefore the costs are reflexive.

## The Genetic Algorithm (GA)

A GA tries to use basic principles of natural evolution. It is especially appropriate for problems with large and complex search-spaces, where the global optimum can't be found within a reasonable amount of time using traditional techniques as e.g. total enumeration or branch and bound. It cannot be guaranteed that the optimum solution is found by the GA. Here are some references for GAs.

### Structure of a GA:

  procedure GA
  begin
    t = 0;
    initialize(P(t));
    evaluate(P(t));
    while (not termination condition)
    begin
      t = t + 1;
      Qs(t) = selection(P(t-1));
      Qr(t) = recombination(Qs(t));
      P(t) = mutation(Qr(t));
      evaluate(P(t));
    end;

  end;

### Description:

A set of potential solutions are randomly initialized and their quality evaluated. Out of this set better solutions are preferred, corresponding to a probability distribution. Each time, two of the selected solutions creats new solutions by recombination which finally are mutated. These generated solutions are evaluated and represents the basis for the next generation. In this way a GA tries to find better solutions and to reach the global optimum.

## Objectives of the program TSPGA

- exact simulation and visualisation of a GA run
- visualisation of the mutation and recombination methods
- possibility to compare different GA runs concerning the same TSP

## The GA for TSPs

In the "Options" menu, you can configure the following properties for the GA:

GA parameters:

- recombination methode:
  - Partially Matched Crossover (PMX)
  - Order Crossover (OX)
  - Cycle Crossover (CX)
  - Uniform Order Based Crossover (UOBX)
  - Edge Recombination Crossover (ERX)
  - ERX with heuristic (Grefenstette)
  - None
- recombination probability (0% - 100%)
- mutation methode:
  - Inversion
  - Insertion
  - Displacement
  - Reciprocal Exchange (Swap)
  - None
- mutation probability (0% - 100%)
- population size (5 - 100)
- k value for the Tournament selection (1 - 10)
- elitism (true / false)

Set Problem: A grid can be defined where the user can set the positions of the towns (4 - 100 towns).

Now its time to start the TSPGA. The applet should run on a www-browser supporting Java 1.1.

Click here:

## Links

Download the zipped thesis of diploma which includes the user documentation for this program (in German): ftp://tspgadoc.zip

Download the zipped class files and this html-page of TSPGA: ftp://tspga.zip

This program is used in the lecture "Evolutionäre Algorithmen" by Univ. Ass. Dipl.-Ing Dr. Günther Raidl of the Institute for Computergraphics on the Vienna University of Technology.

## References

- this thesis of diploma
- Z. Michalewicz: Genetic Algorithms + Data Structures = Evolution Programs, Springer, New York, 1992
- D. E. Goldberg: Genetic Algorithms in Search, Optimization and Machine Learning, Addison-Wesley, MA, 1989

Page maintained by Johannes Sarg, March 1998