Skip to content

ashleywang1/TSP-solver

Repository files navigation

To Strive, to Seek, to Find, and not to Forget: Adding Memory to Ant Colony Optimization

By: Ashley L. Wang email: ashwang@mit.edu

######################################################

This is the README file for the research project submitted to the 2012 Siemens Competition.

DISCLAIMER: The author is free from any liability involving the use of the project results.

====================== Background Information

The research project was based on two codes in the public domain:

(1) ACOTSP-1.0.2 Thomas Stuetzle. ACOTSP, Version 1.0.2 Available from http://www.aco-metaheuristic.org/aco-code, 2004.

The original ACOTSP code will always be referred to as ACOTSP-1.0.2 The modified ACOTSP code wll always be referred to as ACOTSP

(2) LKH-2.0.6 The LKH code can be found online at http://www.akira.ruc.dk/~keld/research/LKH/

During the earlier stages of the research project, LKH-2.0.5 was used. The current results are consistent with the LKH-2.0.6 version. No changes were made to the LKH-2.0.6 code.

Although LKH-2.0.6 can be incorporated into m-ACOTSP by replacing the local search component (ls.c), the integration of the two codes needs more testing.

Compilation of ACOTSP: On a Unix/Linux machine execute the following commands: tar xvfz acotsp.tgz cd acotsp make An executable file called acotsp will now be available in the directory acotsp.

Compilation of LKH-2.0.6: On a Unix/Linux machine execute the following commands: tar xvfz LKH-2.0.6.tgz cd LKH-2.0.6 make An executable file called LKH will now be available in the directory LKH-2.0.6.

======== Contents

TSPLIB doc opt.tour bin mMMAS 2-opt-p LKHsolo ACOsolo QnD mMMAS-LKH

TSPLIB: A collection of TSP files from http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/ Other TSP files include the mona-lisa100K.tsp from http://www.tsp.gatech.edu/data/ml/monalisa.html and 115,475 Towns and Cities in the United States usa115475.tsp from http://www.tsp.gatech.edu/data/usa/index.html

doc: A collection of papers and manuals relevant to the project.

opt.tour: A collection of optimal tour files (compatible with LKH format). LKH format (for input or output) has 6 lines at the beginning, while other published opt.tour files have only 5 top lines. For TSP instances without knowing optimality, the length of the tour replaces .opt., such as monalisa.5757191.tour.

bin: Two executable files: ACOTSP and LKH. Source codes: filename.c and filename.h A record of their changes: filename.change

mMMAS: To use this option, the modified-MIN-MAX ant system must be activated using -n in the command line.

Example: dsj1000.tsp, a random clustered TSP constructed by Johnson. Note: The TSP instance uses CEIL_2D, in which weights are Euclidean distances in 2-D (EUC_2D) rounded up. There is a bug in ACOTSP1.0.2 for this calculation (confirmed through e-mail communications with the original author of ACOTSP). Note: Running the dsj1000.tsp using the windows version of CONCORDE from http://www.tsp.gatech.edu/concorde/downloads/downloads.htm uses an EUC_2D setting.

2-opt-p: To use this setting, the local search flag has to be activated using -l 4 in the command line.
Note: Two extra parameters delta1 = 0.05 and delta2 = 0.1 have been added in order to reduce the running time.

Examples: att48.tsp, eil51.tsp, berlin52.tsp, bier127.tsp, ch130.tsp, ch150.tsp, gr202.tsp, gr229.tsp, pr439.tsp, att532.tsp, ali535.tsp, d657.tsp

LKHsolo: This runs the code LKH-2.0.6. The command to run the code is ./LKH instancename.par The results can be seen by using the command grep "Length" *.tour

ACOsolo: This runs the code ACOTSP. The command to run the code is ./acotsp -i instancename.tsp -z (or -x or -n) Note: Other parameters can be found in the manual for acotsp-1.0.2 The results can be found using the command grep "Best try" best* or grep "LENGTH" *.tour An optional input is the instancename.tour file. The output of this code is an instancename.ant.tour file.

QnD: This follows the quick-and-dirty ACO approach. The command to run the code is ./LKH instancename.par In the filename.par file, there is the line: INPUT_TOUR_FILE = instancename.ant.tour The instancename.ant.tour file can be generated from the acotsp code. The output of this code is an instancename.tour file.

mMMAS-LKH: This follows the modified-acotsp with an LKH local search approach. The results were generated by iteratively running two codes, with the acotsp code first and the LKH code last. The instancename.ant.tour file generated by the acotsp code becomes the input for the LKH code. The instancename.tour file generated by the LKH code becomes the input for the acotsp code.


   AAAA    CCCC   OOOO   TTTTTT   SSSSS  PPPPP
  AA  AA  CC     OO  OO    TT    SS      PP  PP
  AAAAAA  CC     OO  OO    TT     SSSS   PPPPP
  AA  AA  CC     OO  OO    TT        SS  PP
  AA  AA   CCCC   OOOO     TT    SSSSS   PP

