%% setting the marker size and line width
MarkerSize=6;
LineWidth=2;
l=-11;
r=8;
n=20242;
ddd=1200;
font1=17;
font2=14;
font3=18;
figure1 = figure(1011);
kkk=10;
d=floor(n/25);
idxx=[0:d:n];
if idxx(end)<n
    idxx=[idxx n];
end
hold on;
%% GD
corl=[0, 128, 128];
h4=plot(info_gd.time,log(info_gd.optgap),'--<','color',corl/255.0,'LineWidth',LineWidth,...
    'MarkerEdgeColor',corl/255.0,...
    'MarkerFaceColor',corl/255.0,...
    'MarkerSize',MarkerSize);

%% compute the index of SGD
our_idx=zeros(length(idxx),1);
for ii=1:length(idxx)
    [~,id]=min(abs(info_sgd.time-idxx(ii)));
    our_idx(ii)=id;
end
our_idx=unique([our_idx; length(info_sgd.time)]);
hold on;
h2=plot(info_sgd.time(our_idx),log(info_sgd.optgap(our_idx)),'-h','color',[19,155,71]/255.0,'LineWidth',LineWidth,...
    'MarkerEdgeColor',[19,155,71]/255.0,...
    'MarkerFaceColor',[19,155,71]/255.0,...
    'MarkerSize',MarkerSize);

%% compute the index of HSGD
our_idx=zeros(length(idxx),1);
for ii=1:length(idxx)
    [~,id]=min(abs(info_persgd.time-idxx(ii)));
    our_idx(ii)=id;
end
our_idx=unique([our_idx; length(info_persgd.time)]);
hold on;
h1=plot(info_persgd.time(our_idx),log(info_persgd.optgap(our_idx)),'-d','color','r','LineWidth',LineWidth,...
    'MarkerEdgeColor','r',...
    'MarkerFaceColor','r',...
    'MarkerSize',MarkerSize);


hold on;
set(gca,'fontsize',font2,'FontWeight','Bold');
box on;
hold on;
[hh,icons,plots,legend_text]=legend('FG-HT','SG-HT','HSG-HT');
set(hh,'Fontsize',font1,'FontWeight','Bold');
xlabel('#IFO','FontWeight','Bold','FontSize',font1);
ylabel('Objective Distance log(f - f^*)','FontWeight','Bold','FontSize',font1);


hold on;
markersize=8;
linewidth=2;
s=get(legend);
s1=s.Children;
s2=[];
s2=findobj(s1,{'type','patch','-or','type','line'});
for m=1:length(s2)
    set(s2(m),'markersize', 8, 'linewidth', 3);
end
ylim([l,r])
xlim([-0.001,n+ddd])

xticks = get(gca, 'xtick');
labels={'0','5000','10000','15000','20000'};
set(gca, 'xtick', xticks, 'xticklabel', labels)
set(gcf,'Position',[0 0 500 405]);

