Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.33 KB | None | 0 0
  1. clear;
  2. clc;
  3. n=6;
  4. for i=1:1:n
  5.     for j=1:1:n
  6.         if i~=j
  7.             w=ceil(rand*20)+30; %waga  
  8.             W(i,j)=w;
  9.         else
  10.             W(i,j)=inf;
  11.         end
  12.     end
  13. end
  14. W;
  15. W=[inf 15 inf inf 9 inf;
  16.    inf inf 35 3 inf inf;
  17.    inf 16 inf 6 inf 21;
  18.    inf inf inf inf 2 7;
  19.    inf 4 inf 2 inf inf;
  20.    inf inf 5 inf inf inf]
  21. %TWORZENIE MACIERZY DROG
  22. P=zeros(6,6);
  23. for i=1:1:n
  24.     for j=1:1:n
  25.         if W(i,j)~=inf
  26.             P(i,j)=i;
  27.         end
  28.     end
  29. end
  30. %ALGORYTM FLOYDA
  31. for l=1:1:n
  32.   for i=1:1:n
  33.       if W(i,l)~=inf
  34.           for j=1:1:n
  35.               if W(i,j)>(W(i,l)+W(l,j))
  36.                  P(i,j)=P(l,j);
  37.               end
  38.               W(i,j)=min(W(i,j),W(i,l)+W(l,j));
  39.           end
  40.       end
  41.   end
  42. end
  43. %długość dróg
  44. W
  45. %drogi
  46. P
  47. %droga od tylu
  48. start=1;
  49. koniec=6;
  50. i=2;
  51. wynik(1)=koniec;
  52. while wynik(i-1)~=start;
  53.  wynik(i)=P(start,wynik(i-1));
  54. i=i+1;
  55. end
  56. fliplr(wynik)
  57.  
  58. ilosc(licznik)=n;
  59. srednia(licznik) = suma/30;
  60. A=(ilosc(1)^2)/srednia(1);
  61. zlozonosc(licznik)=(n*n)/A;
  62. licznik = licznik + 1;
  63.  
  64.  
  65. plot(ilosc,zlozonosc,'-ro')
  66. title('Wykres złożoności obliczeniowej');
  67. xlabel('Ilość węzłów w grafie');
  68. ylabel('Czas');
  69. hold on
  70. plot(ilosc,srednia, '-s')
  71. legend('złożoność obliczeniowa algorytmu','czas trwaniaalgorytmu','Location','northwest');'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement