You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ess_kernel.m
    path of file: ./repos/d2d/arFramework3/ThirdParty/strike-goldd/STRIKE-GOLDD/MEIGO64/MEIGO/eSS
    
    the code of the file until where you have to start completion: 
function [Results]=ess_kernel(problem,opts,varargin)
% 
    
function value: %g \n', sol_val_pen(1));
    end
end
%%

%Initialize Refset
Refset=zeros(dim_refset,nvar);
Refset_values=zeros(dim_refset,1);
Refset_values_penalty=zeros(dim_refset,1);
Refset_nlc=[];
penalty=[];


[aaa, iii]=sort(sol_val_pen);
first_members=ceil(dim_refset/2);
last_members=dim_refset-first_members;


%Create the initial sorted Refset

Refset=sol(iii(1:first_members),:);
Refset_values=sol_val(iii(1:first_members));
Refset_values_penalty=sol_val_pen(iii(1:first_members));
penalty=sol_pen(iii(1:first_members));
Refset_nlc=sol_nlc(iii(1:first_members),:);

%The rest of Refset members are chosen randomly
iii(1:first_members)=[];
ooo=randperm(length(iii));
%ooo=randperm(ndiverse+2+size(x_0,1)-first_members);

Refset=[Refset; sol(iii(ooo(1:last_members)),:)];
Refset_values=[Refset_values; sol_val(iii(ooo(1:last_members)))];
Refset_values_penalty=[Refset_values_penalty; sol_val_pen(iii(ooo(1:last_members)))];
penalty=[penalty; sol_val_pen(iii(ooo(1:last_members)))];
Refset_nlc=[Refset_nlc; sol_nlc(iii(ooo(1:last_members)),:)];

%Check best value
ggg=find(penalty<=tolc);
if not(isempty(ggg))
    [fbest,iii]=min(Refset_values_penalty(ggg));
    xbest=Refset((ggg(iii)),:);
end