⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sim_sizep.m

📁 best routing protocol
💻 M
字号:
function sim_sizep(instance, job_id)% job_id: %  >0  -- called in condor for specific jobs, never use it manually%  except for debugging!%  ==0 -- called by user: run all jobs without using condor% unspecified -- save consts and schedule condor jobs% ==-1 -- don't calculate. only process and plot!%run size experiment in parallel%this is different from sim_size in that each simulation uses a new%topology filefn = 'sim_sizep';MAX_JOBS = 100;if nargin==2  if job_id == -1    process_data(fn, instance)  else    get_raw_data(fn, instance, [job_id], MAX_JOBS)  end  returnendtotal_jobs = get_raw_data(fn, instance, [], MAX_JOBS)fid = fopen('condor.matlab','wt');if fid<0  error('could not open file');endfprintf(fid, '%s %s %d\n', fn, instance, min(total_jobs,MAX_JOBS));fclose(fid);! python gen_condor_jobs.pyfunction job_count = get_raw_data(fn, instance, job_ids, max_jobs)nodes_list = [100, 500, 1000,2000, 3000, 4000, 5000];repeat = 10;const_fn = sprintf('%s/%s-const.mat', instance, fn);if length(job_ids)==0 | ismember(0, job_ids)  const_fn = sprintf('%s/%s-const.mat', instance, fn);  save(const_fn, 'repeat', 'nodes_list','max_jobs','-V6');endload(const_fn); %make sure it's consistant between instancesjob_count = 0;%%%%%%%for i=1:repeat  for b=1:length(nodes_list)    job_count = job_count + 1;    if schedule_job(job_count, job_ids, max_jobs)      final_fn = sprintf('%s/%s-%d.mat', instance, fn, job_count);      fprintf('**job_id=%d**sim2 test num of nodes=%d, i=%d\n', job_count, nodes_list(b), i);      try	tmp=load(final_fn);	clear tmp	fprintf('**ALREADY DID job_id=%d**sim2 test nodes=%d, i=%d\n', job_count, nodes_list(b), i);      catch	topo=sprintf('%s/topo-size-%d-%d.mat',instance,nodes_list(b),i)	topology_generator(topo, nodes_list(b), 5.12, 0, 0, 0);	optimal = sim_optimal(topo);	res = simulation(topo, ceil(sqrt(nodes_list(b))));	save(final_fn ,'res','optimal');      end    end  endendfunction process_data(fn, instance)load(sprintf('%s/%s-const.mat', instance,fn))job_count = 0;for i=1:repeat  for p=1:length(nodes_list)    job_count = job_count + 1;    final_fn = sprintf('%s/%s-%d.mat', instance, fn, job_count);    TMP = load(final_fn);    res(p,i) = TMP.res;    optimal(p,i) = TMP.optimal;  endendsave(sprintf('%s/%s-all.mat',instance,fn));msz=12;for n=1:length(nodes_list)  clear stretch_bvr_sf_mean  for i=1:repeat    %size(res(n,i).transmission_dist_bvr_sf)    %size(optimal(n,i).optimal_dist)    stretch_bvr_sf_mean(i)=plot_routing_stretch( ...	res(n,i).transmission_dist_bvr_sf', optimal(n,i).optimal_dist, 'k',[-1],0);    if stretch_bvr_sf_mean(i)>100      n, i    end    stretch_bvr_2h_mean=plot_routing_stretch( ...	res(n,i).transmission_dist_bvr_2h', optimal(n,i).optimal_dist, 'k',[-1],0);    stretch_cr_mean=plot_routing_stretch( ...	res(n,i).routing_dist_cr, optimal(n,i).optimal_dist, 'k',[-1],0);  end  bvr_sf(n) = mean(stretch_bvr_sf_mean);  bvr_2h(n) = mean(stretch_bvr_2h_mean);  cr(n) = mean(stretch_cr_mean);  fprintf('# of nodes:%d, avg stretch %f\t%f\t%f\n', ...	  nodes_list(n),  ...	  mean(stretch_bvr_sf_mean), ...	  mean(stretch_bvr_2h_mean), ...	  mean(stretch_cr_mean));  endfigure(1)set(gca, 'FontSize',20);hold onplot(nodes_list, bvr_sf,'r-*','MarkerSize', msz);%plot(nodes_list, bvr_2h,'k-x','MarkerSize', msz);plot(nodes_list, cr,'b-o','MarkerSize', msz);%legend('BVR 1 hop', 'BVR 2 hop', 'S4',2);legend('BVR', 'S4',2);xlabel('number of nodes');ylabel('average transmission stretch');saveas(gcf, 'size_stretch.eps','psc2')%%%%%%%%%%%%%%%for n=1:length(nodes_list)  for i=1:repeat    state_cr(n,i)=mean(routing_state_cr(res(n,i)));    state_bvr(n,i) = mean(routing_state_bvr(res(n,i)));  endendfigure(2)set(gca, 'FontSize',20);hold onplot(nodes_list, mean(state_bvr,2),'r-*','MarkerSize', msz)plot(nodes_list, mean(state_cr,2),'b-o','MarkerSize', msz)legend('BVR', 'S4',2);xlabel('number of nodes N');ylabel('average routing state per node (Byte)');saveas(gcf, 'size_state.eps','psc2')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for n=1:length(nodes_list)  for i=1:repeat    [cr_setup(n,i), bvr_setup(n,1)] = setup_traffic(res(n,i));  endendfigure(3)set(gca, 'FontSize',20);hold ony = mean(cr_setup, 2);l = y - min(cr_setup,[], 2);u = max(cr_setup, [], 2) -y;errorbar(nodes_list, y, l, u,'o-b','MarkerSize', msz);plot(nodes_list, bvr_setup, 'x-r','MarkerSize', msz);legend('S4', 'BVR',2);xlabel('number of nodes N');ylabel('setup control traffic per node (Byte)');saveas(gcf, 'size_traffic.eps','psc2')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -