implémentation tri par sélection + écriture dans les fichiers
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@209088 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
f089f32c83
commit
ef9cb81ff8
|
@ -108,7 +108,7 @@ package body Google_Naive is
|
||||||
mat(i,j) := 1.0/sum;
|
mat(i,j) := 1.0/sum;
|
||||||
end if;
|
end if;
|
||||||
end loop;
|
end loop;
|
||||||
else
|
else -- sum == 0
|
||||||
for j in 0..N-1 loop
|
for j in 0..N-1 loop
|
||||||
mat(i,j) := 1.0 / T_Element(N);
|
mat(i,j) := 1.0 / T_Element(N);
|
||||||
end loop;
|
end loop;
|
||||||
|
@ -138,4 +138,43 @@ package body Google_Naive is
|
||||||
end loop;
|
end loop;
|
||||||
end put;
|
end put;
|
||||||
|
|
||||||
|
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur) is
|
||||||
|
begin
|
||||||
|
for i in 0..N-1 loop
|
||||||
|
put(file, Float(vec(i)));
|
||||||
|
new_line(file);
|
||||||
|
end loop;
|
||||||
|
end put;
|
||||||
|
|
||||||
|
procedure sort_with_index_desc(pi: in T_Vecteur; pi_sorted: out T_Vecteur; pi_index: out T_Vecteur) is
|
||||||
|
tmp: T_Element;
|
||||||
|
max: Natural;
|
||||||
|
begin
|
||||||
|
pi_sorted := pi;
|
||||||
|
|
||||||
|
initialize(pi_index);
|
||||||
|
for i in 0..N-1 loop
|
||||||
|
pi_index(i) := T_Element(i);
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
for i in 0..N-2 loop
|
||||||
|
max := i;
|
||||||
|
for j in i+1..N-1 loop
|
||||||
|
if pi_sorted(max) < pi_sorted(j) then
|
||||||
|
max := j;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
if max /= i then
|
||||||
|
tmp := pi_sorted(i);
|
||||||
|
pi_sorted(i) := pi_sorted(max);
|
||||||
|
pi_sorted(max) := tmp;
|
||||||
|
|
||||||
|
tmp := pi_index(i);
|
||||||
|
pi_index(i) := pi_index(max);
|
||||||
|
pi_index(max) := tmp;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
end sort_with_index_desc;
|
||||||
|
|
||||||
|
|
||||||
end Google_Naive;
|
end Google_Naive;
|
||||||
|
|
|
@ -30,6 +30,10 @@ package Google_Naive is
|
||||||
|
|
||||||
procedure put(vec: in T_Vecteur);
|
procedure put(vec: in T_Vecteur);
|
||||||
procedure put(mat: in T_Google);
|
procedure put(mat: in T_Google);
|
||||||
|
|
||||||
|
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur);
|
||||||
|
|
||||||
|
procedure sort_with_index_desc(pi: in T_Vecteur; pi_sorted: out T_Vecteur; pi_index: out T_Vecteur);
|
||||||
private
|
private
|
||||||
|
|
||||||
type T_Google is array (0..N-1, 0..N-1) of T_Element;
|
type T_Google is array (0..N-1, 0..N-1) of T_Element;
|
||||||
|
|
|
@ -79,19 +79,18 @@ procedure pageRank is
|
||||||
end get_args;
|
end get_args;
|
||||||
|
|
||||||
|
|
||||||
|
procedure choix_type_algo(N: Natural; filename: in Unbounded_String; file: in out Ada.Text_IO.File_Type; alpha: Float; ite_max: Natural; naif: Boolean) is
|
||||||
|
|
||||||
|
|
||||||
procedure algorithm_naif(N: in Positive;
|
|
||||||
file: in Ada.Text_IO.File_Type;
|
|
||||||
alpha: in Float;
|
|
||||||
ite_max: in Natural) is
|
|
||||||
|
|
||||||
package Google is
|
package Google is
|
||||||
new Google_Naive(T_Element => T_Double, N => N);
|
new Google_Naive(T_Element => T_Double, N => N);
|
||||||
use Google;
|
use Google;
|
||||||
|
|
||||||
pi: T_Vecteur;
|
procedure algorithm_naif(N: in Positive;
|
||||||
|
file: in out Ada.Text_IO.File_Type;
|
||||||
|
alpha: in Float;
|
||||||
|
ite_max: in Natural;
|
||||||
|
pi: out T_Vecteur) is
|
||||||
|
|
||||||
G: T_Google;
|
G: T_Google;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -102,19 +101,20 @@ procedure pageRank is
|
||||||
|
|
||||||
initialize(G);
|
initialize(G);
|
||||||
put_line("initialized G");
|
put_line("initialized G");
|
||||||
--put(G); new_line;
|
put(G); new_line;
|
||||||
|
|
||||||
create_H(G, file);
|
create_H(G, file);
|
||||||
put_line("created H");
|
put_line("created H");
|
||||||
--put(G); new_line;
|
put(G); new_line;
|
||||||
|
close(file);
|
||||||
|
|
||||||
create_S(G);
|
create_S(G);
|
||||||
put_line("created S");
|
put_line("created S");
|
||||||
--put(G); new_line;
|
put(G); new_line;
|
||||||
|
|
||||||
create_G(G, alpha);
|
create_G(G, alpha);
|
||||||
put_line("created G");
|
put_line("created G");
|
||||||
--put(G); new_line;
|
put(G); new_line;
|
||||||
|
|
||||||
-- on applique l'algorithme itératif
|
-- on applique l'algorithme itératif
|
||||||
put("ite: ");
|
put("ite: ");
|
||||||
|
@ -123,12 +123,49 @@ procedure pageRank is
|
||||||
put(i, 1); put(" ");
|
put(i, 1); put(" ");
|
||||||
end loop; new_line;
|
end loop; new_line;
|
||||||
|
|
||||||
--new_line;
|
new_line;
|
||||||
--put_line("final pi:");
|
put_line("final pi:");
|
||||||
--put(pi); new_line;
|
put(pi); new_line;
|
||||||
|
|
||||||
end algorithm_naif;
|
end algorithm_naif;
|
||||||
|
|
||||||
|
-- procedure algorithm_creux();
|
||||||
|
|
||||||
|
procedure write_to_file(filename: in Unbounded_String; pi_sorted: in T_Vecteur; pi_index: in T_Vecteur) is
|
||||||
|
file: Ada.Text_IO.File_Type;
|
||||||
|
begin
|
||||||
|
|
||||||
|
create(file, Out_File, To_String(filename & ".p"));
|
||||||
|
put(file, N);
|
||||||
|
put(file, alpha);
|
||||||
|
put(file, ite_max);
|
||||||
|
new_line(file);
|
||||||
|
put(file, pi_sorted);
|
||||||
|
close(file);
|
||||||
|
|
||||||
|
create(file, Out_File, To_String(filename & ".ord"));
|
||||||
|
put(file, pi_index);
|
||||||
|
close(file);
|
||||||
|
end write_to_file;
|
||||||
|
|
||||||
|
pi, pi_sorted, pi_index: T_Vecteur;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
if naif then
|
||||||
|
algorithm_naif(N, file, alpha, ite_max, pi);
|
||||||
|
else
|
||||||
|
--algorithm_creux(N, file, alpha, ite_max, pi);
|
||||||
|
null;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
sort_with_index_desc(pi, pi_sorted, pi_index);
|
||||||
|
|
||||||
|
write_to_file(filename, pi_sorted, pi_index);
|
||||||
|
|
||||||
|
end choix_type_algo;
|
||||||
|
|
||||||
|
|
||||||
filename: Unbounded_String;
|
filename: Unbounded_String;
|
||||||
ite_max: Natural := 150;
|
ite_max: Natural := 150;
|
||||||
naif: Boolean := False;
|
naif: Boolean := False;
|
||||||
|
@ -148,14 +185,19 @@ begin
|
||||||
get(file, N); -- on récupère le nombre de pages
|
get(file, N); -- on récupère le nombre de pages
|
||||||
put("N = "); put(N, 1); new_line;
|
put("N = "); put(N, 1); new_line;
|
||||||
|
|
||||||
new_line;
|
choix_type_algo(N, filename, file, alpha, ite_max, naif);
|
||||||
|
|
||||||
algorithm_naif(N, file, alpha, ite_max);
|
|
||||||
|
|
||||||
new_line;
|
|
||||||
|
|
||||||
--sort_with_index(pi, pi_sorted, pi_index);
|
|
||||||
|
|
||||||
--write-to_file(filename);
|
|
||||||
|
|
||||||
end pageRank;
|
end pageRank;
|
||||||
|
|
||||||
|
|
||||||
|
--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)
|
Loading…
Reference in a new issue