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' );
%
%  It's not worth my time to try to beg Octave to read a CSV file properly.
%
  state = { ...
    'AL', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'ID', ...
    'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', ...
    'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', ...
    'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', ...
    'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY' };

  lat = [ ...
     32.361538,   ...
     33.448457,   ...
     34.736009,   ...
     38.555605,   ...
     39.7391667,  ...
     41.767,      ...
     39.161921,   ...
     30.4518,     ...
     33.76,       ...
     43.613739,   ...
     39.783250,   ...
     39.790942,   ...
     41.590939,   ...
     39.04,       ...
     38.197274,   ...
     30.45809,    ...
     44.323535,   ...
     38.972945,   ...
     42.2352,     ...
     42.7335,     ...
     44.95,       ...
     32.320,      ...
     38.572954,   ...
     46.595805,   ...
     40.809868,   ...
     39.160949,   ...
     43.220093,   ...
     40.221741,   ...
     35.667231,   ...
     42.659829,   ...
     35.771,      ...
     48.813343,   ...
     39.962245,   ...
     35.482309,   ...
     44.931109,   ...
     40.269789,   ...
     41.82355,    ...
     34.000,      ...
     44.367966,   ...
     36.165,      ...
     30.266667,   ...
     40.7547,    ...
     44.26639,    ...
     37.54,       ...
     47.042418,  ...
     38.349497,   ...
     43.074722,   ...
     41.145548 ];

  lon = [ ...
     -86.279118, ...
    -112.073844, ...
     -92.331122, ...
    -121.468926, ...
    -104.984167, ...
     -72.677, ...
     -75.526755, ...
     -84.27277, ...
     -84.39, ...
    -116.237651, ...
     -89.650373, ...
     -86.147685, ...
     -93.620866, ...
     -95.69, ...
     -84.86311, ...
     -91.140229, ...
     -69.765261, ...
     -76.501157, ...
     -71.0275, ...
     -84.5467, ...
     -93.094, ...
     -90.207, ...
     -92.189283, ...
    -112.027031, ...
     -96.675345, ...
    -119.753877, ...
     -71.549127, ...
     -74.756138, ...
    -105.964575, ...
     -73.781339, ...
     -78.638, ...
    -100.779004, ...
     -83.000647, ...
     -97.534994, ...
    -123.029159, ...
     -76.875613, ...
     -71.422132, ...
     -81.035, ...
    -100.336378, ...
     -86.784, ...
     -97.75, ...
    -111.892622, ...
     -72.57194, ...
     -77.46, ...
    -122.893077, ...
     -81.633294, ...
     -89.384444, ...
    -104.802042 ];
%
%  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, '  %2s  %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
