function cvt_2d_lumping_test ( )

%*****************************************************************************80
%
%% CVT_2D_LUMPING_TEST tests CVT_2D_LUMPING.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 May 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../cvt_2d_lumping' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CVT_2D_LUMPING_TEST:\n' );
  fprintf ( 1, '  CVT_2D_LUMPING applies a certain number of iterations\n' );
  fprintf ( 1, '  to an initial set of N points in the unit square,\n' );
  fprintf ( 1, '  using a sampling approach to estimate centroids,\n' );
  fprintf ( 1, '  and a weight function which affects the centroids,\n' );
  fprintf ( 1, '  in an attempt to locate an arrangement of the points\n' );
  fprintf ( 1, '  that satisfies the CVT condition.\n' );
%
%  We are most interested in values of N that correspond to the number of
%  monomials in X and Y up to some degree, that is, values like 
%  N = 3, 6, 10, 15, 21, 28...
%
  for degree = 1 : 10

    n = ( ( degree + 1 ) * ( degree + 2 ) ) / 2;
    it_num = 100;
    s_num = 1000;
    init = 1;

    xy = cvt_2d_lumping ( n, it_num, s_num, @mu_2d_chebyzero, init );
%
%  Write values to a file.
%
    filename = sprintf ( 'generators_%03d.txt', n );
    unit = fopen ( filename, 'wt' );

    for i = 1 : n
      for j = 1 : 2
        fprintf ( unit, '  %g', xy(i,j) );
      end
      fprintf ( unit, '\n' );
    end
    fclose ( unit );
%
%  Plot the final configuration.
%
    figure ( )
    plot ( xy(:,1), xy(:,2), 'b.', 'Markersize', 15 );
    grid on
    title ( 'Generator locations:', 'Fontsize', 16 )
    filename = sprintf ( 'generators_%03d.png', n );
    print ( '-dpng', filename );

    figure ( )
    voronoi ( xy(:,1), xy(:,2) );
    title ( 'Voronoi diagram', 'Fontsize', 16 );
    filename = sprintf ( 'voronoi_%03d.png', n );
    print ( '-dpng', filename );

    figure ( )
    tri = delaunay ( xy(:,1), xy(:,2) );
    triplot ( tri, xy(:,1), xy(:,2) );
    title ( 'Delaunay diagram', 'Fontsize', 16 );
    filename = sprintf ( 'delaunay_%03d.png', n );
    print ( '-dpng', filename );

  end
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CVT_2D_LUMPING_TEST:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../cvt_2d_lumping' );

  return
end

