From c8a03f9eaebc99988a3133a32893eb041e05ec23 Mon Sep 17 00:00:00 2001 From: lfainsin Date: Sun, 24 Jan 2021 09:26:20 +0000 Subject: [PATCH] git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@214003 e13453a9-b01f-0410-a051-f404c4f0c485 --- src/google.adb | 19 ++++++------------- src/google.ads | 5 ++++- src/pagerank.adb | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/google.adb b/src/google.adb index ddfc83b..eaa5212 100644 --- a/src/google.adb +++ b/src/google.adb @@ -119,11 +119,10 @@ package body Google is procedure create_Google(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is row, col: Natural; - offset: Natural; begin initialize(mat.Rows, 0); - initialize(mat.Cols, -1); + initialize(mat.Cols, N); for i in 0..N_Links-1 loop get(file, row); @@ -139,19 +138,13 @@ package body Google is for i in 0..N_Links-1 loop get(file, row); get(file, col); - - if row = N then - offset := 0; - else - offset := mat.rows(row+1) - mat.rows(row); - end if; - for j in 0..offset loop + for j in mat.rows(row)..mat.rows(row+1)-1 loop - exit when mat.cols(mat.rows(row)+j) = col; -- anti-doublon + exit when mat.cols(j) = col; -- anti-doublon - if mat.cols(mat.rows(row)+j) = -1 then - mat.cols(mat.rows(row)+j) := col; + if mat.cols(j) >= N then + mat.cols(j) := col; exit; end if; @@ -196,7 +189,7 @@ package body Google is for j in mat.rows(i)..mat.rows(i+1)-1 loop index_col := mat.cols(j); - if index_col /= -1 then -- anti calcul d'un doublon + if index_col < N then -- anti calcul d'un doublon new_vec(index_col) := new_vec(index_col) + alpha*vec(i)/T_Reel(nb_col); end if; end loop; diff --git a/src/google.ads b/src/google.ads index cd73475..f9e985b 100644 --- a/src/google.ads +++ b/src/google.ads @@ -55,11 +55,14 @@ package Google is package Vector_Rows is new Vector.Entier(T_Entier => Natural, Capacite => N+1); package Vector_Cols is - new Vector.Entier(T_Entier => Integer, Capacite => N_Links); + new Vector.Entier(T_Entier => Natural, Capacite => N_Links); use Vector_Rows; use Vector_Cols; + type T_Rows is array (0..N) of Natural; + type T_Cols is array (0..N_Links-1) of Natural; + -- on définit le type T_Google correspondant à une matrice CSC type T_Google is record rows: Vector_Rows.T_Vecteur; diff --git a/src/pagerank.adb b/src/pagerank.adb index f3801d7..ede3e22 100644 --- a/src/pagerank.adb +++ b/src/pagerank.adb @@ -19,7 +19,7 @@ procedure pageRank is INFO_help: Exception; -- définition du type T_Reel - Type T_Reel is digits 6; + Type T_Reel is digits 18; -- on utilise le module générique Float_IO pour pouvoir afficher T_Reel directement package Text_T_Reel is new Ada.Text_IO.Float_IO(Num => T_Reel); @@ -172,6 +172,7 @@ begin skip_line(file); declare + -- on peut maintenant créer nos vecteurs package Vector_Entier is new Vector.Entier(T_Entier => Natural, Capacite => N);