###################################################### ########## ACO algorithms for the TSP ########## ######################################################

  Version: 1.02
  Author:  Thomas Stuetzle
  Copyright (c) Thomas Stuetzle, 2002

This is the README file to the software package ACOTSP.

This software package was developed by Thomas Stuetzle in connection with the Book

[DorStu04] Marco Dorigo and Thomas Stuetzle, "Ant Colony Optimization", MIT Press, Cambridge, MA, USA, 2004.

The software package is freely available subject to the GNU General Public Licence, which is included in file gpl.txt.

If you use ACOTSP in your research, I would appreciate a citation in your publication(s). Please cite it as

Thomas Stuetzle. ACOTSP, Version 1.0. Available from http://www.aco-metaheuristic.org/aco-code, 2004.

This software package provides an implementation of various Ant Colony Optimization (ACO) algorithms for the symmetric Traveling Salesman Problem (TSP). The ACO algorithms implemented are Ant System, Elitist Ant System, MAX-MIN Ant System, Rank-based version of Ant System, Best-Worst Ant System, and Ant Colony System. This is Version 1.0 of ACOTSP; it is in large part identical to the software used to produce the results in [DorStu04], but it has been slightly adapted to make the code more readable, more comments were added, and a new command line parser was generated with opag.

AIMS OF THE SOFTWARE: This software was developed to have one common code for the various known ACO algorithms that were at some point applied to the TSP in the literature. The software tries to provide a reasonably efficient implementation of these ACO algorithms while at the same time aiming for readability and understandability of the code.

UPDATES for version 1.02: (Manuel Lopez-Ibanez)

  • Avoid rounding issues that may rarely result in broken tours. (ants.c: neighbour_choose_and_move_to_next)

  • The termination condition is now checked after every local search call. (acotsp.c: local_search)

  • Avoid division by zero. (ants.c: bwas_pheromone_mutation)

  • Defaults for all algorithms follow those given in the ACO book.

  • The type of timer can be selected when building. Either 'make TIMER=dos' or 'make TIMER=unix'.

  • New command-line flags: --quiet and --seed

  • Information about command-line options is printed to stdout. Only errors are printed in stderr.

  • Fix various compiler warnings.

UPDATES for version 1.01:

  • corrected a memory leak on 64 bit architectures (file ls.c, line 83, changed int to long int)

  • corrected a problem in MMAS pheromone update (file acotsp.c, line 406, condition corrected to
    if ( u_gb == 1 && (iteration - restart_found_best > 50)) )

  • corrected a problem in BWAS update (file acotsp.c, line 406, procedure call should read
    bwas_worst_ant_update( &ant[iteration_worst_ant], best_so_far_ant ); )

  • corrected a problem in option parsing (file parse.c, line 1032 should read check_out_of_range( nn_ants, 1, 100, "nn_ants"); )

Thanks to the various users who have reported these problems!

========= CONTENTS

The GNU General Public Licence: gpl.txt

The main control routines, main: acotsp.c

Procedures to implement the ants behaviour: ants.c ants.h

Input / output / statistics routines: InOut.c InOut.h

Procedures specific to the TSP: TSP.c TSP.h

Local search procedures: ls.c ls.h

Additional useful / helping procedure: utilities.c utilities.h

Command line parser: parse.c parse.h

Time measurement: timer.h dos_timer.c : default timer implementation based on clock() unix_timer.c : in case you want to use rusage() instead, edit the Makefile to use this one or compile with 'make TIMER=unix'

Makefile

