欧拉图fluery算法matlab

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

clear all

A=zeros(16);

for i=1:16

%A(i,i)=1/2;

if i+1<=16 && mod(i,4)~=0

A(i,i+1)=1;

end

if i+4<=16

A(i,i+4)=1;

end

end

A(2,5)=1;

A(3,8)=1;

A(9,14)=1;

A(12,15)=1;

% A(1,6)=1;

% A(6,11)=1;

% A(11,16)=1;

% A(16,1)=1;

A=A+A';

[T3 c3]=Fleuf2(A);

pos3(1:2,1)=0;

for i=1:16

if i==1, pos3(1:2,i)=0;

else

if mod(i-1,4)~=0

pos3(1,i)=pos3(1,i-1)+1;

pos3(2,i)=pos3(2,i-1);

else

pos3(1,i)=pos3(1,i-4);

pos3(2,i)=pos3(2,i-4)-1;

end

end

end

figure (1), title('3rd Question')

for j=i:16

if A(i,j)==1,

plot([pos3(1,i),pos3(1,j)],[pos3(2,i),pos3(2,j)]); hold on, end

end

end

for i=2:c3

draw_arrow(pos3(:,T3(1,i))',pos3(:,T3(2,i))',0.5)

x = mean(pos3(1,T3(:,i)));

y = mean(pos3(2,T3(:,i)))

text(x,y,num2str(i),'FontSize',18);

pause;

end

pause off;

hold off

function [T c]=Fleuf1(d)

n = length(d);

b = d;

b(b == Inf)=0;

b(b~=0) = 1;

m = 0;

a = sum(b);

eds = sum(a)/2;

ed = zeros(2,eds);

vexs = zeros(1,eds+1);

matr = b;

for i=1:n

if mod(a(i),2) ==1

m = m+1;

end

end

if m~=0

fprintf('there is not exist Euler path.\n');

T=0;c=0;

end

if m==0

flag=0;

t1 = find(matr(vet,:)==1);

for ii = 1:length(t1)

ii=1;

ed(:,1)=[vet,t1(ii)];

vexs(1,1)=vet;

vexs(1,2)=t1(ii);

matr(vexs(1,2),vexs(1,1))=0;

flagg=1;tem=1;

while flagg

[flagg ed]=edf(matr,eds,vexs,ed,tem);

tem = tem+1;

if ed(1,eds)~=0 & ed(2,eds) ~=0

T=ed;

% T(2,eds) = 1;

c= 0;

for g=1:eds

c = c+d(T(1,g),T(2,g));

end

flagg = 0;

break;

end

end

end

end

function [flag ed] = edf(matr, eds, vexs, ed, tem)

flag =1;

for i=2:eds

[dvex f] = flecvexf(matr, i, vexs, eds, ed, tem);

if f==1

flag =0;

break ;

end

if dvex ~=0

ed(:,i)=[vexs(1,i) dvex];

vexs(1, i+1) = dvex;

matr(vexs(1,i+1), vexs(1,i))=0;

else

break;

end

end

function [dvex f]=flecvexf(matr, i, vexs, eds, ed, temp)

f = 0;

edd = find(matr(vexs(1,i),:)==1);

dvex = 0;

dvex1 = [];

ded = [];

if length(edd)==1

dvex = edd;

else

dd = 1; dd1=0;kkk=0;

for kk=1:length(edd)

m1 = find(vexs==edd(kk));

if sum(m1)==0

dvex1(dd)=edd(kk);

dd = dd+1;

dd1 = 1;

else

kkk=kkk+1;

end

end

if kkk==length(edd)

tem = vexs(1,i)*ones(1,kkk);

edd1=[tem;edd];

for l1=1:kkk

lt = 0; ddd=1;

for l2=1:eds

if edd1(1:2,l1) == ed(1:2, l2)

lt = lt +1;

end

end

if lt==0

ded(ddd) = edd(l1);

ddd = ddd+1;

end

end

end

相关文档
最新文档