small fixes
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@209145 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
ef9cb81ff8
commit
32aedad426
|
@ -1,6 +1,6 @@
|
|||
package body Google_Naive is
|
||||
|
||||
function "*"(left : T_Vecteur ; right : T_Google) return T_Vecteur is
|
||||
function "*"(left : T_Vecteur; right : T_Google) return T_Vecteur is
|
||||
vec: T_Vecteur;
|
||||
c: T_Element;
|
||||
begin
|
||||
|
@ -15,7 +15,7 @@ package body Google_Naive is
|
|||
return vec;
|
||||
end "*";
|
||||
|
||||
function "*"(left: Float; right: T_Google) return T_Google is
|
||||
function "*"(left: T_Element; right: T_Google) return T_Google is
|
||||
mat: T_Google;
|
||||
begin
|
||||
initialize(mat);
|
||||
|
@ -27,7 +27,7 @@ package body Google_Naive is
|
|||
return mat;
|
||||
end "*";
|
||||
|
||||
function "/"(left: T_Google; right: Float) return T_Google is
|
||||
function "/"(left: T_Google; right: T_Element) return T_Google is
|
||||
mat: T_Google;
|
||||
begin
|
||||
initialize(mat);
|
||||
|
@ -84,7 +84,7 @@ package body Google_Naive is
|
|||
mat(i,j) := elm;
|
||||
end insert;
|
||||
|
||||
procedure create_H(mat: in out T_Google ; file: in Ada.Text_IO.File_Type) is
|
||||
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
|
||||
|
@ -116,9 +116,9 @@ package body Google_Naive is
|
|||
end loop;
|
||||
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 T_Element) is
|
||||
begin
|
||||
mat := alpha*mat + (1.0-alpha)/Float(N)*ones;
|
||||
mat := alpha*mat + (1.0-alpha)/T_Element(N)*ones;
|
||||
end create_G;
|
||||
|
||||
procedure put(vec: in T_Vecteur) is
|
||||
|
|
|
@ -12,9 +12,9 @@ package Google_Naive is
|
|||
type T_Google is private;
|
||||
type T_Vecteur is private;
|
||||
|
||||
function "*"(left: T_Vecteur ; right: T_Google) return T_Vecteur;
|
||||
function "*"(left: Float; right: T_Google) return T_Google;
|
||||
function "/"(left: T_Google; right: Float) return T_Google with Pre => right /= 0.0;
|
||||
function "*"(left: T_Vecteur; right: T_Google) return T_Vecteur;
|
||||
function "*"(left: T_Element; right: T_Google) return T_Google;
|
||||
function "/"(left: T_Google; right: T_Element) return T_Google with Pre => right /= 0.0;
|
||||
function "+"(left, right: T_Google) return T_Google;
|
||||
|
||||
procedure initialize(mat: in out T_Google);
|
||||
|
@ -24,9 +24,9 @@ package Google_Naive is
|
|||
|
||||
procedure insert(mat: in out T_Google; i, j: Natural; elm: T_Element);
|
||||
|
||||
procedure create_H(mat: in out T_Google ; file: in Ada.Text_IO.File_Type);
|
||||
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 Float);
|
||||
procedure create_G(mat: in out T_Google; alpha: in T_Element);
|
||||
|
||||
procedure put(vec: in T_Vecteur);
|
||||
procedure put(mat: in T_Google);
|
||||
|
@ -34,6 +34,7 @@ package Google_Naive is
|
|||
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
|
||||
|
||||
type T_Google is array (0..N-1, 0..N-1) of T_Element;
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
with Ada.Text_IO; use Ada.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.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
|
||||
|
||||
with Google_Naive;
|
||||
|
||||
procedure pageRank is
|
||||
|
||||
Type T_Double is digits 6;
|
||||
ERROR_args: Exception;
|
||||
|
||||
|
||||
|
||||
|
||||
-- on définit le type T_Double, et on utilise le module générique Float_IO pour pouvoir l'afficher
|
||||
Type T_Double is digits 10;
|
||||
package Text_T_Double is
|
||||
new Ada.Text_IO.Float_IO(Num => T_Double);
|
||||
use Text_T_Double;
|
||||
|
||||
procedure get_args(filename: in out Unbounded_String;
|
||||
ite_max: in out Natural;
|
||||
alpha: in out Float;
|
||||
alpha: in out T_Double;
|
||||
naif: in out Boolean) is
|
||||
i: Natural := 1;
|
||||
begin
|
||||
|
||||
-- on affiche tous les arguments
|
||||
put("Argument_Count = "); put(Argument_Count, 1); new_line;
|
||||
for i in 1 .. Argument_Count loop
|
||||
Put("Argument(");
|
||||
|
@ -43,7 +43,7 @@ procedure pageRank is
|
|||
i := i + 1;
|
||||
put_line("parsed naif");
|
||||
elsif Argument(i) = "-A" then
|
||||
alpha := Float'Value(Argument(i+1));
|
||||
alpha := T_Double'Value(Argument(i+1));
|
||||
i := i + 2;
|
||||
put_line("parsed alpha");
|
||||
elsif Argument(i) = "-I" then
|
||||
|
@ -63,36 +63,33 @@ procedure pageRank is
|
|||
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("ite_max = "); put(ite_max, 1); new_line;
|
||||
put("filename = "); put_line(To_String(filename));
|
||||
|
||||
new_line;
|
||||
|
||||
exception
|
||||
-- s'il y a un problème on arrête l'execution 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");
|
||||
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: Float; ite_max: Natural; naif: Boolean) is
|
||||
|
||||
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
|
||||
package Google is
|
||||
new Google_Naive(T_Element => T_Double, N => N);
|
||||
use Google;
|
||||
|
||||
procedure algorithm_naif(N: in Positive;
|
||||
file: in out Ada.Text_IO.File_Type;
|
||||
alpha: in Float;
|
||||
alpha: in T_Double;
|
||||
ite_max: in Natural;
|
||||
pi: out T_Vecteur) is
|
||||
|
||||
G: T_Google;
|
||||
|
||||
begin
|
||||
|
||||
initialize(pi);
|
||||
|
@ -101,20 +98,20 @@ procedure pageRank is
|
|||
|
||||
initialize(G);
|
||||
put_line("initialized G");
|
||||
put(G); new_line;
|
||||
--put(G); new_line;
|
||||
|
||||
create_H(G, file);
|
||||
put_line("created H");
|
||||
put(G); new_line;
|
||||
close(file);
|
||||
--put(G); new_line;
|
||||
|
||||
create_S(G);
|
||||
put_line("created S");
|
||||
put(G); new_line;
|
||||
--put(G); new_line;
|
||||
|
||||
create_G(G, alpha);
|
||||
put_line("created G");
|
||||
put(G); new_line;
|
||||
--put(G); new_line;
|
||||
|
||||
-- on applique l'algorithme itératif
|
||||
put("ite: ");
|
||||
|
@ -123,18 +120,17 @@ procedure pageRank is
|
|||
put(i, 1); put(" ");
|
||||
end loop; new_line;
|
||||
|
||||
new_line;
|
||||
put_line("final pi:");
|
||||
put(pi); new_line;
|
||||
--new_line;
|
||||
--put_line("final pi:");
|
||||
--put(pi); new_line;
|
||||
|
||||
end algorithm_naif;
|
||||
|
||||
-- procedure algorithm_creux();
|
||||
-- procedure algorithm_creux(); -- TODO
|
||||
|
||||
procedure write_to_file(filename: in Unbounded_String; pi_sorted: in T_Vecteur; pi_index: in T_Vecteur) is
|
||||
procedure write_to_files(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);
|
||||
|
@ -146,7 +142,7 @@ procedure pageRank is
|
|||
create(file, Out_File, To_String(filename & ".ord"));
|
||||
put(file, pi_index);
|
||||
close(file);
|
||||
end write_to_file;
|
||||
end write_to_files;
|
||||
|
||||
pi, pi_sorted, pi_index: T_Vecteur;
|
||||
|
||||
|
@ -156,48 +152,49 @@ procedure pageRank is
|
|||
algorithm_naif(N, file, alpha, ite_max, pi);
|
||||
else
|
||||
--algorithm_creux(N, file, alpha, ite_max, pi);
|
||||
null;
|
||||
put_line("TODO");
|
||||
end if;
|
||||
|
||||
-- on trie les poids par ordre décroissant, on tri en même temps les indices des pages
|
||||
sort_with_index_desc(pi, pi_sorted, pi_index);
|
||||
|
||||
write_to_file(filename, pi_sorted, pi_index);
|
||||
-- on écrit les resultats dans des fichiers
|
||||
write_to_files(filename, pi_sorted, pi_index);
|
||||
|
||||
end choix_type_algo;
|
||||
|
||||
|
||||
-- initialisation des arguments
|
||||
filename: Unbounded_String;
|
||||
ite_max: Natural := 150;
|
||||
naif: Boolean := False;
|
||||
alpha: Float := 0.85;
|
||||
alpha: T_Double := 0.85;
|
||||
|
||||
-- initialisation des variables pour créer les matices/vecteurs
|
||||
N: Positive;
|
||||
file: Ada.Text_IO.File_Type;
|
||||
|
||||
begin
|
||||
|
||||
-- on récupère les arguments de la ligne de commande
|
||||
get_args(filename, ite_max, alpha, naif);
|
||||
put_line("args OK");
|
||||
|
||||
-- on ouvre le fichier .net
|
||||
open(file, In_File, To_String(filename & ".net"));
|
||||
put_line("file OK");
|
||||
|
||||
get(file, N); -- on récupère le nombre de pages
|
||||
-- on récupère le nombre de pages
|
||||
get(file, N);
|
||||
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);
|
||||
|
||||
exception
|
||||
|
||||
-- si il y a une erreur lors du parsing des arguments, on rappelle l'usage.
|
||||
when ERROR_args =>
|
||||
put_line("Erreur lors de la saisi de la commande");
|
||||
put_line("Usage: pagerank [-I max_iterations] [-A alpha] [-P] fichier_reseau.net");
|
||||
|
||||
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