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

📄 sim_density.m

📁 best routing protocol
💻 M
字号:
function sim_density%vary the number of beacons%fn = 'sim_density.mat';fn_low = 'low_density/sim_parallel-all.mat';fn_high = 'high_density/sim_parallel-all.mat';%get_raw_data(fn)process_data_new(fn_high, fn_low)function get_raw_data(fn)%DO NOT USE. DEPRECATEDreturn topo = 'topo-3200-3.mat';repeat = 10;n_beacons =[10,20,56]S = load(topo);[optimal_dist optimal_nexthop] = allpair_dijkstra(S.D, ...						  1:S.n_nodes, 1, ...						  'optimal-cache3.mat');load_optimal = get_nexthop_load(optimal_nexthop, S.random_pairs);for i=1:repeat  for b=1:length(n_beacons)    fprintf('****sim_density test beacon=%d, i=%d\n', n_beacons(b), i);    res(b,i) = simulation(topo, n_beacons(b));    res(b,i).failure_bvr    save(fn, 'res','optimal_dist','load_optimal', 'n_beacons','repeat','topo');  endendfunction process_data_new(fn_high, fn_low)fontsize=15;msz = 12;h = load(fn_high);l = load(fn_low);S = load(h.topo);pair_indices = S.random_pairs(:,1)+(S.random_pairs(:,2)-1)*S.n_nodes;h_optimal_dist = h.optimal_dist(pair_indices);S = load(l.topo);pair_indices = S.random_pairs(:,1)+(S.random_pairs(:,2)-1)*S.n_nodes;l_optimal_dist = l.optimal_dist(pair_indices);n_beacons = h.n_beacons;repeat = h.repeat;if 0%for routing stretchfor b = 1:length(n_beacons)  for i=1:repeat    h_routing_dist_bvr_sf(:,i)=h.res(b,i).routing_dist_bvr_sf;    h_routing_dist_cr(:,i)=h.res(b,i).routing_dist_cr;    l_routing_dist_bvr_sf(:,i)=l.res(b,i).routing_dist_bvr_sf;    l_routing_dist_cr(:,i)=l.res(b,i).routing_dist_cr;  end  h_avg_bvr_stretch(b) = plot_routing_stretch(h_routing_dist_bvr_sf, h_optimal_dist, '',[-1],0);  h_avg_cr_stretch(b) = plot_routing_stretch(h_routing_dist_cr, h_optimal_dist, '',[-1],0);  l_avg_bvr_stretch(b) = plot_routing_stretch(l_routing_dist_bvr_sf, l_optimal_dist, '',[-1],0);  l_avg_cr_stretch(b) = plot_routing_stretch(l_routing_dist_cr, l_optimal_dist, '',[-1],0);endendfigure(1)set(gca, 'FontSize', fontsize);hold onbeacon_to_study = find(n_beacons==56);for b = 1:length(n_beacons)  for i=1:repeat    h_transmission_dist_bvr_sf(:,i)=h.res(b,i).transmission_dist_bvr_sf;    h_routing_dist_cr(:,i)=h.res(b,i).routing_dist_cr;    l_transmission_dist_bvr_sf(:,i)=l.res(b,i).transmission_dist_bvr_sf;    l_routing_dist_cr(:,i)=l.res(b,i).routing_dist_cr;    h_failure_bvr(i) = h.res(b,i).failure_bvr;    l_failure_bvr(i) = l.res(b,i).failure_bvr;  end  plot_or_not = 0;  if b==beacon_to_study    plot_or_not = 1;    h_avg_bvr_worst = plot_routing_stretch(h_transmission_dist_bvr_sf, h_optimal_dist, '-r',[100],0);    l_avg_bvr_worst = plot_routing_stretch(l_transmission_dist_bvr_sf, l_optimal_dist, '-.r',[100],0);    h_avg_cr_worst = plot_routing_stretch(h_routing_dist_cr, h_optimal_dist, '-.b',[100],0);    l_avg_cr_worst = plot_routing_stretch(l_routing_dist_cr, l_optimal_dist, '--b',[100],0);        tmp = mean(h_failure_bvr);    plot([1 3],[1-tmp,1-tmp],'g--');    bvr_str3 = sprintf('BVR, high density, success rate=%.1f%%', 100-tmp*100);        tmp = mean(l_failure_bvr);    plot([1 3],[1-tmp,1-tmp],'g-.');    bvr_str4 = sprintf('BVR, low density, success rate=%.1f%%', 100-tmp*100);      end  h_avg_bvr_stretch(b) = plot_routing_stretch(h_transmission_dist_bvr_sf, h_optimal_dist, '-r',[-1],plot_or_not);  l_avg_bvr_stretch(b) = plot_routing_stretch(l_transmission_dist_bvr_sf, l_optimal_dist, '-.r',[-1],plot_or_not);  h_avg_cr_stretch(b) = plot_routing_stretch(h_routing_dist_cr, h_optimal_dist, '-.b',[-1],plot_or_not);  l_avg_cr_stretch(b) = plot_routing_stretch(l_routing_dist_cr, l_optimal_dist, '--b',[-1],plot_or_not);endbvr_str1 = sprintf('BVR, high density, avg./worst stretch=%.2f/%.1f',...		   h_avg_bvr_stretch(beacon_to_study),h_avg_bvr_worst);bvr_str2 = sprintf('BVR, low density, avg./worst stretch=%.2f/%.1f',...		   l_avg_bvr_stretch(beacon_to_study),l_avg_bvr_worst);cr_str1 = sprintf('S4, high density, avg./worst stretch=%.2f/%.1f',...		  h_avg_cr_stretch(beacon_to_study),h_avg_cr_worst);cr_str2 = sprintf('S4, low density, avg./worst stretch=%.2f/%.1f',...		  l_avg_cr_stretch(beacon_to_study), ...		  l_avg_cr_worst);% $$$ legend('BVR high density','BVR low density', ...% $$$        'S4 high density','S4 low density',0);legend(bvr_str3, bvr_str4, bvr_str1, bvr_str2, cr_str1, cr_str2,4);%grid onxlabel('transmission stretch');ylabel('CDF');xlim([1 3])saveas(gcf, 'density_cdf.eps','psc2')saveas(gcf, 'density_cdf.fig')figure(2)set(gca, 'FontSize', fontsize);hold onplot(n_beacons, h_avg_bvr_stretch,'r-x','MarkerSize', msz)plot(n_beacons, l_avg_bvr_stretch,'r--^','MarkerSize', msz)plot(n_beacons, h_avg_cr_stretch,'b-o','MarkerSize', msz)plot(n_beacons, l_avg_cr_stretch,'k-*','MarkerSize', msz)legend('BVR high density','BVR low density', ...       'S4 high density','S4 low density');%grid onxlabel('number of beacons (K)');ylabel('transmission stretch');saveas(gcf, 'density_stretch.eps','psc2')

⌨️ 快捷键说明

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