D
G=[0,inf,inf,1.2,9.2,inf,0.5; inf,0,inf,5,inf,3.1,2 inf,inf,0,inf,inf,4,1.5 1.2,5,inf,0,6.7,inf,inf 9.2,inf,inf,6.7,0,15.6,inf inf,3.1,4,inf,15.6,0,inf 0.5,2,1.5,inf,inf,inf,0]; length_G = length(G); d=[inf,inf,inf,inf,inf,inf,inf]; visited=[0,0,0,0,0,0,0]; path=[1,2,3,4,5,6,7];%路径矩阵 s=5;%源点 visited(s)=1; for i=1:length_G if G(s,i)~=inf d(i)=G(s,i); end end %dijkstra for i=1:length_G min = inf; for j=1:length_G if visited(j)==0 && d(j)<min min = d(j); k = j; end end visited(k)=1; for l=1:length_G if visited(l)==0 && d(k)+G(k,l) < d(1,l) d(l) = d(k)+G(k,l); path(l)=k; end end end disp('length'); disp(d); %print routes p = zeros(length_G); for dest=1:length_G tmpd=dest; r=1; p(dest,r)=tmpd; r=r+1; % disp(dest); for j=1:length_G if tmpd==path(tmpd) break; else %disp(path(dest)); p(dest,r)=path(tmpd); tmpd=path(tmpd); r=r+1; end end p(dest,r)=s; r=r+1; %disp(s); end %swap p for i=1:length_G j=1; while p(i,j)~=0 j = j+1; end dec=1; for g=1:j-1 tmp = p(i,g); p(i,g)=p(i,j-dec); p(i,j-dec)=tmp; dec = dec+1; g=g+1; if j-dec <= g break; end end end disp("routes:"); disp(p); figure(1); %hold off; clf; axis([1,10,0,5]); for k=1:10 b(1,k)=k; end b(2,:)=rand(1,10)*5; for i=1:length_G txt=['min(v',num2str(s),',','v1)=',num2str(d(i))]; text(i,b(2,i)+0.1,txt); end hold on; for i=1:length_G idage=p(i,:); c=1; while c<length_G&&idage(c)~=0&&idage(c+1)~=0 f=idage(c); g=idage(c+1); s=[b(1,f),b(1,g)]; t=[b(2,f),b(2,g)]; lenx=(b(1,f)+b(1,g))/2; leny=(b(2,f)+b(2,g))/2; plot(s,t); txt = ['(v',num2str(f),',','v',num2str(g),')=',num2str(G(f,g))]; text(lenx,leny,txt); hold on; c=c+1; end end for e=1:length_G plot(b(1,e)-0.01,b(2,e),'bd'); end title('D算法') %end
F
G=[0,inf,inf,1.2,9.2,inf,0.5; inf,0,inf,5,inf,3.1,2 inf,inf,0,inf,inf,4,1.5 1.2,5,inf,0,6.7,inf,inf 9.2,inf,inf,6.7,0,15.6,inf inf,3.1,4,inf,15.6,0,inf 0.5,2,1.5,inf,inf,inf,0]; length_G = length(G); dis=G;%最短距离矩阵dis visited=zeros(length_G); r=zeros(length_G);%route for i=1:length_G%初始化r for j=1:length_G if(i~=j) r(i,j)=j; else r(i,j)=0; end end end for k=1:length_G for i=1:length_G for j=1:length_G if dis(i,k)+dis(k,j) < dis(i,j) dis(i,j) = dis(i,k)+dis(k,j); r(i,j)=k; end end end end disp('dis:'); disp(dis); disp('route:'); disp(r);
B
function ErlangB clc; pn=[]; s=[]; x=0.1:0.1:100; %横坐标范围 m=[4 5 8 10 15 20 25 30 40 50 60 75 90 100]; %交换机出线容量 L=length(m); for i=1:L for a=0.1:0.1:100 %流入话务量强度 for k=0:m(i) s=[s,a.^k/factorial(k)]; add=sum(s); end pn0=(a.^m(i)/factorial(m(i)))./add; pn=[pn,pn0]; %顾客被拒绝的概率 s=[]; end loglog(x,pn); %plot(x,pn); %对数坐标 set(gca,'Xlim',[1 100]); %限定横坐标的取值范围 set(gca,'XGrid','on'); %画网格线 set(gca,'XMinorTick','off'); set(gca,'XTick',[1 2 4 6 8 10 20 40 60 80 100]); %x坐标轴刻度设置 %set(gca,'XMinorGrid','off'); set(gca,'Ylim',[0.001 1]); %限定纵坐标的取值范围 set(gca,'YGrid','on'); set(gca,'YMinorTick','off'); set(gca,'YTick',[0.001 0.002 0.004 0.006 0.008 0.01 0.02 0.04 0.06 0.08 0.1 0.2 0.4 0.6 0.8 1]); %set(gca,'YMinorGrid','off'); hold on pn=[]; end xlabel('话务量强度α(erl)','fontsize',8); ylabel('呼损率Pc','fontsize',8); hold off for i=1:L txt = ['m=',int2str(m(i))]; gtext(txt,'fontsize',10); end
C
function ErlangC clc; pc=[]; s=[]; m=[4 5 8 10 15 20 25 30 40 50 60 75 90 100]; %交换机出线容量 L=length(m); for i=1:L for a=1:100 %流入话务量强度 if a<=m(i) for k=0:(m(i)-1) s=[s,a.^k/factorial(k)]; add=sum(s); end pc0=a.^m(i)/(a.^m(i)+factorial(m(i))*(1-a/m(i))*add); pc=[pc,pc0]; %呼叫等待概率 s=[]; end end x=1:length(pc); %横坐标范围 loglog(x,pc); %对数坐标 set(gca,'XGrid','on'); %画网格线 set(gca,'XMinorTick','off'); set(gca,'Xlim',[1 100]); %限定横坐标的取值范围 set(gca,'XTick',[1 2 4 6 8 10 20 40 60 80 100]); %set(gca,'XTick',[0.1 0.2 0.5 1 2 5 10 20 50 100]); %x坐标轴刻度设置 %set(gca,'XMinorGrid','off'); set(gca,'Ylim',[0.001 1]); %限定纵坐标的取值范围 set(gca,'YGrid','on'); set(gca,'YTick',[0.001 0.002 0.004 0.006 0.008 0.01 0.02 0.04 0.06 0.08 0.1 0.2 0.4 0.6 0.8 1]); %set(gca,'YMinorTick','off'); hold on pc=[]; end xlabel('话务量强度α(erl)','fontsize',8); ylabel('呼叫等待概率Pw','fontsize',8); for i=1:L txt = ['m=',int2str(m(i))]; gtext(txt,'fontsize',10); end
G L
t=2005:0.01:2020; g_=120./(1+2.861.*exp(-0.341*(t-2004))); l_ = 120*exp(-1.554*exp(-0.275*(t-2004))); avg = (g_+l_)/2; xlabel('年份'); ylabel('部/百人'); set(gca,'xTick',[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020]); hold on; plot(t,g_); plot(t,l_,'-.'); plot(t,avg,'--'); gtext('Gompertz','fontsize',10); gtext('Logistic','fontsize',10); gtext('Average','fontsize',10); legend('Gompertz模型预测的移动电话普及率','Logistic模型预测的移动电话普及率','平均法预测的移动电话普及率'); %title('2015~2020年移动电话普及率'); title('2005~2020年移动电话普及率及率预测曲线');