Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear;
- clc;
- n=6;
- for i=1:1:n
- for j=1:1:n
- if i~=j
- w=ceil(rand*20)+30; %waga
- W(i,j)=w;
- else
- W(i,j)=inf;
- end
- end
- end
- W;
- W=[inf 15 inf inf 9 inf;
- inf inf 35 3 inf inf;
- inf 16 inf 6 inf 21;
- inf inf inf inf 2 7;
- inf 4 inf 2 inf inf;
- inf inf 5 inf inf inf]
- %TWORZENIE MACIERZY DROG
- P=zeros(6,6);
- for i=1:1:n
- for j=1:1:n
- if W(i,j)~=inf
- P(i,j)=i;
- end
- end
- end
- %ALGORYTM FLOYDA
- for l=1:1:n
- for i=1:1:n
- if W(i,l)~=inf
- for j=1:1:n
- if W(i,j)>(W(i,l)+W(l,j))
- P(i,j)=P(l,j);
- end
- W(i,j)=min(W(i,j),W(i,l)+W(l,j));
- end
- end
- end
- end
- %długość dróg
- W
- %drogi
- P
- %droga od tylu
- start=1;
- koniec=6;
- i=2;
- wynik(1)=koniec;
- while wynik(i-1)~=start;
- wynik(i)=P(start,wynik(i-1));
- i=i+1;
- end
- fliplr(wynik)
- ilosc(licznik)=n;
- srednia(licznik) = suma/30;
- A=(ilosc(1)^2)/srednia(1);
- zlozonosc(licznik)=(n*n)/A;
- licznik = licznik + 1;
- plot(ilosc,zlozonosc,'-ro')
- title('Wykres złożoności obliczeniowej');
- xlabel('Ilość węzłów w grafie');
- ylabel('Czas');
- hold on
- plot(ilosc,srednia, '-s')
- legend('złożoność obliczeniowa algorytmu','czas trwaniaalgorytmu','Location','northwest');'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement