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

📄 sim_parallel.m

📁 best routing protocol
💻 M
📖 第 1 页 / 共 2 页
字号:
function sim_parallel(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!%supported instances:% high_density% low_density% high_dhtfn = 'sim_parallel';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)if strcmp(instance,'high_density')  topo = 'topo-3200-5.12v6.mat';  n_beacons =[10, 20, 30, 56, 80, 100]elseif strcmp(instance,'low_density')  topo = 'topo-3200-3v6.mat';  n_beacons =[10, 20, 30, 56, 80, 100]elseif strcmp(instance,'very_low')  topo = 'topo-1000.mat';  n_beacons =[ 8, 16, 24, 32, 40]elseif strcmp(instance,'high_dht')  topo = 'topo-3200-5.12v6.mat';  n_beacons =[10, 20, 30, 56, 80, 100]else  error('unknown topo file');  %topo = 'topo-100-5.12-0.1.mat';endrepeat = 10;%repeat = 1;%n_beacons =[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', 'n_beacons','topo','max_jobs','-V6');endload(const_fn); %make sure it's consistant between instancesjob_count = 0;S = load(topo);%%%%%%% hetergeneous jobs.. :) the first one is optimaljob_count = job_count + 1;if schedule_job(job_count, job_ids, max_jobs)  fprintf('job 1\n');  [optimal_dist optimal_nexthop] = allpair_dijkstra(S.D, ...						    1:S.n_nodes, 1, ...						    'optimal-cache.mat');  load_optimal = get_nexthop_load(optimal_nexthop, S.random_pairs);  final_fn = sprintf('%s/%s-%d.mat', instance, fn, job_count);  save(final_fn, 'optimal_dist','load_optimal');end%%%%%%%for i=1:repeat  for b=1:length(n_beacons)    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 beacon=%d, i=%d\n', job_count, n_beacons(b), i);      try	tmp=load(final_fn);	clear tmp	fprintf('**ALREADY DID job_id=%d**sim2 test beacon=%d, i=%d\n', job_count, n_beacons(b), i);      catch	if strcmp(instance,'high_dht')	  res = sim_with_dht(topo, n_beacons(b));	elseif strcmp(instance,'very_low')	  res = simulation(topo, n_beacons(b), 1);	else	  res = simulation(topo, n_beacons(b));	end	save(final_fn ,'res');      end    end  endendfunction process_data(fn, instance)load(sprintf('%s/%s-const.mat', instance,fn))job_count = 1;load(sprintf('%s/%s-1.mat', instance, fn))for i=1:repeat  for p=1:length(n_beacons)    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;  endendsave(sprintf('%s/%s-all.mat',instance,fn));if strcmp(instance,'high_dht')  sim_dht  returnendif strcmp(instance,'low_density')  sim_density   % don't need to keep running and OVERWRITE the figures  returnend%%%for high_density and low_densitymsz = 12; %MarkerSizefontsize = 15;INTERVAL=2;%n_beacons =[10, 20, 56, 80, 100]%repeat = 10;topoS = load(topo);n_beacons%%%%figure 1.a routing success ratefor i=1:repeat  for b=1:length(n_beacons)    failure_bvr(b,i) = res(b,i).failure_bvr;    failure_bvr_2h(b,i) = res(b,i).failure_bvr_2h;  endendfigure(1)set(gca, 'FontSize',fontsize);hold onplot_errorbar(failure_bvr, n_beacons-0.5, 'x-r', msz,1);plot_errorbar(failure_bvr_2h, n_beacons+0.5, 'v-k', msz,1);plot(n_beacons, zeros(1, length(n_beacons)),'o-b', 'MarkerSize', msz)xlabel('number of beacons K');ylabel('routing failure rate');ylim([0 0.35]);legend('BVR w/o flooding', 'BVR 2 hop neighbor w/o flooding', 'S4');saveas(gcf, 'failure_rate.eps','psc2')%%%%%figure 1.b routing stretch vs Kpair_indices = S.random_pairs(:,1)+(S.random_pairs(:,2)-1)*S.n_nodes;optimal_dist = optimal_dist(pair_indices);fprintf('average optimal distance:%.2f\n',mean(optimal_dist));failure_opt = length(find(optimal_dist==Inf))/S.n_random_pairs;figure(10)set(gca, 'FontSize',fontsize);hold oncolors_bvr=['k--';'   ';'k--';'k-.'];colors_bvr_nf=['r--';'   ';'r--';'r-.'];colors_bvr_rate=['g  ';'   ';'   ';'g--'];colors_cr=['b ';'  ';'  ';'b:'];for b =1:length( n_beacons)  for i=1:repeat    routing_dist_bvr_sf(:,i)=res(b,i).routing_dist_bvr_sf;    routing_dist_bvr_nf(:,i)=res(b,i).routing_hops_sf;    routing_dist_cr(:,i)=res(b,i).routing_dist_cr;    routing_dist_bvr_2h(:,i)=res(b,i).routing_dist_bvr_2h;    routing_dist_bvr_2hnf(:,i)=res(b,i).routing_hops_2h;  end  if ismember(b, [1 4])    worst_bvr(b) = plot_routing_stretch(routing_dist_bvr_sf, optimal_dist, colors_bvr(b,:),[100],1);    worst_cr(b) = plot_routing_stretch(routing_dist_cr, optimal_dist, ...				       colors_cr(b,:),[100],1);    worst_bvr_nf(b) = plot_routing_stretch(routing_dist_bvr_nf, ...					   optimal_dist, colors_bvr_nf(b,:), ...					   [100],1,1);  end  avg_routing_stretch_bvr_sf(b) = plot_routing_stretch(...      routing_dist_bvr_sf, optimal_dist,'',[-1],0,0);  avg_routing_stretch_bvr_nf(b) = plot_routing_stretch(...      routing_dist_bvr_nf, optimal_dist,'',[-1],0,1);  avg_routing_stretch_cr(b) = plot_routing_stretch(...      routing_dist_cr, optimal_dist,'',[-1],0,0);  avg_routing_stretch_bvr_2h(b) = plot_routing_stretch(...      routing_dist_bvr_2h, optimal_dist,'',[-1],0,0);  avg_routing_stretch_bvr_2hnf(b) = plot_routing_stretch(...      routing_dist_bvr_2hnf, optimal_dist,'',[-1],0,1);  %plot_routing_stretch(transmission_dist_bvr_2h, optimal_dist, 'r',[],1);  tmp = mean(failure_bvr,2);  %plot([1 6],[1-tmp(b), 1-tmp(b)],colors_bvr_rate(b,:));endbvr_str1 = sprintf('BVR w/ flooding. K=10, worst stretch=%.1f',worst_bvr(1));bvr_str2 = sprintf('BVR w/ flooding. K=56, worst stretch=%.1f',worst_bvr(4));bvr_nf_str1 = sprintf('BVR w/o flooding. K=10, worst stretch=%.1f',worst_bvr_nf(1));bvr_nf_str2 = sprintf('BVR w/o flooding. K=56, worst stretch=%.1f',worst_bvr_nf(4));cr_str1 = sprintf('S4. K=10, worst stretch=%.1f',worst_cr(1));cr_str2 = sprintf('S4. K=56, worst stretch=%.1f',round(worst_cr(4)));%legend(bvr_str1, cr_str1,bvr_nf_str1, 'BVR success rate K=10', ...%       bvr_str2, ...%       cr_str2, bvr_nf_str2,'BVR success rate K=56',0);legend(bvr_str1, cr_str1,bvr_nf_str1,  ...       bvr_str2, ...       cr_str2, bvr_nf_str2,4);xlabel('routing stretch');ylabel('CDF');xlim([1 3])saveas(gcf, 'rstretch_normal.eps','psc2')figure(21)hold onset(gca, 'FontSize',fontsize);plot(n_beacons, avg_routing_stretch_cr, 'o-b', 'MarkerSize', msz);plot(n_beacons, avg_routing_stretch_bvr_nf, '+-r', 'MarkerSize', msz);plot(n_beacons, avg_routing_stretch_bvr_sf, 'x:r', 'MarkerSize', msz);plot(n_beacons, avg_routing_stretch_bvr_2hnf, 'v-k', 'MarkerSize', msz);plot(n_beacons, avg_routing_stretch_bvr_2h, '<:k', 'MarkerSize', msz);xlabel('number of beacons K');ylabel('average routing stretch');legend('S4','BVR no flooding','BVR w/ flooding','BVR 2-hop no flooding',...       'BVR 2-hop w/ flooding');saveas(gcf, 'avg_routing_stretch.eps', 'psc2');%%%%%%%%%%%%%%%%%%%%routing stretch 2 hop NEWfigure(11)set(gca, 'FontSize',fontsize);hold oncolors_bvr=['k--';'   ';'k--';'k-.'];colors_bvr_nf=['r--';'   ';'r--';'r-.'];colors_bvr_rate=['g  ';'   ';'   ';'g--'];colors_cr=['b ';'  ';'  ';'b:'];for b = [1,4]  for i=1:repeat    routing_dist_bvr_2h(:,i)=res(b,i).routing_dist_bvr_2h;    routing_dist_bvr_sf(:,i)=res(b,i).routing_dist_bvr_sf;    routing_dist_bvr_nf(:,i)=res(b,i).routing_hops_sf;    routing_dist_cr(:,i)=res(b,i).routing_dist_cr;  end  worst_bvr(b) = plot_routing_stretch(routing_dist_bvr_2h, optimal_dist, colors_bvr(b,:),[100],1);  worst_cr(b) = plot_routing_stretch(routing_dist_cr, optimal_dist, ...  				 colors_cr(b,:),[100],1);  %plot_routing_stretch(transmission_dist_bvr_2h, optimal_dist, 'r',[],1);  tmp = mean(failure_bvr,2);  %plot([1 6],[1-tmp(b), 1-tmp(b)],colors_bvr_rate(b,:));endbvr_str1 = sprintf('BVR 2hop w/ flooding. K=10, worst stretch=%.1f',worst_bvr(1));bvr_str2 = sprintf('BVR 2hop w/ flooding. K=56, worst stretch=%.1f',worst_bvr(4));cr_str1 = sprintf('S4. K=10, worst stretch=%.1f',worst_cr(1));cr_str2 = sprintf('S4. K=56, worst stretch=%.1f',round(worst_cr(4)));%legend(bvr_str1, cr_str1,bvr_nf_str1, 'BVR success rate K=10', ...%       bvr_str2, ...%       cr_str2, bvr_nf_str2,'BVR success rate K=56',0);legend(bvr_str1, cr_str1, ...       bvr_str2, ...       cr_str2, 4);xlabel('average routing stretch');ylabel('CDF');xlim([1 3])saveas(gcf, '2hoprstretch_normal.eps','psc2')%%%%%distance vs stretch%%%%%%%%%figure(31)hold onset(gca, 'FontSize',fontsize);b=4;clear routing_dist_bvr_sffor i=1:repeat  routing_dist_bvr_sf(:,i) = res(b,i).routing_dist_bvr_sf;  routing_dist_cr(:,i) = res(b,i).routing_dist_cr;  %routing_dist_bvr_sf(:,i) = res(b,i).transmission_dist_bvr_sf;  %routing_dist_cr(:,i) = res(b,i).routing_dist_cr;endplot_stretch_by_distance(routing_dist_bvr_sf, optimal_dist, 'r-x', ...			 'relative', msz-3)plot_stretch_by_distance(routing_dist_cr, optimal_dist, 'b-o','relative',msz-3)xlabel('optimal routing distance (hops)')ylabel('routing stretch')legend('BVR','S4')saveas(gcf, 'dist_stretch.eps','psc2')xlim([1 43])figure(32)hold onset(gca, 'FontSize',fontsize);plot_stretch_by_distance(routing_dist_bvr_sf, optimal_dist, 'r-x', ...			 'abs', msz-3)plot_stretch_by_distance(routing_dist_cr, optimal_dist, 'b-o', 'abs', ...			 msz-3)xlabel('optimal routing distance (hops)')ylabel('absolute routing distance error (hops) ')legend('BVR','S4',2)saveas(gcf, 'dist_abs_stretch.eps','psc2')xlim([1 43])%%%%%figure 1.b transmission stretch vs K%pair_indices = S.random_pairs(:,1)+(S.random_pairs(:,2)-1)*S.n_nodes;%optimal_dist = optimal_dist(pair_indices);%failure_opt = length(find(optimal_dist==Inf))/S.n_random_pairs;figure(2)set(gca, 'FontSize',fontsize);hold oncolors_bvr=['k--';'   ';'k--';'k-.'];colors_bvr_rate=['g  ';'   ';'   ';'g--'];colors_cr=['b ';'  ';'  ';'b:'];for b = 1:length(n_beacons)  for i=1:repeat    transmission_dist_bvr_2h(:,i)=res(b,i).transmission_dist_bvr_2h;    transmission_dist_bvr_sf(:,i)=res(b,i).transmission_dist_bvr_sf;    transmission_dist_cr(:,i)=res(b,i).routing_dist_cr;  end  if ismember(b, [1 4])    worst_bvr(b) = plot_routing_stretch(transmission_dist_bvr_sf, optimal_dist, colors_bvr(b,:),[100],1);    worst_cr(b) = plot_routing_stretch(transmission_dist_cr, optimal_dist, ...				       colors_cr(b,:),[100],1);    tmp = mean(failure_bvr,2);    plot([1 6],[1-tmp(b), 1-tmp(b)],colors_bvr_rate(b,:));  end  avg_tran_stretch_bvr_sf(b)=plot_routing_stretch(...      transmission_dist_bvr_sf, optimal_dist, '',[-1],0);  avg_tran_stretch_bvr_2h(b)=plot_routing_stretch(...      transmission_dist_bvr_2h, optimal_dist, '',[-1],0);  avg_tran_stretch_cr(b)=plot_routing_stretch(...      transmission_dist_cr, optimal_dist, '',[-1],0);  %plot_routing_stretch(transmission_dist_bvr_2h, optimal_dist, 'r',[],1);endbvr_str1 = sprintf('BVR w/ flooding. K=10, worst stretch=%.1f',worst_bvr(1));bvr_str2 = sprintf('BVR w/ flooding. K=56, worst stretch=%.1f',worst_bvr(4));cr_str1 = sprintf('S4. K=10, worst stretch=%.1f',worst_cr(1));cr_str2 = sprintf('S4. K=56, worst stretch=%.1f',round(worst_cr(4)));legend(bvr_str1, cr_str1, 'BVR success rate K=10', ...       bvr_str2, ...       cr_str2, 'BVR success rate K=56',0);xlabel('transmission stretch');ylabel('CDF');xlim([1 6])saveas(gcf, 'stretch_normal.eps','psc2')figure(22)hold onset(gca, 'FontSize',fontsize);plot(n_beacons, avg_tran_stretch_cr, 'o-b', 'MarkerSize', msz);plot(n_beacons, avg_tran_stretch_bvr_sf, 'x-r', 'MarkerSize', msz);plot(n_beacons, avg_tran_stretch_bvr_2h, 'v-k', 'MarkerSize', msz);

⌨️ 快捷键说明

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