function matrix_chain_brute_test ( )

%*****************************************************************************80
%
%% matrix_chain_brute_test() tests matrix_chain_brute().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 June 2024
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../matrix_chain_brute' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'matrix_chain_brute_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test matrix_chain_brute().\n' );

  for test = 1 : 10

    if ( test == 1 )
      dims = [ 40, 20, 30, 10, 30 ];
    elseif ( test == 2 )
      dims = [ 1, 2, 3, 4, 3 ];
    elseif ( test == 3 )
      dims = [ 10, 20, 30 ];
    elseif ( test == 4 )
      dims = [ 10, 30, 5, 60 ];
    elseif ( test == 5 )
      dims = [ 10, 20 ];
    elseif ( test == 6 )
      dims = [ 40, 20, 0, 10, 30 ];
    elseif ( test == 7 )
      dims = [ 1, 100, 1, 100, 1 ];
    elseif ( test == 8 )
      dims = [ 100, 50, 1, 50, 100 ];
    elseif ( test == 9 )
      dims = [ 1, 50, 100, 50, 1 ];
    elseif ( test == 10 )
      dims = [ 4, 10, 3, 12, 20, 7 ];
    end

    n_dims = length ( dims );
    n_mats = n_dims - 1;
    n_mults = n_mats - 1;

    fprintf ( 1, '\n' );
    fprintf ( 1, '  Test #%d\n', test );
    fprintf ( 1, '  Number of dimensions =      %d\n', n_dims );
    fprintf ( 1, '  Number of matrices =        %d\n', n_mats );
    fprintf ( 1, '  Number of multiplications = %d\n', n_mults );
    fprintf ( 1, '  Matrix dimensions' );
    for i = 1 : n_dims
      fprintf ( 1, '  %2d', dims(i) );
    end
    fprintf ( 1, '\n' );
    parens = catalan_number ( n_mults );
    fprintf ( 1, '  Number of possible parenthesizations is %d\n', parens );
    perms = factorial ( n_mults );
    fprintf ( 1, '  Number of possible permutations is %d\n', perms );
    [ cost, p ] = matrix_chain_brute ( dims );
    fprintf ( 1, '  Minimal cost is %d\n', cost );
    fprintf ( 1, '  Multiplication order:' );
    for i = 1 : n_mults
      fprintf ( 1, '  %2d', p(i) );
    end
    fprintf ( 1, '\n' );

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

  rmpath ( '../matrix_chain_brute' );

  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 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

