tsp_ga_basic(nStops​, popSize, numIter, xy )

quickly solves traveling salesman problem using genetic algorithm
282 Downloads
Updated 6 Oct 2017

View License

Uses tournament style genetic algorithm to solve the tsp problem. Initial population construction uses a random permutation approach as well as a greedy approach to make the algorithm more efficient.
% FUNCTION: tsp_ga_basic calculates the minimum tsp route distance for a
% set of xy points. The GA initializes the population using a random mix
% of greedy algorithm and random permutation
% Inputs:
% nStops: number of total delivery stops (or cities)
% popSize: size of the GA population of initial trials
% numIter: iteration budget estimate until convergence
% xy: coordinates of stops (cities or delivery locations)
% Outputs:
% globalMin: min route distance
% optEnergy: energy consumed by typical fedex truck
% optRoute: optimal tsp route based on xy coordinates
% GA uses uses a tournament approach mutation type genetic algorithm.
% Initialize:
% (1) Calculate the distance from each xy coordinate to every other xy
% coordinate as distance matrix dmat.
% Body:
% (1) Randomly generate populations
% (2) Find min-cost of all pop (trials); keep best pop member and plot.
% (3) Shuffle (reshuffle) pop for a new tournament
% (4) Sub-group pop into groups of 4.
% Find the best of the 4; Overwrite worst of 4 from sub-group pop
% (5) Mutate the best of 4 (winner) in each sub-group
% (6) Insert best of 4 (winner) and all mutations back into population
% (7) If iteration budget remains, go to step 2, else terminate.
% Termination: based on iteration budget.
%
% Useage:
%
% Example of inputs:
% nStops = 50; % Number of delivery stops for blimp-drone
% popSize = 400; % Size of the population of trials.
% numIter = 1500; % Number of iterations of GA; iteration budget.
% xy=10*rand([nStops,2]);
% tsp_ga_basic(popSize, numIter, xy, alpha, range )

Cite As

Robert Rich (2024). tsp_ga_basic(nStops, popSize, numIter, xy ) (https://www.mathworks.com/matlabcentral/fileexchange/64653-tsp_ga_basic-nstops-popsize-numiter-xy), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Traveling Salesman (TSP) in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.1.0

added convergence cost graph

1.0.0.0