Instances: Some problem instances from TSPLIB: eil51.tsp kroA100.tsp d198.tsp lin318.tsp pcb442.tsp att532.tsp rat783.tsp pcb1173.tsp d1291.tsp pr2392.tsp. Other TSP instances are available from TSPLIB, the webpage for the 8th DIMACS Implementation Challenge on the TSP (http://www.research.att.com/~dsj/chtsp/) or the webpage on "Solving TSP"

===== Code

The software was developed in ANSI C under Linux, using the GNU 2.95.3 gcc compiler and extensively tested in this environment. The software is distributed as a gzipped tar file.

To install the code, first obtain the file ACOTSP.V1.0.tar.gz. Unzip the file by typing

gunzip ACOTSP.V1.0.tar.gz

and then unpack it by typing

tar -xvf ACOTSP.V1.0.tar

The software will unpack in a new folder ACOTSP.V1.0

To compile it under Linux just type 'make' and the executable 'acotsp' is produced.

Note: The code is written in ANSI C. Hence, the code should be reasonable portable to other Operating Systems than Linux or Unix.

====== USAGE

Given the large number of ACO algorithms, also the number of command line options is relatively large.

The default parameter settings are such, that MAX-MIN Ant System will be run using a 3-opt local search, using alpha = 1, beta = 2, rho = 0.5 for a maximum of 10 seconds per each trial for 10 independent trials. (guess who developed MAX-MIN Ant System ;-)

The executable 'acotsp' provides the following command line options (given are the short and the long options):

-r, --tries # number of independent trials -s, --tours # number of steps in each trial -t, --time # maximum time for each trial --seed # seed for the random number generator -i, --tsplibfile f inputfile (TSPLIB format necessary) -o, --optimum # stop if tour better or equal optimum is found -m, --ants # number of ants -g, --nnants # nearest neighbours in tour construction -a, --alpha # alpha (influence of pheromone trails) -b, --beta # beta (influence of heuristic information) -e, --rho # rho: pheromone trail evaporation -q, --q0 # q_0: prob. of best choice in tour construction -c, --elitistants # number of elitist ants -f, --rasranks # number of ranks in rank-based Ant System -k, --nnls # No. of nearest neighbors for local search -l, --localsearch 0: no local search 1: 2-opt 2: 2.5-opt 3: 3-opt -d, --dlb 1 use don't look bits in local search -u, --as apply basic Ant System -v, --eas apply elitist Ant System -w, --ras apply rank-based version of Ant System -x, --mmas apply MAX-MIN ant system -y, --bwas apply best-worst ant system -z, --acs apply ant colony system -n, --mmmas apply modified MMAS system (added by Ashley Wang) -j, --mmmaslkh apply modified ACO and LKH (added by Ashley Wang) -h, --help display the help text and exit

Options -u --as, -v --eas, -w --ras, -x --mmas, -y --bwas, -z --acs, -h, --help don't need arguments, while all the others do.

A Mandatory option is only the option "-i, --tsplibfile". Here, mandatory means that without specifying this option, the program won't work, since there is no input file.

All the other options take some default values. The default values for these are:

-r, --tries : 10 -s, --tours : 100 -t, --time : 10 /* seconds / -o, --optimum : 1 -m, --ants : 25 -g, --nnants : 20 -a, --alpha : 1 -b, --beta : 2 -e, --rho : 0.5 -q, --q0 : 0.0 -c, --elitistants : 100 -f, --rasranks : 6 -k, --nnls : 20 -l, --localsearch : 3 / use 3-opt / -d, --dlb : 1 -u, --as : 0 -v, --eas : 0 -w, --ras : 0 -x, --mmas : 1 / apply MAX-MIN Ant System */ -y, --bwas : 0 -z, --acs : 0

The default settings imply that as default MAX-MIN Ant System is run using a 3-opt local search procedure. Please note that these default values do not really make sense for some of the algorithms (e.g., typically an evaporation of 0.2 is recommended vor MAX-MIN Ant System); that is, for some of the algorithms the default parameter settings lead to poor performance (an example is ACS). Hence, when you use any of the ACO algorithms, make sure you set the appropriate parameter values. Typically, one may want to adjust the parameters

-t, --time -o, --optimum -m, --ants -b, --beta -e, --rho -q, --q0 -l, --localsearch

Note that only one option among -u --as, -v --eas, -w --ras, -x --mmas, -y --bwas, -z --acs, is to be specified.

Examples for running an experiments are:

./acotsp -i lin318.tsp -v -t 60. -o 42029 -m 50 -b 5

or

./acotsp --tsplibfile lin318.tsp --acs --rho 0.1 --q0 0.95 --time 60. --optimum 42029 --ants 10

======= OUTPUT

Every experiment produces three files. These files are

best.tsplibfilename cmp.tsplibfilename stat.tsplibfilename

where tsplibfilename is the instance identifier of the instance under solution.

The most important of these is the file "cmp.tsplibfilename". This file starts with a specification of the parameter settings used to run the experiment. The section with the comprehensive experimental data starts with

begin problem tsplibfilename

Next the random number seed for the next trial is given

Then, for each trial statistical information on the development of the best-so-far solution is given. Each section for a trial starts with

begin try <trial_number>

Then, each time the algorithm finds a new best solution a line

best iteration tours time

is added, where "best" is the tour length of the best-so-far solution; iteration is the iteration number in which this solution is found; tours is the number of solutions constructed so far (typically this is simple iteration X n_ants); and time is the time at which a new best-so-far solution is found

Each trial is ended by

end try <trial_number>

Once all trials are run the line

end problem tsplibfilename

is added to end the file.

The file best.tsplibfilename

collects the information about parameter settings, the best solution found in each trial, and some additional statistical information.

The file stat.tsplibfilename

may be used for the output of statistical information on a trial as generated by the procedure population_statistics(); in InOut.c; however, it is not heavily used in ACOTSP V1.0.

Have fun, and if you have any comments please write to

stuetzle no@spam informatik.tu-darmstadt.de

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages