function [Tour weight] = TSPNearInsertion(W,start) %[Tour weight] = TSPNearInsertion(W,start) %Program for the nearest insertion heuristic for the travelling salesman %problem. %Inputs: the price matrix W for a traveling salesman problem. Optional %second input variable start allows the user to prescribe the vertex number %for the start of the tour. %Outputs: A vector Tour containing a tour and its associated weight using the %nearest insertion heuristic. %Set start to default value 1 if not specified if nargin < 2, start =1; end [n m] = size(W);%n = m = number of vertices %Initialize Tour and vector of unused vertices Tour=[start]; REMAIN = setdiff(1:n,start); weight=0; %initialize weight while length(Tour)