quelques modifications mineures
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210346 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
84fd75766b
commit
695673f9b5
|
@ -1,26 +1,13 @@
|
||||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||||
|
|
||||||
with Ada.Text_IO; use Ada.Text_IO;
|
|
||||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
|
||||||
with Ada.Command_Line; use Ada.Command_Line;
|
|
||||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
|
||||||
with Ada.Text_IO.Text_Streams;
|
|
||||||
|
|
||||||
|
|
||||||
package body Google_Creux is
|
package body Google_Creux is
|
||||||
|
|
||||||
-- construction simple, de compléxité N^2
|
|
||||||
-- on peut diminuer la compléxité en triant d'abord le réseau
|
|
||||||
-- on passerait à une complexité 2*N + N*Log(2, N)
|
|
||||||
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is
|
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is
|
||||||
row, col: Natural;
|
row, col: Natural;
|
||||||
nb: Natural := 0;
|
nb: Natural := 0;
|
||||||
stdout: constant Ada.Text_IO.File_Type := Ada.Text_IO.Standard_Output;
|
|
||||||
begin
|
begin
|
||||||
mat.rows(0) := 0;
|
mat.rows(0) := 0;
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
String'Write(Ada.Text_IO.Text_Streams.Stream(stdout),
|
|
||||||
ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(N-1));
|
|
||||||
reset(file, In_File);
|
reset(file, In_File);
|
||||||
skip_line(file);
|
skip_line(file);
|
||||||
for j in 0..N_links-1 loop
|
for j in 0..N_links-1 loop
|
||||||
|
|
|
@ -25,10 +25,10 @@ package Google_Creux is
|
||||||
rows: T_Rows;
|
rows: T_Rows;
|
||||||
end record;
|
end record;
|
||||||
|
|
||||||
function calcul(vec: T_Vecteur_Element; mat :T_Google; alpha: in T_Element) return T_Vecteur_Element;
|
|
||||||
|
|
||||||
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type);
|
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type);
|
||||||
|
|
||||||
|
function calcul(vec: T_Vecteur_Element; mat :T_Google; alpha: in T_Element) return T_Vecteur_Element;
|
||||||
|
|
||||||
procedure put(mat: in T_Google);
|
procedure put(mat: in T_Google);
|
||||||
|
|
||||||
end Google_Creux;
|
end Google_Creux;
|
||||||
|
|
|
@ -6,7 +6,6 @@ package body Google_Naive is
|
||||||
vec: T_Vecteur_Element;
|
vec: T_Vecteur_Element;
|
||||||
c: T_Element;
|
c: T_Element;
|
||||||
begin
|
begin
|
||||||
initialize(vec); -- garder ?
|
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
c := 0.0;
|
c := 0.0;
|
||||||
for j in 0..N-1 loop
|
for j in 0..N-1 loop
|
||||||
|
@ -69,6 +68,7 @@ package body Google_Naive is
|
||||||
end create_G;
|
end create_G;
|
||||||
|
|
||||||
procedure put(mat: in T_Google) is
|
procedure put(mat: in T_Google) is
|
||||||
|
use Text_T_Element;
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
for j in 0..N-1 loop
|
for j in 0..N-1 loop
|
||||||
|
|
|
@ -12,7 +12,6 @@ package Google_Naive is
|
||||||
-- on permet l'affichage direct des T_Element
|
-- on permet l'affichage direct des T_Element
|
||||||
package Text_T_Element is
|
package Text_T_Element is
|
||||||
new Ada.Text_IO.Float_IO(Num => T_Element);
|
new Ada.Text_IO.Float_IO(Num => T_Element);
|
||||||
use Text_T_Element;
|
|
||||||
|
|
||||||
-- on utilise le module Vector
|
-- on utilise le module Vector
|
||||||
use Vector_T_Element;
|
use Vector_T_Element;
|
||||||
|
|
|
@ -152,7 +152,7 @@ procedure pageRank is
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
initialize(pi);
|
initialize(pi, 1.0/T_Double(N));
|
||||||
put_line("initialized pi");
|
put_line("initialized pi");
|
||||||
-- put(pi); new_line;
|
-- put(pi); new_line;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ procedure pageRank is
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
initialize(pi);
|
initialize(pi, 1.0/T_Double(N));
|
||||||
put_line("initialized pi:");
|
put_line("initialized pi:");
|
||||||
-- put(pi); new_line;
|
-- put(pi); new_line;
|
||||||
|
|
||||||
|
@ -220,9 +220,9 @@ procedure pageRank is
|
||||||
ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(ite_max));
|
ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(ite_max));
|
||||||
end loop; new_line;
|
end loop; new_line;
|
||||||
|
|
||||||
new_line;
|
-- new_line;
|
||||||
put_line("final pi:");
|
-- put_line("final pi:");
|
||||||
put(pi);
|
-- put(pi);
|
||||||
|
|
||||||
end algorithm_creux;
|
end algorithm_creux;
|
||||||
|
|
||||||
|
|
106
src/vector.adb
106
src/vector.adb
|
@ -2,13 +2,6 @@ with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||||
|
|
||||||
package body vector is
|
package body vector is
|
||||||
|
|
||||||
procedure initialize(vec: in out T_Vecteur_Element) is
|
|
||||||
begin
|
|
||||||
for i in 0..N-1 loop
|
|
||||||
vec(i) := 1.0/T_Element(N);
|
|
||||||
end loop;
|
|
||||||
end initialize;
|
|
||||||
|
|
||||||
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element) is
|
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element) is
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
|
@ -33,6 +26,7 @@ package body vector is
|
||||||
end sum;
|
end sum;
|
||||||
|
|
||||||
procedure put(vec: in T_Vecteur_Element) is
|
procedure put(vec: in T_Vecteur_Element) is
|
||||||
|
use Text_T_Element;
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
put(vec(i)); new_line;
|
put(vec(i)); new_line;
|
||||||
|
@ -40,6 +34,7 @@ package body vector is
|
||||||
end put;
|
end put;
|
||||||
|
|
||||||
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element) is
|
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element) is
|
||||||
|
use Text_T_Element;
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
put(file, vec(i), Fore=>1, Aft=>10);
|
put(file, vec(i), Fore=>1, Aft=>10);
|
||||||
|
@ -79,6 +74,46 @@ package body vector is
|
||||||
end loop;
|
end loop;
|
||||||
end sort_with_index_desc;
|
end sort_with_index_desc;
|
||||||
|
|
||||||
|
<<<<<<< .mine
|
||||||
|
||||||| .r210321
|
||||||
|
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is
|
||||||
|
pivot: Natural := a;
|
||||||
|
i: Natural := a;
|
||||||
|
tmp: T_Element;
|
||||||
|
begin
|
||||||
|
if b - a > 1 then
|
||||||
|
for j in a..b loop
|
||||||
|
if vec(j) <= vec(pivot) then
|
||||||
|
i := i + 1;
|
||||||
|
tmp := vec(i);
|
||||||
|
vec(i) := vec(j);
|
||||||
|
vec(j) := tmp;
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
tmp := vec(i);
|
||||||
|
vec(i) := vec(pivot);
|
||||||
|
vec(pivot) := tmp;
|
||||||
|
|
||||||
|
pivot := i;
|
||||||
|
|
||||||
|
put(vec); new_line;
|
||||||
|
|
||||||
|
if pivot - 1 > 0 then
|
||||||
|
quicksort(vec, vec_index, a, pivot-1);
|
||||||
|
elsif b - pivot - 1 > 0 then
|
||||||
|
quicksort(vec, vec_index, pivot+1, b);
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
end if;
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
end if;
|
||||||
|
end quicksort;
|
||||||
|
|
||||||
|
=======
|
||||||
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is
|
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is
|
||||||
pivot: Natural := a;
|
pivot: Natural := a;
|
||||||
i: Natural := a;
|
i: Natural := a;
|
||||||
|
@ -116,7 +151,63 @@ package body vector is
|
||||||
end if;
|
end if;
|
||||||
end quicksort;
|
end quicksort;
|
||||||
|
|
||||||
|
>>>>>>> .r210345
|
||||||
end vector;
|
end vector;
|
||||||
|
<<<<<<< .mine
|
||||||
|
||||||| .r210321
|
||||||
|
|
||||||
|
-- def triRapide(L): # Quicksort
|
||||||
|
-- if len(L) <= 1:
|
||||||
|
-- return L
|
||||||
|
-- pvt = L[0]
|
||||||
|
-- L1, L2 = [], []
|
||||||
|
-- for i in range(1, len(L)):
|
||||||
|
-- if L[i] < pvt:
|
||||||
|
-- L1.append(L[i])
|
||||||
|
-- else:
|
||||||
|
-- L2.append(L[i])
|
||||||
|
-- return triRapide(L1) + [pvt] + triRapide(L2)
|
||||||
|
|
||||||
|
-- procedure Quick_Sort (A : in out Element_Array) is
|
||||||
|
|
||||||
|
-- procedure Swap(Left, Right : Index) is
|
||||||
|
-- Temp : Element := A (Left);
|
||||||
|
-- begin
|
||||||
|
-- A (Left) := A (Right);
|
||||||
|
-- A (Right) := Temp;
|
||||||
|
-- end Swap;
|
||||||
|
|
||||||
|
-- begin
|
||||||
|
-- if A'Length > 1 then
|
||||||
|
-- declare
|
||||||
|
-- Pivot_Value : Element := A (A'First);
|
||||||
|
-- Right : Index := A'Last;
|
||||||
|
-- Left : Index := A'First;
|
||||||
|
-- begin
|
||||||
|
-- loop
|
||||||
|
-- while Left < Right and not (Pivot_Value < A (Left)) loop
|
||||||
|
-- Left := Index'Succ (Left);
|
||||||
|
-- end loop;
|
||||||
|
-- while Pivot_Value < A (Right) loop
|
||||||
|
-- Right := Index'Pred (Right);
|
||||||
|
-- end loop;
|
||||||
|
-- exit when Right <= Left;
|
||||||
|
-- Swap (Left, Right);
|
||||||
|
-- Left := Index'Succ (Left);
|
||||||
|
-- Right := Index'Pred (Right);
|
||||||
|
-- end loop;
|
||||||
|
-- if Right = A'Last then
|
||||||
|
-- Right := Index'Pred (Right);
|
||||||
|
-- Swap (A'First, A'Last);
|
||||||
|
-- end if;
|
||||||
|
-- if Left = A'First then
|
||||||
|
-- Left := Index'Succ (Left);
|
||||||
|
-- end if;
|
||||||
|
-- Quick_Sort (A (A'First .. Right));
|
||||||
|
-- Quick_Sort (A (Left .. A'Last));
|
||||||
|
-- end;
|
||||||
|
-- end if;
|
||||||
|
-- end Quick_Sort;=======
|
||||||
|
|
||||||
-- def triRapide(L): # Quicksort
|
-- def triRapide(L): # Quicksort
|
||||||
-- if len(L) <= 1:
|
-- if len(L) <= 1:
|
||||||
|
@ -170,3 +261,4 @@ end vector;
|
||||||
-- end;
|
-- end;
|
||||||
-- end if;
|
-- end if;
|
||||||
-- end Quick_Sort;
|
-- end Quick_Sort;
|
||||||
|
>>>>>>> .r210345
|
||||||
|
|
|
@ -13,9 +13,8 @@ package Vector is
|
||||||
-- on permet l'affichage direct des T_Element
|
-- on permet l'affichage direct des T_Element
|
||||||
package Text_T_Element is
|
package Text_T_Element is
|
||||||
new Ada.Text_IO.Float_IO(Num => T_Element);
|
new Ada.Text_IO.Float_IO(Num => T_Element);
|
||||||
use Text_T_Element;
|
|
||||||
|
|
||||||
procedure initialize(vec: in out T_Vecteur_Element);
|
|
||||||
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element);
|
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element);
|
||||||
procedure initialize(vec: in out T_Vecteur_Natural);
|
procedure initialize(vec: in out T_Vecteur_Natural);
|
||||||
|
|
||||||
|
@ -27,6 +26,4 @@ package Vector is
|
||||||
|
|
||||||
procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural);
|
procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural);
|
||||||
|
|
||||||
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural);
|
|
||||||
|
|
||||||
end Vector;
|
end Vector;
|
||||||
|
|
Loading…
Reference in a new issue