MTSPOFS_GA Fixed Start Open Multiple Traveling Salesmen Problem (MTSP) Genetic Algorithm (GA)
Finds a (near) optimal solution to a variation of the "open" MTSP 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 without returning to the starting location)
Summary:
1. Each salesman starts at the first point, but travels to a unique
set of cities after that (and none of them close their loops by
returning to their starting points)
2. Except for the first, each city is visited by exactly one salesman
Note: The Fixed Start is taken to be the first XY point
Input:
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 citytocity 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
 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.
Output:
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 10 3 7], brks = [3 7]
Taken together, these represent the solution [1 5 6 9][1 4 2 8 10][1 3 7],
which designates the routes for the 3 salesmen as follows:
. Salesman 1 travels from city 1 to 5 to 6 to 9
. Salesman 2 travels from city 1 to 4 to 2 to 8 to 10
. Salesman 3 travels from city 1 to 3 to 7
Usage:
mtspofs_ga
or
mtspofs_ga(userConfig)
or
resultStruct = mtspofs_ga;
or
resultStruct = mtspofs_ga(userConfig);
or
[...] = mtspofs_ga('Param1',Value1,'Param2',Value2, ...);
Example:
% Let the function create an example problem to solve
mtspofs_ga;
Example:
% Request the output structure from the solver
resultStruct = mtspofs_ga;
Example:
% Pass a random set of userdefined XY points to the solver
userConfig = struct('xy',10*rand(35,2));
resultStruct = mtspofs_ga(userConfig);
Example:
% Pass a more interesting set of XY points to the solver
n = 50;
phi = (sqrt(5)1)/2;
theta = 2*pi*phi*(0:n1);
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 = mtspofs_ga(userConfig);
Example:
% Pass a random set of 3D (XYZ) points to the solver
xyz = 10*rand(35,3);
userConfig = struct('xy',xyz);
resultStruct = mtspofs_ga(userConfig);
Example:
% Change the defaults for GA population size and number of iterations
userConfig = struct('popSize',200,'numIter',1e4);
resultStruct = mtspofs_ga(userConfig);
Example:
% Turn off the plots but show a waitbar
userConfig = struct('showProg',false,'showResult',false,'showWaitbar',true);
resultStruct = mtspofs_ga(userConfig);
1.5.0.0  Major overhaul of input/output interface. 

1.4.0.0  Removed waitbar. 

1.3.0.0  Corrected the route/break details in the comment section. 

1.2.0.0  Bug fix. Minor cosmetic updates. 

1.1.0.0  Added 3D capability. 

1.0.0.0  Removed the SINGLES parameter and replaced it with a more generalized MIN_TOUR 
Inspired by: Multiple Traveling Salesmen Problem  Genetic Algorithm
Create scripts with code, output, and formatted text in a single executable document.
Skybeat (view profile)
Hi Joseph,
Thanks for this code. This is very close to my problem. I like to use your code to solve a Multiobjective problem. Do you know that if I can modify it and use multiobjective Genetic Algorithm? I am not sure if it is your own GA algorithm or you used Matlab's GA?
Stefan D. (view profile)
Hi Joseph,
Thanks for your contribution. I would like to implement an algorithm in order that the paths do not cross each other. Do you have any idea how could I approach this?
Joseph Kirk (view profile)
@Jia, "popSize" must be divisible by 8 because of the way good solutions in the current population are propagated to the next iteration. (I randomly group 8 citizens at a time, take the best one of those eight, and pass it on to the next generation. I then perform 3 different mutations on that bestof8 citizen: flip, swap, and slide. I then make copies of the bestof8 and 3 mutated versions and mix up the length of the salesmen routes for each. The 7 modified solutions are then passed on to the next generation)
Jia Guo (view profile)
What is popsize? Why is it divisible by 8?
shahram taghipour (view profile)
mina (view profile)
hi. i want to make a WSN and implement one of the intelligent routing protocols on it.for start i dont know how to simulate a WSN. would anyone help me or send me anything helpful?
thank you
Tom (view profile)
Joseph,
This is excellent and very close to the exact problem I would like to solve. My problem involves cable laying and cable routes I wanted to ask how hard / how would you implement the following two things?
1. In my problem the routes cannot cross paths. Each route must start from one city and go to the other cities but must not cross the path of any other route.
2. In my problem the cost of each leg of the route is slightly different. So for example the first leg of the route may cost 100% of the value in dmax but the second costs 125% and the third 150% etc. I don’t think I can implement this into the dmax input as I don’t know which distance / cost will be the first / second leg.
Any feedback on this would be much appreciated!
Thanks
Tom
Iain (view profile)
Joseph,
This is excellent and very close to the exact problem I would like to solve. My problem involves cable laying and cable routes I wanted to ask how hard / how would you implement the following two things?
1. In my problem the routes cannot cross paths. Each route must start from one city and go to the other cities but must not cross the path of any other route.
2. In my problem the cost of each leg of the route is slightly different. So for example the first leg of the route may cost 100% of the value in dmax but the second costs 125% and the third 150% etc. I don’t think I can implement this into the dmax input as I don’t know which distance / cost will be the first / second leg.
Any feedback on this would be much appreciated!
Thanks
Iain
Update: The SINGLES parameter has been replaced with a more generalized MIN_TOUR.