function x = cplex_solution_multiple_read ( data )

%*****************************************************************************80
%
%% cplex_solution_multiple_read() reads a CPLEX multiple solution file.
%
%  Discussion:
%
%    When CPLEX determines multiple solutions to a problem, it returns a
%    solution structure which lists first the optimal solution, and then
%    all solutions.  This means the optimal solution shows up twice in
%    the structure.  We remove one of the two copies of the optimal solution
%    before returning the CPLEX information.
%
%    The information is returned as an array X(?,SOL_NUM);
%    Each column of X lists a solution vector.  
%    Each row of X lists the value of a given component for the given solution.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 June 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    struct DATA, the solution data structure.
%
%  Output:
%
%    real X(?,SOL_NUM), an array of solutions.
%

%
%  Get the number of solutions.
%
  sol_num = length ( data.CPLEXSolutions.CPLEXSolution );
%
%  CPLEX doesn't tell us the size of a solution vector, 
%  so start by setting first dimension of X to 1.
%
  x = zeros ( 1, sol_num );
%
%  Examine each solution.
%
  for sol_index = 1 : sol_num
%
%  Determine how many nonzero values are given in this solution.
%
    nonzero_num = length ( data.CPLEXSolutions.CPLEXSolution{1,sol_index}.variables.variable );
%
%  Read the name, index, and value for each nonzero entry.
%
    for nonzero_index = 1 : nonzero_num
      name = data.CPLEXSolutions.CPLEXSolution{1,sol_index}.variables.variable{nonzero_index}.Attributes.name;
      var_index = str2num ( name(2:end) );
      value = data.CPLEXSolutions.CPLEXSolution{1,sol_index}.variables.variable{nonzero_index}.Attributes.value;
      value = str2num ( value );
%
%  Save the data into X.
%
      x(var_index,sol_index) = value;

    end

  end
%
%  If the number of solutions was greater than 1, then the first solution
%  is redundant, since CPLEX lists the "best" solution first, then all the
%  solutions.
%
  if ( 1 < sol_num )
    x = x(:,2:sol_num);
    sol_num = sol_num - 1;
  end

  return
end
 
