function [fin_sol, pos, sol, acer_tmp, eta] = Opt(proc, eta, ACER, CI, eta1, delta)

proc = proc(:)';
proc(isnan(proc)) = [];

condition = ( CI < (ACER)*delta );
% condition = updatecond(condition);
eta = eta(condition);
ACER = ACER(condition);
CI = CI(condition);
clear condition

condition = eta > eta1;
eta = eta(condition);
CI_tmp = CI(condition);
acer_tmp = ACER(condition);

CI_plus = acer_tmp + CI_tmp;
CI_minus = acer_tmp - CI_tmp;

W = (log(CI_plus)-log(CI_minus)).^(-2);
% Checking for all weights to be "positive" and "real"
pos_index = W>0;
real_index = imag(W)~=0;
if ~isempty(pos_index)
    %fprintf('Non-positive weights of the objective function changed to positive.\n')
    W = abs(W);
elseif ~isempty(real_index)
    %fprintf('Imaginary weights of the objective function changed to real.\n')
    W = abs(W);
end
% Normalizing weights to have sum(w)=1
W = W/sum(W);
clear pos_index real_index condition;

[q0, b0, a0, c0, ~] = guess(eta, eta1, proc, acer_tmp);
[~, ind] = min(abs(eta - mean2(proc)));
qMedian = acer_tmp(ind);

[fin_sol, ~, pos, sol] = Optimization(eta, ...
    acer_tmp, eta1, W, q0, b0, a0, c0, qMedian, min(min(proc)), 0.05, 'No');
% [fin_sol, ~, pos, sol] = Optimization_cutted(eta, ...
%     acer_tmp, eta1, W, q0, b0, a0, c0, qMedian, min(min(proc)), 0.05, 'No');


end