Code covered by the BSD License  

Highlights from
Fixed Start Open Traveling Salesman Problem - Genetic Algorithm

Be the first to rate this file! 22 Downloads (last 30 days) File Size: 3.24 KB File ID: #21198
image thumbnail

Fixed Start Open Traveling Salesman Problem - Genetic Algorithm

by Joseph Kirk

 

23 Aug 2008 (Updated 07 Nov 2011)

Finds a near-optimal solution to a "open" variation of the TSP with fixed start points using a GA

| Watch this File

File Information
Description

TSPOFS_GA Fixed Start Open Traveling Salesman Problem (TSP) Genetic Algorithm (GA)
Finds a (near) optimal solution to a variation of the TSP by setting up a GA to search for the shortest route (least distance for the salesman to travel from a FIXED START to the other cities exactly once without returning to the starting city)

Summary:
1. A single salesman starts at the first point and travels to each of the remaining cities but does not close the loop by returning to the city he started from
2. Each city is visited by the salesman exactly once

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

Input:
XY (float) is an Nx2 (or Nx3) matrix of cities
DMAT (float) is an NxN matrix of point to point distances/costs
POPSIZE (scalar integer) is the size of the population (should be divisible by 4)
NUM_ITER (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

Output:
OPTRTE (integer array) is the best route found by the algorithm
MINDIST (scalar float) is the cost of the best route

Example:
n = 50;
xy = 10*rand(n,2);
popSize = 60;
numIter = 1e4;
showProg = 1;
showResult = 1;
a = meshgrid(1:n);
dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);
[optRoute,minDist] = tspofs_ga(xy,dmat,popSize,numIter,showProg,showResult);

Example:
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]));
popSize = 60;
numIter = 1e4;
showProg = 1;
showResult = 1;
a = meshgrid(1:n);
dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);
[optRoute,minDist] = tspofs_ga(xy,dmat,popSize,numIter,showProg,showResult);

Example:
n = 50;
xyz = 10*rand(n,3);
popSize = 60;
numIter = 1e4;
showProg = 1;
showResult = 1;
a = meshgrid(1:n);
dmat = reshape(sqrt(sum((xyz(a,:)-xyz(a',:)).^2,2)),n,n);
[optRoute,minDist] = tspofs_ga(xyz,dmat,popSize,numIter,showProg,showResult);

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Traveling Salesman Problem - Genetic Algorithm

Required Products MATLAB
MATLAB release MATLAB 7.12 (2011a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
02 Sep 2008

updated help notes, description

02 Jun 2009

Added 3D capability.

07 Nov 2011

Minor cosmetic updates.

Tag Activity for this File
Tag Applied By Date/Time
optimization Joseph Kirk 22 Oct 2008 10:15:48
traveling salesman problem Joseph Kirk 22 Oct 2008 10:15:48
tsp Joseph Kirk 22 Oct 2008 10:15:48
open variation Joseph Kirk 22 Oct 2008 10:15:48
fixed start Joseph Kirk 22 Oct 2008 10:15:48

Contact us at files@mathworks.com