function [ tsp_dist, tsp_trip ] = tsp_nearest ( dist, nearest )

  [ n, n ] = size ( dist );
  tsp_trip = zeros ( 1, n );
  dist2 = dist;
  
  for i = 1 : n

    here = nearest;
    dist2(1:n,here) = Inf;
    tsp_trip(i) = here;

    dmin = Inf;
    nearest = 0;

    for j = 1 : n
      if ( dist2(here,j) < dmin )
        dmin = dist2(here,j);
        nearest = j;
      end
    end

  end

  tsp_dist = trip_distance ( dist, tsp_trip );

  return
end
