ajouts de commentaires
création de google_creux.ad* (copie des naives pour l'instant) git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@209566 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
394360c5df
commit
53b44c597f
12
README.md
12
README.md
|
@ -45,14 +45,16 @@ communiquez avec votre coéquipier !
|
|||
├── build \
|
||||
├── doc \
|
||||
├── livrables \
|
||||
│ ├── raffinages.txt \
|
||||
│ └── rapport.pdf \
|
||||
│ ├── raffinages.txt \
|
||||
│ └── rapport.pdf \
|
||||
├── Makefile \
|
||||
├── README.md \
|
||||
└── src \
|
||||
├── googleNaive.ada \
|
||||
├── googleNaive.ads \
|
||||
└── pageRank.ada \
|
||||
├── google_naive.adb \
|
||||
├── google_naive.ads \
|
||||
├── pagerank.adb \
|
||||
├── vector.adb \
|
||||
└── vector.ads \
|
||||
|
||||
# Autres informations
|
||||
|
||||
|
|
72
src/google_creux.adb
Normal file
72
src/google_creux.adb
Normal file
|
@ -0,0 +1,72 @@
|
|||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
|
||||
package body Google_Creux is
|
||||
|
||||
function "*"(left : T_Vecteur; right : T_Google) return T_Vecteur is
|
||||
vec: T_Vecteur;
|
||||
c: T_Element;
|
||||
begin
|
||||
initialize(vec);
|
||||
for i in 0..N-1 loop
|
||||
c := 0.0;
|
||||
for j in 0..N-1 loop
|
||||
c := c + left(j)*right(j,i);
|
||||
end loop;
|
||||
vec(i) := c;
|
||||
end loop;
|
||||
return vec;
|
||||
end "*";
|
||||
|
||||
procedure create_H(mat: in out T_Google; file: in Ada.Text_IO.File_Type) is
|
||||
row, col: Integer;
|
||||
begin
|
||||
while not end_of_File(file) loop
|
||||
get(file, row);
|
||||
get(file, col);
|
||||
mat(row, col) := 1.0;
|
||||
end loop;
|
||||
end create_H;
|
||||
|
||||
procedure create_S(mat: in out T_Google) is
|
||||
sum: T_Element;
|
||||
begin
|
||||
for i in 0..N-1 loop
|
||||
sum := 0.0;
|
||||
for j in 0..N-1 loop
|
||||
sum := sum + mat(i,j);
|
||||
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 -- sum == 0 then
|
||||
for j in 0..N-1 loop
|
||||
mat(i,j) := 1.0/T_Element(N);
|
||||
end loop;
|
||||
end if;
|
||||
end loop;
|
||||
end create_S;
|
||||
|
||||
procedure create_G(mat: in out T_Google; alpha: in T_Element) is
|
||||
begin
|
||||
for i in 0..N-1 loop
|
||||
for j in 0..N-1 loop
|
||||
mat(i,j) := alpha*mat(i,j) + (1.0-alpha)/T_Element(N);
|
||||
end loop;
|
||||
end loop;
|
||||
end create_G;
|
||||
|
||||
procedure put(mat: in T_Google) is
|
||||
begin
|
||||
for i in 0..N-1 loop
|
||||
for j in 0..N-1 loop
|
||||
put(mat(i,j));
|
||||
end loop;
|
||||
new_line;
|
||||
end loop;
|
||||
end put;
|
||||
|
||||
end Google_Creux;
|
30
src/google_creux.ads
Normal file
30
src/google_creux.ads
Normal file
|
@ -0,0 +1,30 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Vector;
|
||||
|
||||
generic
|
||||
|
||||
type T_Element is digits <>;
|
||||
N: Positive;
|
||||
with package Vector_T_Element is new Vector(T_Element => T_Element, N => N);
|
||||
|
||||
package Google_Creux is
|
||||
|
||||
-- on permet l'affichage direct des T_Element
|
||||
package Text_T_Element is
|
||||
new Ada.Text_IO.Float_IO(Num => T_Element);
|
||||
use Text_T_Element;
|
||||
|
||||
-- on utilise le module Vector
|
||||
use Vector_T_Element;
|
||||
|
||||
type T_Google is array (0..N-1, 0..N-1) of T_Element;
|
||||
|
||||
function "*"(left: T_Vecteur; right: T_Google) return T_Vecteur;
|
||||
|
||||
procedure create_H(mat: in out T_Google; file: in Ada.Text_IO.File_Type);
|
||||
procedure create_S(mat: in out T_Google);
|
||||
procedure create_G(mat: in out T_Google; alpha: in T_Element);
|
||||
|
||||
procedure put(mat: in T_Google);
|
||||
|
||||
end Google_Creux;
|
100
src/pagerank.adb
100
src/pagerank.adb
|
@ -3,19 +3,25 @@ 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;
|
||||
with Vector;
|
||||
with Google_Naive;
|
||||
with Google_Creux;
|
||||
|
||||
procedure pageRank is
|
||||
|
||||
ERROR_args: Exception;
|
||||
|
||||
-- on définit le type T_Double, et on utilise le module générique Float_IO pour pouvoir l'afficher
|
||||
-- définition du type T_Double
|
||||
Type T_Double is digits 11;
|
||||
-- on utilise le module générique Float_IO pour pouvoir afficher T_Double directement
|
||||
package Text_T_Double is
|
||||
new Ada.Text_IO.Float_IO(Num => T_Double);
|
||||
use Text_T_Double;
|
||||
|
||||
|
||||
|
||||
|
||||
-- proédure pour récupérer les arguments de la ligne de commande
|
||||
procedure get_args(filename: in out Unbounded_String;
|
||||
ite_max: in out Natural;
|
||||
alpha: in out T_Double;
|
||||
|
@ -25,7 +31,7 @@ procedure pageRank is
|
|||
|
||||
-- on affiche tous les arguments
|
||||
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(i, 0);
|
||||
Put(") = ");
|
||||
|
@ -43,21 +49,26 @@ procedure pageRank is
|
|||
naif := True;
|
||||
i := i + 1;
|
||||
put_line("parsed naif");
|
||||
|
||||
elsif Argument(i) = "-A" then
|
||||
alpha := T_Double'Value(Argument(i+1));
|
||||
i := i + 2;
|
||||
put_line("parsed alpha");
|
||||
|
||||
elsif Argument(i) = "-I" then
|
||||
ite_max := Natural'Value(Argument(i+1));
|
||||
i := i + 2;
|
||||
put_line("parsed ite_max");
|
||||
|
||||
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));
|
||||
i := i + 1;
|
||||
put_line("parsed filename");
|
||||
|
||||
else
|
||||
put_line("unexpected passing case");
|
||||
raise ERROR_args;
|
||||
|
||||
end if;
|
||||
exit when i > Argument_Count;
|
||||
end loop;
|
||||
|
@ -74,27 +85,37 @@ procedure pageRank is
|
|||
when others => raise ERROR_args;
|
||||
end get_args;
|
||||
|
||||
procedure choix_type_algo(N: Natural;
|
||||
filename: in Unbounded_String;
|
||||
file: in out Ada.Text_IO.File_Type;
|
||||
alpha: T_Double;
|
||||
ite_max: Natural;
|
||||
naif: Boolean) is
|
||||
|
||||
-- on utilise le module générique
|
||||
|
||||
|
||||
-- procédure pour choisir le type d'algo, une fois N et les arguments récupérés
|
||||
procedure type_algo(N: Natural;
|
||||
filename: in Unbounded_String;
|
||||
file: in out Ada.Text_IO.File_Type;
|
||||
alpha: T_Double;
|
||||
ite_max: Natural;
|
||||
naif: Boolean) is
|
||||
|
||||
-- on instancie le module générique Vecteur
|
||||
package Vector_T_Double is
|
||||
new Vector(T_Element => T_Double, N => N);
|
||||
new Vector(T_Element => T_Double,
|
||||
N => N);
|
||||
use Vector_T_Double;
|
||||
|
||||
-- procédure qui effectue l'algorithme du pageRank avec Google_Naive
|
||||
procedure algorithm_naif(file: in out Ada.Text_IO.File_Type;
|
||||
alpha: in T_Double;
|
||||
ite_max: in Natural;
|
||||
pi: out T_Vecteur) is
|
||||
|
||||
-- on utilise le module générique
|
||||
-- on instancie le module générique Naif de Google
|
||||
package Google is
|
||||
new Google_Naive(T_Element => T_Double, N => N, Vector_T_Element => Vector_T_Double);
|
||||
new Google_Naive(T_Element => T_Double,
|
||||
N => N,
|
||||
Vector_T_Element => Vector_T_Double);
|
||||
use Google;
|
||||
|
||||
-- définition de la matrice Google
|
||||
G: T_Google;
|
||||
|
||||
begin
|
||||
|
@ -133,10 +154,39 @@ procedure pageRank is
|
|||
|
||||
end algorithm_naif;
|
||||
|
||||
-- procedure algorithm_creux(); -- TODO
|
||||
-- procédure qui effectue l'algorithme du pageRank avec Google_Creux
|
||||
procedure algorithm_creux(file: in out Ada.Text_IO.File_Type;
|
||||
alpha: in T_Double;
|
||||
ite_max: in Natural;
|
||||
pi: out T_Vecteur) is
|
||||
|
||||
-- on instancie le module générique Creux de Google
|
||||
package Google is
|
||||
new Google_Creux(T_Element => T_Double,
|
||||
N => N,
|
||||
Vector_T_Element => Vector_T_Double);
|
||||
use Google;
|
||||
|
||||
-- définition de la matrice Google
|
||||
G: T_Google;
|
||||
|
||||
begin
|
||||
|
||||
put("TODO");
|
||||
|
||||
end algorithm_creux;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- procédure pour écrire les résultats dans les fichiers
|
||||
procedure write_to_files(filename: in Unbounded_String;
|
||||
pi_sorted: in T_Vecteur;
|
||||
pi_index: in T_Vecteur_Index) is
|
||||
|
||||
procedure write_to_files(filename: in Unbounded_String; pi_sorted: in T_Vecteur; pi_index: in T_Vecteur_Index) is
|
||||
file: Ada.Text_IO.File_Type;
|
||||
|
||||
begin
|
||||
create(file, Out_File, To_String(filename & ".p"));
|
||||
put(file, N, 1);
|
||||
|
@ -151,6 +201,11 @@ procedure pageRank is
|
|||
close(file);
|
||||
end write_to_files;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- définition des vecteurs
|
||||
pi: T_Vecteur;
|
||||
pi_index: T_Vecteur_Index;
|
||||
|
||||
|
@ -159,8 +214,7 @@ procedure pageRank is
|
|||
if naif then
|
||||
algorithm_naif(file, alpha, ite_max, pi);
|
||||
else
|
||||
--algorithm_creux(N, file, alpha, ite_max, pi);
|
||||
put_line("TODO");
|
||||
algorithm_creux(file, alpha, ite_max, pi);
|
||||
end if;
|
||||
|
||||
-- on trie les poids par ordre décroissant, on tri en même temps les indices des pages
|
||||
|
@ -174,15 +228,19 @@ procedure pageRank is
|
|||
-- on écrit les resultats dans des fichiers
|
||||
write_to_files(filename, pi, pi_index);
|
||||
|
||||
end choix_type_algo;
|
||||
end type_algo;
|
||||
|
||||
-- initialisation des arguments
|
||||
|
||||
|
||||
|
||||
|
||||
-- définition des arguments
|
||||
filename: Unbounded_String;
|
||||
ite_max: Natural := 150;
|
||||
naif: Boolean := False;
|
||||
alpha: T_Double := 0.85;
|
||||
|
||||
-- initialisation des variables pour créer les matices/vecteurs
|
||||
-- définition des variables pour créer les matices/vecteurs
|
||||
N: Positive;
|
||||
file: Ada.Text_IO.File_Type;
|
||||
|
||||
|
@ -201,7 +259,7 @@ begin
|
|||
put("N = "); put(N, 1); new_line;
|
||||
|
||||
-- on peut maintenant choisir le type de matrice que l'on souhaite
|
||||
choix_type_algo(N, filename, file, alpha, ite_max, naif);
|
||||
type_algo(N, filename, file, alpha, ite_max, naif);
|
||||
|
||||
exception
|
||||
|
||||
|
|
Loading…
Reference in a new issue