function tsp_dantzig42_test ( )

%*****************************************************************************80
%
%% tsp_dantzig42_test() tests tsp_dantzig42().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 July 2026
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../tsp_dantzig42' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_dantzig42_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test tsp_dantzig42(), which returns the Dantzig 42 city\n' );
  fprintf ( 1, '  traveling salesperson problem challenge data.\n' );

  n = 42;
  dantzig42_order = tsp_dantzig42_order ( );
  dantzig42_xy = tsp_dantzig42_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, dantzig42_xy(i,1), dantzig42_xy(i,2) );
  end
%
%  Copy the city locations in TSP order.
%
  x2 = zeros ( n + 1, 2 );
 
  for i2 = 1 : n + 1
    if ( i2 <= n )
      i = dantzig42_order(i2);
    else
      i = dantzig42_order(1);
    end
    x2(i2,1) = dantzig42_xy(i,1);
    x2(i2,2) = dantzig42_xy(i,2);
  end
%
%  Report the tour length.
%
  from = dantzig42_order(n);
  cost = 0.0;
  for i2 = 1 : n
    to   = dantzig42_order(i2);
    cost = cost + norm ( x2(to,:) - x2(from,:) );
    from = to;
  end
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Tour length = %g\n', cost );
%
%  Display the locations.
%
  tsp_display ( "dantzig42", n + 1, x2 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'tsp_dantzig42_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../tsp_dantzig42' );

  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
