Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Heuristic Optimization: EDA for TSP (Practical ...

Heuristic Optimization: EDA for TSP (Practical Work)

Resolve Travelling Salesman Problem (TSP) using GA-EDA-Lib.

Athens 2005 Heuristic Optimization (http://laurel.datsi.fi.upm.es/docencia/cursos/heuristic_optimization)

Oscar Cubo Medina

November 16, 2005
Tweet

More Decks by Oscar Cubo Medina

Other Decks in Education

Transcript

  1. Estimation Distribution Algorithms l  Population based algorithms l  Main steps:

    1.  Create population 2.  While not convergence 1.  Evaluate the individuals 2.  Train a Bayesian/Gaussian network with the best individuals 3.  Generate a new population simulating the network
  2. TSP: Definition l  A salesman has to find a route

    which visits each of n cities exactly one, and which minimizes the total distance travelled l  Inputs: l  Set of cities: l  Distances: l  Euclidean: l  Manhattan: l  Solution: which cyclic permutation Π of integers from 1 to N minimizes the distance? ( ) ( ) ( ) 2 2 distance , x x y y i j i j i j c c c c c c = − + − { } 1 2 3 , , , , n C c c c c = L ( ) distance , x x y y i j i j i j c c c c c c = − + −
  3. Our “map” 1 2 3 4 5 6 7 8

    9 10 1 0 1 2 2 3 3 4 4 5 6 5 7 6 8 9 7 8 10 9 11
  4. Looking for a solution 1.  Define the data format 2. 

    Define the format of our solution 3.  Define the fitness 1.  Use Euclidean distance 2.  Use Manhattan distance
  5. Step 1: Data Format City X Y 0 1 1

    1 1 7 2 2 4 3 2 9 4 3 5 5 4 1 6 4 9 … … …
  6. Step 2: Individual l  Our genome will have a position

    for each country/town/city… l  The value of each position could be: l  Order to visit the town l  Id of the town to be visited in the turn Town (Index) 0 1 … N Order (Value) 2 1 … 5
  7. Step 2: Individual l  Our genome will have a position

    for each country/town/city… l  The value of each position could be: l  Order to visit the town l  Id of the town to be visited in the turn Order (Index) 0 1 … N City (Value) 2 1 … 5
  8. Step 2: Individual l  Problems: l  How could we be

    sure that the individual is valid? Order 0 1 2 3 City 1 1 3 2 City 0 1 2 3 Order 0 3 0 1
  9. Step 2: Individual l  Use a “score” value for each

    town l  Order the vectors l  Use the sorted list of towns City (Index) 0 1 2 3 … N Score (Value) 1.20 2.45 3.12 1.26 … 4.10
  10. Step 2: Individual l  Use a “score” value for each

    town l  Order the vectors l  Use the sorted list of towns: (0,3,1,2,…,N) City (Index) 0 3 1 2 … N Score (Value) 1.20 1.26 2.45 3.12 … 4.10
  11. Step 3: Fitness l  We will use 2 distances: l 

    Euclidean l  Manhattan l  Convert our data format into a distance matrix l  Add the distances of the cities in the order of the individual City X Y 0 1 1 1 1 7 City 0 1 0 0 6 1 6 0
  12. Solution: Setup extern "C" GAGenome *defineProblem( int size, char *data

    ) { // Calculates all distances for(int i=0;i<NCITIES;i++) { for(int j=i; j<NCITIES;j++) { double dx=g_ptCities[i][X]-g_ptCities[j][X]; double dy=g_ptCities[i][Y]-g_ptCities[j][Y]; g_dDistances[j][i] = g_dDistances[i][j] = sqrt(dx*dx+dy*dy); } // for } // for // Create the genome GAAlleleSet<int> alleles; // Add the alleles values for (register int i = 0; i < 10*NCITIES; i++) alleles.add(i); return (GAGenome*) new GA1DArrayAlleleGenome<int>(NCITIES, alleles, evaluator); }
  13. Solution: fitness float evaluator( GAGenome& g ) { GA1DArrayGenome<int>& genome

    = (GA1DArrayGenome<int>&)g; // Prepare the data vector<int> city(NCITIES); vector<double> values(NCITIES); for (register int i=0; i<NCITIES; i++) { city[i] = i; values[i] = genome.gene(i); } // for // Sort all the values quicksort(city, values); // Calculate the score (sum of the distances in the path) register double score = 0; for (register int i=1; i<NCITIES; i++) { score += g_dDistances[ city[i-1] ][ city[i] ]; } // for score += g_dDistances[ city[NCITIES-1] ][ city[0] ]; score = 100/score; return score; }
  14. Extra: GA-EDA approach l  Execute the problem with: l  GA:

    -g l  EDA: -e l  GA-EDA: -ge l  Compare the results
  15. Extra: Improve the solution l  Add a local search with

    5 iteration in each evaluation l  TIP: The code looks like Simulated Anneling code (see first Session)