File Exchange

image thumbnail

Fixed Endpoints Open Multiple Traveling Salesmen Problem - Genetic Algorithm

version (14.7 KB) by Joseph Kirk
Finds a near-optimal solution to a "open" variation of the M-TSP with fixed endpoints using a GA


Updated 06 May 2014

View License

MTSPOF_GA Fixed Open Multiple Traveling Salesmen Problem (M-TSP) Genetic Algorithm (GA)
Finds a (near) optimal solution to a variation of the "open" M-TSP by
setting up a GA to search for the shortest route (least distance needed
for each salesman to travel from the start location to unique
individual cities and finally to the end location)
1. Each salesman starts at the first point, and ends at the last
point, but travels to a unique set of cities in between (none of
them close their loops by returning to their starting points)
2. Except for the first and last, each city is visited by exactly one salesman

Note: The Fixed Start is taken to be the first XY point and the Fixed End
is taken to be the last XY point

USERCONFIG (structure) with zero or more of the following fields:
- XY (float) is an Nx2 matrix of city locations, where N is the number of cities
- DMAT (float) is an NxN matrix of city-to-city distances or costs
- NSALESMEN (scalar integer) is the number of salesmen to visit the cities
- MINTOUR (scalar integer) is the minimum tour length for any of the
salesmen, NOT including the start point or end point
- POPSIZE (scalar integer) is the size of the population (should be divisible by 8)
- NUMITER (scalar integer) is the number of desired iterations for the algorithm to run
- SHOWPROG (scalar logical) shows the GA progress if true
- SHOWRESULT (scalar logical) shows the GA results if true
- SHOWWAITBAR (scalar logical) shows a waitbar if true

Input Notes:
1. Rather than passing in a structure containing these fields, any/all of
these inputs can be passed in as parameter/value pairs in any order instead.
2. Field/parameter names are case insensitive but must match exactly otherwise.

RESULTSTRUCT (structure) with the following fields:
(in addition to a record of the algorithm configuration)
- OPTROUTE (integer array) is the best route found by the algorithm
- OPTBREAK (integer array) is the list of route break points (these specify the indices
into the route used to obtain the individual salesman routes)
- MINDIST (scalar float) is the total distance traveled by the salesmen

Route/Breakpoint Details:
If there are 10 cities and 3 salesmen, a possible route/break
combination might be: rte = [5 6 9 4 2 8 3 7], brks = [3 7]
Taken together, these represent the solution [1 5 6 9 10][1 4 2 8 3 10][1 7 10],
which designates the routes for the 3 salesmen as follows:
. Salesman 1 travels from city 1 to 5 to 6 to 9 to 10
. Salesman 2 travels from city 1 to 4 to 2 to 8 to 3 to 10
. Salesman 3 travels from city 1 to 7 to 10

resultStruct = mtspof_ga;
resultStruct = mtspof_ga(userConfig);
[...] = mtspof_ga('Param1',Value1,'Param2',Value2, ...);

% Let the function create an example problem to solve

% Request the output structure from the solver
resultStruct = mtspof_ga;

% Pass a random set of user-defined XY points to the solver
userConfig = struct('xy',10*rand(35,2));
resultStruct = mtspof_ga(userConfig);

% Pass a more interesting set of XY points to the solver
n = 50;
phi = (sqrt(5)-1)/2;
theta = 2*pi*phi*(0:n-1);
rho = (1:n).^phi;
[x,y] = pol2cart(theta(:),rho(:));
xy = 10*([x y]-min([x;y]))/(max([x;y])-min([x;y]));
userConfig = struct('xy',xy);
resultStruct = mtspof_ga(userConfig);

% Pass a random set of 3D (XYZ) points to the solver
xyz = 10*rand(35,3);
userConfig = struct('xy',xyz);
resultStruct = mtspof_ga(userConfig);

% Change the defaults for GA population size and number of iterations
userConfig = struct('popSize',200,'numIter',1e4);
resultStruct = mtspof_ga(userConfig);

% Turn off the plots but show a waitbar
userConfig = struct('showProg',false,'showResult',false,'showWaitbar',true);
resultStruct = mtspof_ga(userConfig);

Comments and Ratings (6)

Joseph Kirk

@Siyabonga, the (default) fitness function is the total distance each salesman travels.

were you able to find the start and end of the salesman? What is your fitness function in this case?

Joseph Kirk

@amir, I have a couple variations that are not available on the file exchange. Send me an email (via the contact form on my author page) and we can determine if I have anything that matches your case.

amir soheil

i mean how can be possible add define different start end points for every salesmen


In addition to the previous, is it also possible to include planitairity in the optimization. This means no crossing of the lines. And a third question is if it is possible to include a third dimension, such as a bathymetry to calculate the shortest routes

The Author

Update: The SINGLES parameter has been replaced with a more generalized MIN_TOUR.


Major overhaul of input/output interface.

Removed waitbar.

Corrected the route/break details in the comment section.

Bug fix. Minor cosmetic updates.

Added 3D capability.

Removed the SINGLES parameter and replaced it with a more generalized MIN_TOUR

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux