📄 sim_obstaclep.m
字号:
function sim_obstaclep(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_obstaclep';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)n_obstacles = [0 25, 50, 75];l_obstacles = [1.25, 2.5];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', 'n_obstacles','l_obstacles','max_jobs','-V6');endload(const_fn); %make sure it's consistant between instancesjob_count = 0;%%%%%%%for i=1:repeat for n=1:length(n_obstacles) for l=1:length(l_obstacles) 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* i=%d\n', job_count, i); try tmp=load(final_fn); clear tmp fprintf('**ALREADY DID job_id=%d**\n', job_count); catch topo=sprintf('%s/topo-obstacle-%d-%1.2f-%d.mat',instance,n_obstacles(n),l_obstacles(l),i) topology_generator(topo,3200, 5.12, n_obstacles(n), l_obstacles(l),0); fprintf('****sim_obstacle test %s, repeat=%d\n', topo, i); res = simulation(topo, 56); optimal = sim_optimal(topo); save(final_fn ,'res','optimal'); end end end endendfunction process_data(fn, instance)load(sprintf('%s/%s-const.mat', instance,fn))job_count = 0;for i=1:repeat for n=1:length(n_obstacles) for l=1:length(l_obstacles) job_count = job_count + 1; final_fn = sprintf('%s/%s-%d.mat', instance, fn, job_count); TMP = load(final_fn); res(n,l,i) = TMP.res; optimal(n,l,i) = TMP.optimal; topo_fn = sprintf('%s/topo-obstacle-%d-%1.2f-%d.mat',instance, ... n_obstacles(n),l_obstacles(l),i); S = load(topo_fn); total_links = sum(S.D(:)); n_blocked(n,l,i) = S.n_blocked/(S.n_blocked+total_links); end endendsave(sprintf('%s/%s-all.mat',instance,fn));plot_data(sprintf('%s/%s-all.mat',instance,fn))function plot_data(fn)%copied from sim_obstacle.m's process_data%not really plot, but output into the table fileload(fn);fid = fopen('obstacle.table','w');for l=1:length(l_obstacles) for n=1:length(n_obstacles) clear stretch_bvr_sf_mean for i=1:repeat stretch_bvr_sf_mean(i)=plot_routing_stretch( ... res(n,l,i).transmission_dist_bvr_sf', optimal(n,l,i).optimal_dist, 'k',[50],0); stretch_bvr_sf_worst(i)=plot_routing_stretch( ... res(n,l,i).transmission_dist_bvr_sf', optimal(n,l,i).optimal_dist, 'k',[95],0); stretch_bvr_2h_mean(i)=plot_routing_stretch( ... res(n,l,i).transmission_dist_bvr_2h', optimal(n,l,i).optimal_dist, 'k',[50],0); stretch_cr_mean(i)=plot_routing_stretch( ... res(n,l,i).routing_dist_cr, optimal(n,l,i).optimal_dist, 'k',[50],0); stretch_cr_worst(i)=plot_routing_stretch( ... res(n,l,i).routing_dist_cr, optimal(n,l,i).optimal_dist, 'k',[95],0); failure_bvr(i) = res(n,l,i).failure_bvr; end fprintf('number:%d,length:%1.2f avg stretch bvr %f(%f)\t cr %f(%f) n_blocked:%f\n', ... n_obstacles(n), l_obstacles(l), ... mean(stretch_bvr_sf_mean), ... mean(stretch_bvr_sf_worst),... mean(stretch_cr_mean), ... mean(stretch_cr_worst),... mean(n_blocked(n,l,:))); %cr_final(l,n)=mean(stretch_cr_mean); %bvr_final(l,n) = mean(stretch_bvr_sf_mean); cr_final(l,n)=mean(stretch_cr_worst); bvr_final(l,n) = mean(stretch_bvr_sf_worst); endend% for the case without obstacle, return the averaged resultbvr_final(1,1) = (bvr_final(1,1)+bvr_final(2,1))/2;bvr_final(2,1) = bvr_final(1,1);cr_final(1,1) = (cr_final(1,1)+cr_final(2,1))/2;cr_final(2,1) = cr_final(1,1);for l=1:length(l_obstacles) fprintf(fid, '%.2f & ', l_obstacles(l)); for n=1:length(n_obstacles) fprintf(fid, '%.2f, %.2f ', cr_final(l,n),bvr_final(l,n)); if n<length(n_obstacles) fprintf(fid,' & '); else fprintf(fid,'\\\\\n'); end endendfclose(fid);%%%%%%%%%%%%%%%%%fontsize=20;msz = 12;lwd = 2;set(gca, 'FontSize', fontsize);hold onplot(n_obstacles, cr_final(1,:),'go-','MarkerSize', msz, 'LineWidth',lwd);plot(n_obstacles, cr_final(2,:),'r<-','MarkerSize', msz, 'LineWidth',lwd)plot(n_obstacles, bvr_final(1,:),'k*-','MarkerSize', msz, 'LineWidth',lwd)plot(n_obstacles, bvr_final(2,:),'k^-','MarkerSize', msz, 'LineWidth',lwd)xlabel('number of obstacles');ylabel('95th percentile transmission stretch');legend('S4, obstacle len=1.25','S4, obstacle len=2.5',... 'BVR, obstacle len=1.25','BVR, obstacle len=2.5','Location','Best');saveas(gcf, 'obstacle.eps','psc2')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -