You are on page 1of 4

Natural Computing - Practical Assignment

Solving Traveling Salesman Problems with Nature-Inspired Algorithms


The Traveling Salesman Problem (TSP) is one of the most intensively studied combinatorial optimization problems. Given a two-dimensional list of city coordinates, the aim is to find the shortest round-trip that visits each city exactly once and then returns to the starting city. The length of the trip is determined by the Euclidean distance between pairs of cities.

Assignment
Based on skeleton files provided, implement the following nature-inspired algorithms for solving Traveling Salesman problems: A Simulated Annealing (SA) algorithm; A Genetic Algorithm (GA); An Ant Colony Optimization (ACO) algorithm.

Run each algorithm for 10,000 function evaluations (i.e., 10,000 calls to evaluate_tour, see PA.zip) on benchmark problems1 Djibouti (38 cities), Qatar (194 cities), and Uruguay (734 cities). Write a report on your work, starting with a section in which per algorithm you provide a description of your implementation, including pseudocode. Under the Experiments section, list comparisons of algorithm convergence on each test problem (make a plot of the length of the best tour found so far against the number of used evaluations), and visualize the best result per optimizer for all test problems. Analyze the outcome of the experiments.

Submission Guidelines
This project is to be implemented in MATLAB. Each algorithm should be fully contained in one .m file and structured according to the skeleton provided in http://natcomp.liacs.nl/NC/PA.zip. Your report in PDF format should include one page per algorithm and two pages for the results. It should follow the template provided in this document. Your complete submission consists of four files: a report in PDF format and one .m file per algorithm. These files are to be 1) sent by email to ereehuis@liacs.nl; 2) printed and put in mailbox of Edgar Reehuis in room 156. Follow carefully the MATLAB Implementation Details and the Report Structure Template provided below (not adhering to the requirements and conventions will affect your grade). Deadline: before May 8th, 2013, 5pm (late delivery: 1 point subtracted per week)

Obtained from http://www.tsp.gatech.edu/world/countries.html.

MATLAB Implementation Details


Each algorithm implementation consists of one .m file named lastname1_lastname2_sa.m, lastname1_lastname2_ga.m, and lastname1_lastname2_aco.m. Each implementation should be structured as follows:
function [opt_tour, opt_tour_length] = lastname1_lastname2_sa(tsp_instance, eval_budget) end

(in) tsp_instance: a string with the name of the TSP instance (e.g., Djibouti ); (in) eval_budget: the number of function evaluations that can be used. One evaluation means computing the length of one candidate tour, and one iteration of the algorithm (generally) consists of several such evaluations; (out) opt_tour: a vector containing the indices of all cities, listed in the order that they are visited (i.e., a permutation of the city indices); (out) opt_tour_length: the length of the best found tour.

Make sure all output (e.g., plotting) is turned off in the submitted version of your work!

TSP Instances
Each TSP instance is provided as a function of the following form:
function x = Qatar()

It returns a three-column array, with in the first column the indices of the cities, and in the second and third column the x and y-coordinates of the cities. The following TSP instances are provided for testing and the experiments: Djibouti.m (38 cities, useful for testing); Qatar.m (194 cities, useful for testing); Uruguay.m (734 cities, for running the actual experiment); Zimbabwe.m (929 cities, optional); Italy.m (16862 cities, optional, if you are up for a challenge).

Skeleton Files
Complete the following three skeleton files for your implementations: sa_skeleton.m ga_skeleton.m aco_skeleton.m

Helper Functions
We provide helper functions that are to be used in your code. analyze_tsp.m: a function for obtaining useful information from a TSP instance.
[num_cities, coordinates, distance_matrix] = analyze_tsp(tsp_instance)

(in) tsp_instance: a string with the name of the TSP instance (e.g., Djibouti ); (out) num_cities: the number of cities in the TSP instance; (out) coordinates: a matrix containing per row the coordinates of a city; (out) distance_matrix: a distance matrix where the value at position i,j denotes the Euclidean distance between city i and city j.

evaluate_tour.m: evaluates a candidate tour.


[tour_length] = evaluate_tour(distance_matrix, tour)

(in) distance_matrix: a distance matrix where the value at position i,j denotes the Euclidean distance between city i and city j; (in) tsp_tour: a candidate tour for the TSP instance, being a vector of indices denoting the order in which the cities are traversed; (out) tour_length: the length of the tour.

nn_shortest_tour_tsp: a Nearest Neighbor algorithm for finding shortest paths (useful for generating a reference tour).
[nn_tour, tour_length] = nn_shortest_tour_tsp(tsp_instance)

(in) tsp_instance: a string with the name of the TSP instance (e.g., Djibouti ); (out) nn_tour: a vector with the ordered city indices of the tour found by the algorithm; (out) tour_length: the length of the path.

plot_tsp_tour.m: plot a path for a tsp instance.


[] = plot_tsp_tour(coordinates, tsp_tour)

(in) coordinates: a matrix containing per row the coordinates of a city; (in) tsp_tour: a vector with the ordered city indices of the to-be-plotted tour.

run_algorithm_comparison.m: use this script to generate the final plots for your report; the results and plots will be stored in a subdirectory named Results. By adhering to the naming convention your optimizers are automatically detected.
[] = run_algorithm_comparison()

This script will be used by the course administration to compare all student implementation against each other, granting a bonus to the best submission(s).

Report Structure Template


Authors (names, email addresses, and student numbers) Simulated Annealing Pseudocode per algorithm including explanatory description, overview of algorithm parameters and optimal settings used for these parameters, and argumentation for design choices. Make sure that the algorithm and the results found are reproducible from your description. Genetic Algorithm ditto Ant Colony Optimization ditto Experiments Use run_algorithm_comparison to generate plots of your results. Analyze the outcome of the experiments.

Example: plots for Djibouti (do this for all three test problems)

You might also like