📄 sim_dv.m
字号:
function sim_dv(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!fn = 'sim_dv';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_dv') topo = 'topo-3200-5.12v6.mat';elseif strcmp(instance,'low_dv') topo = 'topo-3200-3v6.mat';else error('unknown topo file'); %topo = 'topo-100-5.12-0.1.mat';endrepeat = 10;%repeat = 1;%failure_percent =0.005:0.005:0.2;failure_percent =0.0:0.005:0.2;%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', 'failure_percent','topo','max_jobs','-V6');endload(const_fn); %make sure it's consistant between instancesjob_count = 0;S = load(topo);%%%%%%%for i=1:repeat for b=1:length(failure_percent) 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**sim_dv test failure_percent=%.3f, i=%d\n', job_count, failure_percent(b), i); try tmp=load(final_fn); clear tmp fprintf('**ALREADY DID job_id=%d** test failure_percent=%.3f, i=%d\n', job_count, failure_percent(b), i); catch res = simulation_dv(topo, 56, failure_percent(b),0); save(final_fn ,'res'); 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(failure_percent) 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));%%%%%%%%%msz = 12; %MarkerSize%n_beacons =[10, 20, 56, 80, 100]%repeat = 10;topoS = load(topo);failure_percentn_nodes = S.n_nodes;%%%%figure 1.a routing success ratefor i=1:repeat for b=1:length(failure_percent) n_live_nodes = n_nodes - ceil(S.n_nodes * failure_percent(b)); broadcast_1(b,i) = res(b,i).broadcast_1/n_nodes; broadcast_2(b,i) = res(b,i).broadcast_2/n_live_nodes; dv_entries_1(b,i) = res(b,i).dv_entries_1/n_nodes; dv_entries_2(b,i) = res(b,i).dv_entries_2/n_live_nodes; dv_entries_3(b,i) = res(b,i).dv_entries_3/n_live_nodes; endendfigure(1)set(gca, 'FontSize',20);hold onDV_PACKET_SIZE=2+1+1+1;%dest id, dist, range,seqBROADCAST_PACKET_SIZE=2+1+1; %becon id, dist, seqif 0plot_errorbar(dv_entries_2*DV_PACKET_SIZE, failure_percent, 'b-o',msz);plot_errorbar(dv_entries_3*DV_PACKET_SIZE, failure_percent, 'r-x', msz);plot_errorbar(broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'k-*',msz);endplot_mean(dv_entries_2*DV_PACKET_SIZE, failure_percent, 'b-o',msz);plot_mean(dv_entries_3*DV_PACKET_SIZE, failure_percent, 'r-x', msz);plot_mean(broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'k-*',msz);legend('incremental DV', 'oblivious DV','beacon flooding',2);xlabel('failure percent');ylabel('traffic per node (Byte)');saveas(gcf, 'dv_only.eps','psc2')figure(2)set(gca, 'FontSize',20);hold onif 0plot_errorbar(dv_entries_2*DV_PACKET_SIZE+broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'b-o', msz);plot_errorbar(dv_entries_3*DV_PACKET_SIZE+broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'r-x',msz);plot_errorbar(dv_entries_1*DV_PACKET_SIZE+broadcast_1*BROADCAST_PACKET_SIZE, failure_percent,'k-*', msz);endplot_mean(dv_entries_2*DV_PACKET_SIZE+broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'b-o', msz);plot_mean(dv_entries_3*DV_PACKET_SIZE+broadcast_2*BROADCAST_PACKET_SIZE, failure_percent, 'r-x',msz);%plot_mean(dv_entries_1*DV_PACKET_SIZE+broadcast_1*BROADCAST_PACKET_SIZE, failure_percent,'k-*', msz);legend('incremental PCR', 'oblivious PCR',2);xlabel('failure percent');ylabel('traffic per node(Byte)');ylim([0, 800]);saveas(gcf, 'dv_overall.eps','psc2')return%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -