pageRank naif fonctionne, ajout de prints de debug
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@208511 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
561e1ac164
commit
f089f32c83
|
@ -8,7 +8,7 @@ package body Google_Naive is
|
||||||
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
|
||||||
c := c + left(i)*right(i,j);
|
c := c + left(j)*right(j,i);
|
||||||
end loop;
|
end loop;
|
||||||
vec(i) := c;
|
vec(i) := c;
|
||||||
end loop;
|
end loop;
|
||||||
|
@ -27,13 +27,13 @@ package body Google_Naive is
|
||||||
return mat;
|
return mat;
|
||||||
end "*";
|
end "*";
|
||||||
|
|
||||||
function "/"(left: T_Google; right: T_Element) return T_Google is
|
function "/"(left: T_Google; right: Float) return T_Google is
|
||||||
mat: T_Google;
|
mat: T_Google;
|
||||||
begin
|
begin
|
||||||
initialize(mat);
|
initialize(mat);
|
||||||
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
|
||||||
mat(i,j) := left(i,j)/right;
|
mat(i,j) := left(i,j)/T_Element(right);
|
||||||
end loop;
|
end loop;
|
||||||
end loop;
|
end loop;
|
||||||
return mat;
|
return mat;
|
||||||
|
@ -63,7 +63,7 @@ package body Google_Naive is
|
||||||
procedure initialize(vec: in out T_Vecteur) is
|
procedure initialize(vec: in out T_Vecteur) is
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
vec(i) := 0.0;
|
vec(i) := 1.0/T_Element(N);
|
||||||
end loop;
|
end loop;
|
||||||
end initialize;
|
end initialize;
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ package body Google_Naive is
|
||||||
mat: T_Google;
|
mat: T_Google;
|
||||||
begin
|
begin
|
||||||
initialize(mat);
|
initialize(mat);
|
||||||
for i in 1..N-1 loop
|
for i in 0..N-1 loop
|
||||||
for j in 1..N-1 loop
|
for j in 0..N-1 loop
|
||||||
mat(i,j) := 1.0;
|
mat(i,j) := 1.0;
|
||||||
end loop;
|
end loop;
|
||||||
end loop;
|
end loop;
|
||||||
|
@ -98,25 +98,27 @@ package body Google_Naive is
|
||||||
sum: T_Element;
|
sum: T_Element;
|
||||||
begin
|
begin
|
||||||
for i in 0..N-1 loop
|
for i in 0..N-1 loop
|
||||||
sum := 0.0;
|
sum := 0.0;
|
||||||
for j in 0..N-1 loop
|
for j in 0..N-1 loop
|
||||||
sum := sum + mat(i,j);
|
sum := sum + mat(i,j);
|
||||||
end loop;
|
|
||||||
if sum /= 0.0 then
|
|
||||||
for j in 0..N-1 loop
|
|
||||||
mat(i,j) := 1.0/sum;
|
|
||||||
end loop;
|
|
||||||
else
|
|
||||||
for j in 0..N-1 loop
|
|
||||||
mat(i,j) := 1.0 / T_Element(N);
|
|
||||||
end loop;
|
|
||||||
end if;
|
|
||||||
end loop;
|
end loop;
|
||||||
|
if sum /= 0.0 then
|
||||||
|
for j in 0..N-1 loop
|
||||||
|
if mat(i,j) /= 0.0 then
|
||||||
|
mat(i,j) := 1.0/sum;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
else
|
||||||
|
for j in 0..N-1 loop
|
||||||
|
mat(i,j) := 1.0 / T_Element(N);
|
||||||
|
end loop;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
end create_S;
|
end create_S;
|
||||||
|
|
||||||
procedure create_G(mat: in out T_Google ; alpha: in Float) is
|
procedure create_G(mat: in out T_Google ; alpha: in Float) is
|
||||||
begin
|
begin
|
||||||
mat := ( alpha * mat ) + ( Float((1.0-alpha)/Float(N)) * ones );
|
mat := alpha*mat + (1.0-alpha)/Float(N)*ones;
|
||||||
end create_G;
|
end create_G;
|
||||||
|
|
||||||
procedure put(vec: in T_Vecteur) is
|
procedure put(vec: in T_Vecteur) is
|
||||||
|
@ -126,4 +128,14 @@ package body Google_Naive is
|
||||||
end loop;
|
end loop;
|
||||||
end put;
|
end put;
|
||||||
|
|
||||||
|
procedure put(mat: in T_Google) is
|
||||||
|
begin
|
||||||
|
for i in 0..N-1 loop
|
||||||
|
for j in 0..N-1 loop
|
||||||
|
put(Float(mat(i,j)));
|
||||||
|
end loop;
|
||||||
|
new_line;
|
||||||
|
end loop;
|
||||||
|
end put;
|
||||||
|
|
||||||
end Google_Naive;
|
end Google_Naive;
|
||||||
|
|
|
@ -12,10 +12,9 @@ package Google_Naive is
|
||||||
type T_Google is private;
|
type T_Google is private;
|
||||||
type T_Vecteur is private;
|
type T_Vecteur is private;
|
||||||
|
|
||||||
function "*"(left : T_Vecteur ; right : T_Google) return T_Vecteur;
|
function "*"(left: T_Vecteur ; right: T_Google) return T_Vecteur;
|
||||||
function "*"(left: Float; right: T_Google) return T_Google;
|
function "*"(left: Float; right: T_Google) return T_Google;
|
||||||
function "/"(left: T_Google; right: T_Element) return T_Google with
|
function "/"(left: T_Google; right: Float) return T_Google with Pre => right /= 0.0;
|
||||||
Pre => right /= 0.0;
|
|
||||||
function "+"(left, right: T_Google) return T_Google;
|
function "+"(left, right: T_Google) return T_Google;
|
||||||
|
|
||||||
procedure initialize(mat: in out T_Google);
|
procedure initialize(mat: in out T_Google);
|
||||||
|
@ -30,6 +29,7 @@ package Google_Naive is
|
||||||
procedure create_G(mat: in out T_Google ; alpha: in Float);
|
procedure create_G(mat: in out T_Google ; alpha: in Float);
|
||||||
|
|
||||||
procedure put(vec: in T_Vecteur);
|
procedure put(vec: in T_Vecteur);
|
||||||
|
procedure put(mat: in T_Google);
|
||||||
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;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
with Ada.Text_IO; use Ada.Text_IO;
|
with Ada.Text_IO; use Ada.Text_IO;
|
||||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||||
|
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||||
with Ada.Command_Line; use Ada.Command_Line;
|
with Ada.Command_Line; use Ada.Command_Line;
|
||||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||||
|
|
||||||
|
@ -23,44 +23,56 @@ procedure pageRank is
|
||||||
i: Natural := 1;
|
i: Natural := 1;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
put(Argument_Count, 1); new_line;
|
put("Argument_Count = "); put(Argument_Count, 1); new_line;
|
||||||
for i in 1 .. Argument_Count loop
|
for i in 1 .. Argument_Count loop
|
||||||
Put("Argument");
|
Put("Argument(");
|
||||||
Put(i, 2);
|
Put(i, 0);
|
||||||
Put(": ");
|
Put(") = ");
|
||||||
Put_line(Argument(i));
|
Put_line(Argument(i));
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
|
new_line;
|
||||||
|
|
||||||
-- on vérifie d'abord que le nombre d'arguments est cohérent
|
-- on vérifie d'abord que le nombre d'arguments est cohérent
|
||||||
if not(0 < Argument_Count and Argument_Count <= 6) then -- verif si double inégalité possible
|
if not(0 < Argument_Count and Argument_Count <= 6) then
|
||||||
raise ERROR_args;
|
raise ERROR_args;
|
||||||
else
|
else -- sinon on parse les arguments
|
||||||
loop
|
loop
|
||||||
if Argument(i) = "-P" then
|
if Argument(i) = "-P" then
|
||||||
put_line("naif");
|
|
||||||
naif := True;
|
naif := True;
|
||||||
i := i + 1;
|
i := i + 1;
|
||||||
|
put_line("parsed naif");
|
||||||
elsif Argument(i) = "-A" then
|
elsif Argument(i) = "-A" then
|
||||||
put_line("alpha");
|
|
||||||
alpha := Float'Value(Argument(i+1));
|
alpha := Float'Value(Argument(i+1));
|
||||||
i := i + 2;
|
i := i + 2;
|
||||||
|
put_line("parsed alpha");
|
||||||
elsif Argument(i) = "-I" then
|
elsif Argument(i) = "-I" then
|
||||||
put_line("iteration");
|
ite_max := Natural'Value(Argument(i+1));
|
||||||
ite_max := Natural'Value(Argument(i+1)); -- verif si les conversions sont bonnes
|
|
||||||
i := i + 2;
|
i := i + 2;
|
||||||
elsif Argument(i)(Argument(i)'Last-3 .. Argument(i)'Last) = ".net" then -- verif les indexs
|
put_line("parsed ite_max");
|
||||||
put_line("filename");
|
elsif Argument(i)(Argument(i)'Last-3 .. Argument(i)'Last) = ".net" then
|
||||||
filename := To_Unbounded_String(Argument(i)(Argument(i)'First .. Argument(i)'Last-4));
|
filename := To_Unbounded_String(Argument(i)(Argument(i)'First .. Argument(i)'Last-4));
|
||||||
i := i + 1;
|
i := i + 1;
|
||||||
|
put_line("parsed filename");
|
||||||
else
|
else
|
||||||
put_line("erreur");
|
put_line("unexpected passing case");
|
||||||
raise ERROR_args;
|
raise ERROR_args;
|
||||||
end if;
|
end if;
|
||||||
exit when i > Argument_Count;
|
exit when i > Argument_Count;
|
||||||
end loop;
|
end loop;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
new_line;
|
||||||
|
|
||||||
|
put("alpha = "); put(alpha, 1); new_line;
|
||||||
|
put("naif = "); put(Boolean'Pos(naif), 1); new_line;
|
||||||
|
put("ite_max = "); put(Float(ite_max), 1); new_line;
|
||||||
|
put("filename = "); put_line(To_String(filename));
|
||||||
|
|
||||||
|
new_line;
|
||||||
|
|
||||||
exception
|
exception
|
||||||
-- s'il y a un problème on arrête l'exectution et on affiche l'usage.
|
-- s'il y a un problème on arrête l'execution et on affiche l'usage.
|
||||||
when others =>
|
when others =>
|
||||||
put_line("Erreur lors de la saisi de la commande");
|
put_line("Erreur lors de la saisi de la commande");
|
||||||
put_line("Usage: pagerank [-I max_iterations] [-A alpha] [-P] fichier_reseau.net");
|
put_line("Usage: pagerank [-I max_iterations] [-A alpha] [-P] fichier_reseau.net");
|
||||||
|
@ -84,24 +96,36 @@ procedure pageRank is
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
put_line("initialized pi");
|
|
||||||
initialize(pi);
|
initialize(pi);
|
||||||
|
put_line("initialized pi");
|
||||||
|
--put(pi); new_line;
|
||||||
|
|
||||||
put_line("start algo naif");
|
initialize(G);
|
||||||
|
put_line("initialized G");
|
||||||
|
--put(G); new_line;
|
||||||
|
|
||||||
create_H(G, file);
|
create_H(G, file);
|
||||||
put_line("created H");
|
put_line("created H");
|
||||||
|
--put(G); new_line;
|
||||||
|
|
||||||
create_S(G);
|
create_S(G);
|
||||||
put_line("created S");
|
put_line("created S");
|
||||||
|
--put(G); new_line;
|
||||||
|
|
||||||
create_G(G, alpha);
|
create_G(G, alpha);
|
||||||
put_line("created G");
|
put_line("created G");
|
||||||
|
--put(G); new_line;
|
||||||
|
|
||||||
-- on applique l'algorithme itératif
|
-- on applique l'algorithme itératif
|
||||||
|
put("ite: ");
|
||||||
for i in 1..ite_max loop
|
for i in 1..ite_max loop
|
||||||
pi := pi * G;
|
pi := pi * G;
|
||||||
end loop;
|
put(i, 1); put(" ");
|
||||||
|
end loop; new_line;
|
||||||
|
|
||||||
put(pi);
|
--new_line;
|
||||||
put_line("end algo naif");
|
--put_line("final pi:");
|
||||||
|
--put(pi); new_line;
|
||||||
|
|
||||||
end algorithm_naif;
|
end algorithm_naif;
|
||||||
|
|
||||||
|
@ -111,7 +135,6 @@ procedure pageRank is
|
||||||
alpha: Float := 0.85;
|
alpha: Float := 0.85;
|
||||||
|
|
||||||
N: Positive;
|
N: Positive;
|
||||||
|
|
||||||
file: Ada.Text_IO.File_Type;
|
file: Ada.Text_IO.File_Type;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -120,11 +143,19 @@ begin
|
||||||
put_line("args OK");
|
put_line("args OK");
|
||||||
|
|
||||||
open(file, In_File, To_String(filename & ".net"));
|
open(file, In_File, To_String(filename & ".net"));
|
||||||
put_line("opened file");
|
put_line("file OK");
|
||||||
|
|
||||||
get(file, N); -- on récupère le nombre de pages
|
get(file, N); -- on récupère le nombre de pages
|
||||||
put_line("got N");
|
put("N = "); put(N, 1); new_line;
|
||||||
|
|
||||||
|
new_line;
|
||||||
|
|
||||||
algorithm_naif(N, file, alpha, ite_max);
|
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;
|
Loading…
Reference in a new issue