function tsp_att48_test ( )

%*****************************************************************************80
%
%% tsp_att48_test() tests tsp_att48().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 June 2026
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../tsp_att48' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_att48_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test tsp_att48(), which returns the AT&T 48 city\n' );
  fprintf ( 1, '  traveling salesperson problem challenge data.\n' );

  n = 48;
  att48_order = tsp_att48_order ( );
  att48_xy = tsp_att48_xy ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  City coordinates:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    fprintf ( 1, '  %2d  (%8.4g  %8.4g)\n', i, att48_xy(i,1), att48_xy(i,2) );
  end
%
%  Report the tour length.
%
  from = att48_order(n);
  cost = 0.0;
  for i2 = 1 : n
    to   = att48_order(i2);
    cost = cost + norm ( att48_xy(to,:) - att48_xy(from,:) );
    from = to;
  end
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Tour length = %g\n', cost );
%
%  Copy the city locations in TSP order.
%
  x2 = zeros ( n, 2 );
 
  for i = 1 : n
    i2 = att48_order(i);
    x2(i,1:2) = att48_xy(i2,1:2);
  end
%
%  Display the locations.
%
  tsp_display ( "att48", n, x2 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_att48_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../tsp_att48' );

  return
end
function tsp_display ( prefix, n, x )

%*****************************************************************************80
%
%% tsp_display() plots cities and a tour connecting them.
%
%  Discussion:
%
%    If a "round trip" is desired, then the x2 array must repeat the
%    first city at the end.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 June 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string prefix: a string that defines the name of
%    the problem.  It is also used to create file names needed for
%    input to gnuplot().
%
%    integer n: the number of cities.
%
%    real x(n,2): the x and y coordinates of the cities.
%
  clf ( );
  hold ( 'on' );
    plot ( x(:,1), x(:,2), 'r-', 'LineWidth', 3 );
    plot ( x(:,1), x(:,2), 'm.', 'MarkerSize', 20 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  title ( prefix );
  filename = sprintf ( '%s.png', prefix );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  close ( );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the 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
