% SPDX-License-Identifier: MIT
% Copyright © 2021 Weiwei "William" Kong

function [summary_tables, comp_models] = run_benchmark(comp_model, solver_arr, solver_hparams_arr)
% A wrapper that runs several solvers on a user-provided CompModel object.
%
% Arguments:
%  
%   comp_model (CompModel): A CompModel object for running the solvers on
%
%   solver_arr ({function}): An array of solvers that correspond to the frameworks
%
%   solver_hparams_arr ({struct}): An array of solver hyperparameters (can be left empty)
% 
% Returns:
%
%   Two structs. The first contains some summary tables related to the execution of the method. The second contains some elements
%   related to the solutions generated by the algorithms
% 

  % Initialize
  if (length(solver_arr) ~= length(solver_hparams_arr))
    error('The number of solvers must equal the number of hyperparameters arrays when the latter is nonempty!');
  end
  n_solvers = length(solver_arr);
  summary_tables.runtime = [];
  
  % Run a routine for each algorithm
  for i=1:n_solvers
    solver = solver_arr{i};
    solver_name = func2str(solver);
    comp_model.solver = solver;
    if (~isempty(solver_hparams_arr))
      comp_model.solver_hparams = solver_hparams_arr{i};
    end
    comp_model.optimize;
    comp_models.(solver_name) = comp_model;
  end

end