function tsp_moler_test ( )

%*****************************************************************************80
%
%% tsp_moler_test() tests tsp_moler().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 March 2023
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../tsp_moler' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_moler_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
%
%  Shuffle the random number generator.
%
  rng ( 'shuffle' );
%
%  Using readtable() and csv file format allows me to read the state 
%  abbreviations and latitudes and longitudes together.  
%  However, dealing with the output of readtable() is a little messy,
%  error prone and non-intuitive (but so is almost any attempt to
%  work with csv data).
%
  data = readtable ( 'state_capitals_48_ll.csv' );
  state = string ( data.Var1 );
  lat = data.Var2;
  lon = data.Var3;  
%
%  Verify that the data has been read correctly.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  First 5 latitudes and longitudes:\n' );
  for i = 1 : 5
    fprintf ( 1, '  %s  %12.4f  %12.4f\n',  state(i), lat(i), lon(i) );
  end
%
%  Compute the distance matrix.
%
  D = distances ( lon, lat );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  5x5 initial block of distance matrix\n' );
  disp ( D(1:5,1:5) );
%
%  Call the TSP solver.
%
  [ len, p ] = traveler ( D ); 
%
%  Report the results.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Length of path = %g\n', len );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Itinerary:\n' )
  fprintf ( 1, '  ');
  for i = 1 : length ( state )
    fprintf ( 1, '%s -> ', state(p(i)) );
    if ( mod ( i, 15 ) == 0 )
      fprintf ( 1, '\n' );
      fprintf ( 1, '  ');
    end
  end
  fprintf ( 1, '%s\n', state(p(1)) );
%
%  Give the mileages.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Mileage per leg:\n' )
  fprintf ( 1, '\n');
  for leg = 1 : length ( state )
    i = p(leg);
    j = p(leg+1);
    fprintf ( 1, '  %s -> %s  %g\n', state(i), state(j), D(i,j) );
  end
%
%  Plot (longitude,latitude) as (X,Y).
%
  clf ( );
  hold ( 'on' );
    plot ( lon, lat, 'bo', 'markersize', 10 );
    for leg = 1 : length ( state )
      i = p(leg);
      j = p(leg+1);
      x = [ lon(i), lon(j) ];
      y = [ lat(i), lat(j) ];
      plot ( x, y, 'r-' );
    end
    for i = 1 : length ( state )
      x = lon(i);
      y = lat(i);
      text ( x, y, state(i) );
    end
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Longitude -->' );
  ylabel ( '<-- Latitude -->' );
  filename = 'tsp_moler_test.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_moler_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../tsp_moler' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2022
%
%  Author:
%
%    John Burkardt
%
  t = now ( );
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end
