function x = cplex_solution_read ( filename )

%*****************************************************************************80
%
%% cplex_solution_read() reads a CPLEX solution file.
%
%  Discussion:
%
%    The structure of the CPLEX solution file varies depending on whether
%    CPLEX found just one, or several solutions.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 February 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    IBM ILOG CPLEX Optimization Studio,
%    Getting Started with CPLEX,
%    https://www.ibm.com/docs/en/SSSA5P_12.8.0/ilog.odms.studio.help/pdf/gscplex.pdf
%
%    IBM ILOG CPLEX Optimization Studio,
%    CPLEX User's Manual,
%    https://www.ibm.com/docs/en/SSSA5P_12.8.0/ilog.odms.studio.help/pdf/usrcplex.pdf
%
%  Input:
%
%    string FILENAME, the file containing the data.
%
%  Output:
%
%    real X(*,SOL_NUM), an array of solutions.
%

%
%  Copy the XML data into a MATLAB struct.
%
  data = xml2struct ( filename );
%
%  Determine whether this file contains one, or multiple solutions.
%
  if ( isfield ( data, 'CPLEXSolutions' ) )
    x = cplex_solution_multiple_read ( data );
  else
    x = cplex_solution_single_read ( data );
  end
%
%  We know that our solution vectors can only have nonnegative integer values.
%
%  In some cases, CPLEX might return a solution X with values -0, or with
%  a tiny nonzero value.  Presumably, these are meaningless, but we must 
%  reset them to 0 (or, in general, integer values) so as not to confuse
%  the plotting code which checks for zero/nonzero values.
%
  x = abs ( x );

  x = round ( x );

  return
end

