tsp_ga_basic(nStops, popSize, numIter, xy )
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 (2026). tsp_ga_basic(nStops, popSize, numIter, xy ) (https://uk.mathworks.com/matlabcentral/fileexchange/64653-tsp_ga_basic-nstops-popsize-numiter-xy), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
