function knapsack_greedy_test01 ( )

%*****************************************************************************80
%
%% knapsack_greedy_test01() tests a greedy algorithm for the knapsack problem.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    29 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'knapsack_greedy_test01():\n' );
  fprintf ( 1, '  knapsack_greedy() uses a greedy algorithm to estimate a\n' );
  fprintf ( 1, '  solution of the knapsack problem.\n' );

  for test = 1 : 6

    if ( test == 1 )
      c = 165;
      n = 10;
      p = [  92,  57,  49,  68,  60,  43,  67,  84,  87,  72 ];
      w = [  23,  31,  29,  44,  53,  38,  63,  85,  89,  82 ];
    elseif ( test == 2 )
      c = 26;
      n = 5;
      p = [  24,  13,  23,  15,  16 ];
      w = [  12,   7,  11,   8,   9 ];
    elseif ( test == 3 )
      c = 190;
      n = 6;
      p = [  50,  50,  64,  46,  50,   5 ];
      w = [  56,  59,  80,  64,  75,  17 ];
    elseif ( test == 4 )
      c = 50;
      n = 7;
      p = [  70,  20,  39,  37,   7,   5,  10 ];
      w = [  31,  10,  20,  19,   4,   3,   6 ];
    elseif ( test == 5 )
      c = 104;
      n = 8;
      p = [ 350, 400, 450,  20,  70,   8,   5,   5 ];
      w = [  25,  35,  45,   5,  25,   3,   2,   2 ];
    elseif ( test == 6 )
      c = 67;
      n = 10;
      p = [ 505, 352, 458, 220, 354, 414, 498, 545, 473, 543 ];
      w = [  23,  26,  20,  18,  32,  27,  29,  26,  30,  27 ];
    end

    fprintf ( 1, '\n' );
    fprintf ( 1, '  Test %d\n', test );
    fprintf ( 1, '    Knapsack weight capacity is %d\n', c );
    fprintf ( 1, '    Object weights:\n' );
    disp ( w );
    fprintf ( 1, '    Object values:\n' );
    disp ( p );

    [ p, w ] = knapsack_reorder ( p, w );

    fprintf ( 1, '\n' );
    fprintf ( 1, '  Object  Profit    Mass    P/M\n' );
    fprintf ( 1, '\n' );
    for i = 1 : n
      fprintf ( 1, '  %6d  %6d  %6d  %g\n', i, p(i), w(i), p(i) / w(i) );
    end

    x = knapsack_greedy ( p, w, c );

    fprintf ( 1, '\n' );
    fprintf ( 1, '  Contents of Knapsack\n' );
    fprintf ( 1, '  Object  Profit    Mass    P/M\n' );
    fprintf ( 1, '\n' );

    chosen = 0;
    mass = 0;
    profit = 0;
    for i = 1 : n
      if ( x(i) == 1 )
        chosen = chosen + 1;
        mass = mass + w(i);
        profit = profit + p(i);
        fprintf ( 1, '  %6d  %6d  %6d  %g\n', i, p(i), w(i), p(i) / w(i) );
      end
    end
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Number of objects chosen = %d\n', chosen );
    fprintf ( 1, '  Total weight of chosen objects = %d\n', mass );
    fprintf ( 1, '  Total profit of chosen objects = %d\n', profit );

  end

  return
end
