561e1ac164
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@207849 e13453a9-b01f-0410-a051-f404c4f0c485
130 lines
3.6 KiB
Ada
130 lines
3.6 KiB
Ada
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 Google_Naive;
|
|
|
|
procedure pageRank is
|
|
|
|
Type T_Double is digits 6;
|
|
ERROR_args: Exception;
|
|
|
|
|
|
|
|
|
|
|
|
procedure get_args(filename: in out Unbounded_String;
|
|
ite_max: in out Natural;
|
|
alpha: in out Float;
|
|
naif: in out Boolean) is
|
|
i: Natural := 1;
|
|
begin
|
|
|
|
put(Argument_Count, 1); new_line;
|
|
for i in 1 .. Argument_Count loop
|
|
Put("Argument");
|
|
Put(i, 2);
|
|
Put(": ");
|
|
Put_line(Argument(i));
|
|
end loop;
|
|
|
|
-- 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
|
|
raise ERROR_args;
|
|
else
|
|
loop
|
|
if Argument(i) = "-P" then
|
|
put_line("naif");
|
|
naif := True;
|
|
i := i + 1;
|
|
elsif Argument(i) = "-A" then
|
|
put_line("alpha");
|
|
alpha := Float'Value(Argument(i+1));
|
|
i := i + 2;
|
|
elsif Argument(i) = "-I" then
|
|
put_line("iteration");
|
|
ite_max := Natural'Value(Argument(i+1)); -- verif si les conversions sont bonnes
|
|
i := i + 2;
|
|
elsif Argument(i)(Argument(i)'Last-3 .. Argument(i)'Last) = ".net" then -- verif les indexs
|
|
put_line("filename");
|
|
filename := To_Unbounded_String(Argument(i)(Argument(i)'First .. Argument(i)'Last-4));
|
|
i := i + 1;
|
|
else
|
|
put_line("erreur");
|
|
raise ERROR_args;
|
|
end if;
|
|
exit when i > Argument_Count;
|
|
end loop;
|
|
end if;
|
|
exception
|
|
-- s'il y a un problème on arrête l'exectution et on affiche l'usage.
|
|
when others =>
|
|
put_line("Erreur lors de la saisi de la commande");
|
|
put_line("Usage: pagerank [-I max_iterations] [-A alpha] [-P] fichier_reseau.net");
|
|
end get_args;
|
|
|
|
|
|
|
|
|
|
|
|
procedure algorithm_naif(N: in Positive;
|
|
file: in Ada.Text_IO.File_Type;
|
|
alpha: in Float;
|
|
ite_max: in Natural) is
|
|
|
|
package Google is
|
|
new Google_Naive(T_Element => T_Double, N => N);
|
|
use Google;
|
|
|
|
pi: T_Vecteur;
|
|
G: T_Google;
|
|
|
|
begin
|
|
|
|
put_line("initialized pi");
|
|
initialize(pi);
|
|
|
|
put_line("start algo naif");
|
|
create_H(G, file);
|
|
put_line("created H");
|
|
create_S(G);
|
|
put_line("created S");
|
|
create_G(G, alpha);
|
|
put_line("created G");
|
|
|
|
-- on applique l'algorithme itératif
|
|
for i in 1..ite_max loop
|
|
pi := pi * G;
|
|
end loop;
|
|
|
|
put(pi);
|
|
put_line("end algo naif");
|
|
|
|
end algorithm_naif;
|
|
|
|
filename: Unbounded_String;
|
|
ite_max: Natural := 150;
|
|
naif: Boolean := False;
|
|
alpha: Float := 0.85;
|
|
|
|
N: Positive;
|
|
|
|
file: Ada.Text_IO.File_Type;
|
|
|
|
begin
|
|
|
|
get_args(filename, ite_max, alpha, naif);
|
|
put_line("args OK");
|
|
|
|
open(file, In_File, To_String(filename & ".net"));
|
|
put_line("opened file");
|
|
|
|
get(file, N); -- on récupère le nombre de pages
|
|
put_line("got N");
|
|
|
|
algorithm_naif(N, file, alpha, ite_max);
|
|
|
|
end pageRank; |