// // This is NOT a GA for TSP. This is an example of a binary encoding for // the TSP inspired by a talk by Chaitin and a paper by WPC. // A tour is represented as a binary string representing a sequence // of swaps by a bubbleSort process, i.e. the string is a sequence of // instructions for constructing a tour. For a tour of n cities the // sequence is of length n(n-1)/2, i.e. maximum number of steps in // a bubble sort (maximum trajectory). If S[i] = 1 then a swap takes place // in the kth step of the bubbleSort (see evaluate method below). // // The encoding permits 2^(n(n-1)/2) chromosomes for n! tours. A more // compact encoding will exist for a mergeSort representation, taking // n.log(n) bits // public class GATSP { int n,m; private int[] P; // permutation, a tour private int[] S; // sequence of actions private boolean overflow; public GATSP(int n){ this.n = n; m = n*(n-1)/2; P = new int[n]; S = new int[m]; overflow = false; for (int i=0;i "); for (int i=0;i0;i--) for (int j=0;j