Le programme Creux semble marcher sauf pour Linux26, il faut trouver un autre moyen de récupérer H.
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210383 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
ef72ba257c
commit
1c8b7d9082
|
@ -4,22 +4,59 @@ package body Google_Creux is
|
||||||
|
|
||||||
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is
|
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is
|
||||||
row, col: Natural;
|
row, col: Natural;
|
||||||
nb: Natural := 0;
|
row_last: Natural;
|
||||||
|
nb: Integer := 1;
|
||||||
|
power: Natural := 1;
|
||||||
|
N_tmp: Natural := N;
|
||||||
|
links: T_Vecteur_Links;
|
||||||
begin
|
begin
|
||||||
mat.rows(0) := 0;
|
|
||||||
for i in 0..N-1 loop
|
while N_tmp > 9 loop
|
||||||
reset(file, In_File);
|
N_tmp := N_tmp / 10;
|
||||||
skip_line(file);
|
power := power + 1;
|
||||||
for j in 0..N_links-1 loop
|
|
||||||
get(file, row);
|
|
||||||
get(file, col);
|
|
||||||
if row = i then
|
|
||||||
mat.cols(nb) := col;
|
|
||||||
nb := nb + 1;
|
|
||||||
end if;
|
|
||||||
end loop;
|
|
||||||
mat.rows(i+1) := nb;
|
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
|
put("power = "); put(power, 1); new_line;
|
||||||
|
|
||||||
|
for i in 0..N_links-1 loop
|
||||||
|
get(file, row);
|
||||||
|
get(file, col);
|
||||||
|
links(i) := row*(10**power) + col;
|
||||||
|
end loop;
|
||||||
|
close(file);
|
||||||
|
|
||||||
|
put_line("got links: ");
|
||||||
|
-- put(links); new_line;
|
||||||
|
|
||||||
|
-- à faire: vérifier si la liste set déjà triée avant de trier
|
||||||
|
quicksort(links, 0, N_links-1);
|
||||||
|
|
||||||
|
put_line("sorted links: ");
|
||||||
|
-- put(links); new_line;
|
||||||
|
|
||||||
|
mat.rows(N) := N_links;
|
||||||
|
mat.rows(0) := 0;
|
||||||
|
row_last := 0;
|
||||||
|
mat.cols(0) := links(0) mod 10**power;
|
||||||
|
|
||||||
|
for i in 1..N-1 loop
|
||||||
|
mat.rows(i) := 0;
|
||||||
|
end loop;
|
||||||
|
for i in 1..N_links-1 loop
|
||||||
|
mat.cols(i) := 0;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
for i in 1..N_links-1 loop
|
||||||
|
row := links(i) / 10**power;
|
||||||
|
col := links(i) mod 10**power;
|
||||||
|
mat.cols(i) := col;
|
||||||
|
for j in 1..row-row_last loop
|
||||||
|
mat.rows(nb) := i;
|
||||||
|
nb := nb + 1;
|
||||||
|
end loop;
|
||||||
|
row_last := row;
|
||||||
|
end loop;
|
||||||
|
|
||||||
end create_H;
|
end create_H;
|
||||||
|
|
||||||
procedure put(mat: in T_Google) is
|
procedure put(mat: in T_Google) is
|
||||||
|
@ -27,7 +64,7 @@ package body Google_Creux is
|
||||||
for i in 0..N_links-1 loop
|
for i in 0..N_links-1 loop
|
||||||
put(mat.cols(i));
|
put(mat.cols(i));
|
||||||
end loop;
|
end loop;
|
||||||
new_line;
|
new_line; new_line;
|
||||||
for i in 0..N loop
|
for i in 0..N loop
|
||||||
put(mat.rows(i));
|
put(mat.rows(i));
|
||||||
end loop;
|
end loop;
|
||||||
|
|
|
@ -6,7 +6,7 @@ generic
|
||||||
type T_Element is digits <>;
|
type T_Element is digits <>;
|
||||||
N: Positive;
|
N: Positive;
|
||||||
N_links: Positive;
|
N_links: Positive;
|
||||||
with package Vector_T_Element is new Vector(T_Element => T_Element, N => N);
|
with package Vector_T_Element is new Vector(T_Element => T_Element, N => N, N_links => N_links);
|
||||||
|
|
||||||
package Google_Creux is
|
package Google_Creux is
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ generic
|
||||||
|
|
||||||
type T_Element is digits <>;
|
type T_Element is digits <>;
|
||||||
N: Positive;
|
N: Positive;
|
||||||
with package Vector_T_Element is new Vector(T_Element => T_Element, N => N);
|
N_links: Positive;
|
||||||
|
with package Vector_T_Element is new Vector(T_Element => T_Element, N => N, N_links => N_links);
|
||||||
|
|
||||||
package Google_Naive is
|
package Google_Naive is
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,8 @@ procedure pageRank is
|
||||||
-- on instancie le module générique Vecteur
|
-- on instancie le module générique Vecteur
|
||||||
package Vector_T_Double is
|
package Vector_T_Double is
|
||||||
new Vector(T_Element => T_Double,
|
new Vector(T_Element => T_Double,
|
||||||
N => N);
|
N => N,
|
||||||
|
N_links => N_links);
|
||||||
use Vector_T_Double;
|
use Vector_T_Double;
|
||||||
|
|
||||||
-- pour le retour chariot
|
-- pour le retour chariot
|
||||||
|
@ -154,6 +155,7 @@ procedure pageRank is
|
||||||
package Google is
|
package Google is
|
||||||
new Google_Naive(T_Element => T_Double,
|
new Google_Naive(T_Element => T_Double,
|
||||||
N => N,
|
N => N,
|
||||||
|
N_links => N_links,
|
||||||
Vector_T_Element => Vector_T_Double);
|
Vector_T_Element => Vector_T_Double);
|
||||||
use Google;
|
use Google;
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,12 @@ procedure test_tri is
|
||||||
Type T_Double is digits 3;
|
Type T_Double is digits 3;
|
||||||
|
|
||||||
N: constant Natural := 10;
|
N: constant Natural := 10;
|
||||||
|
N_links: constant Natural := 1000;
|
||||||
|
|
||||||
package Vector_Double is
|
package Vector_Double is
|
||||||
new Vector(T_Element => T_Double,
|
new Vector(T_Element => T_Double,
|
||||||
N => N);
|
N => N,
|
||||||
|
N_links => N_links);
|
||||||
use Vector_Double;
|
use Vector_Double;
|
||||||
|
|
||||||
vec: T_Vecteur_Element;
|
vec: T_Vecteur_Element;
|
||||||
|
|
|
@ -50,6 +50,32 @@ package body vector is
|
||||||
end loop;
|
end loop;
|
||||||
end put;
|
end put;
|
||||||
|
|
||||||
|
procedure put(vec: in T_Vecteur_Links) is
|
||||||
|
begin
|
||||||
|
for i in 0..N-1 loop
|
||||||
|
put(vec(i), 1); new_line;
|
||||||
|
end loop;
|
||||||
|
end put;
|
||||||
|
|
||||||
|
procedure sort_insert(vec: in out T_Vecteur_Links) is
|
||||||
|
tmp_Element: Natural;
|
||||||
|
max: Natural;
|
||||||
|
begin
|
||||||
|
for i in 0..N_links-2 loop
|
||||||
|
max := i;
|
||||||
|
for j in i+1..N_links-1 loop
|
||||||
|
if vec(max) >= vec(j) then
|
||||||
|
max := j;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
if max /= i then
|
||||||
|
tmp_Element := vec(i);
|
||||||
|
vec(i) := vec(max);
|
||||||
|
vec(max) := tmp_Element;
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
end sort_insert;
|
||||||
|
|
||||||
procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural) is
|
procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural) is
|
||||||
tmp_Element: T_Element;
|
tmp_Element: T_Element;
|
||||||
tmp_Natural: Natural;
|
tmp_Natural: Natural;
|
||||||
|
@ -89,6 +115,52 @@ package body vector is
|
||||||
pivot : constant T_Element := vec(low);
|
pivot : constant T_Element := vec(low);
|
||||||
right : Natural := high;
|
right : Natural := high;
|
||||||
left : Natural := low;
|
left : Natural := low;
|
||||||
|
begin
|
||||||
|
loop
|
||||||
|
while left < right and pivot >= vec(left) loop
|
||||||
|
left := left + 1;
|
||||||
|
end loop;
|
||||||
|
while pivot < vec(right) loop
|
||||||
|
right := right - 1;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
exit when right <= left;
|
||||||
|
|
||||||
|
swap(left, right);
|
||||||
|
left := left + 1;
|
||||||
|
right := right - 1;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
if right = high then
|
||||||
|
right := right - 1;
|
||||||
|
swap(low, high);
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if left = low then
|
||||||
|
left := left - 1;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
quicksort(vec, low, right);
|
||||||
|
quicksort(vec, left, high);
|
||||||
|
end;
|
||||||
|
end if;
|
||||||
|
end quicksort;
|
||||||
|
|
||||||
|
procedure quicksort(vec: in out T_Vecteur_Links; low, high: Natural) is
|
||||||
|
|
||||||
|
procedure swap(left, right: Natural) is
|
||||||
|
tmp : constant Natural := vec(left);
|
||||||
|
begin
|
||||||
|
vec(left) := vec(right);
|
||||||
|
vec(right) := tmp;
|
||||||
|
end swap;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if high - low > 0 then
|
||||||
|
declare
|
||||||
|
pivot : constant Natural := vec(low);
|
||||||
|
right : Natural := high;
|
||||||
|
left : Natural := low;
|
||||||
begin
|
begin
|
||||||
loop
|
loop
|
||||||
while left < right and not(pivot < vec(left)) loop
|
while left < right and not(pivot < vec(left)) loop
|
||||||
|
@ -113,7 +185,6 @@ package body vector is
|
||||||
left := left - 1;
|
left := left - 1;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
--put(left); put(right); put(low); put(high); new_line;
|
|
||||||
quicksort(vec, low, right);
|
quicksort(vec, low, right);
|
||||||
quicksort(vec, left, high);
|
quicksort(vec, left, high);
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -4,16 +4,17 @@ generic
|
||||||
|
|
||||||
type T_Element is digits <>;
|
type T_Element is digits <>;
|
||||||
N: Positive;
|
N: Positive;
|
||||||
|
N_links: Positive;
|
||||||
|
|
||||||
package Vector is
|
package Vector is
|
||||||
|
|
||||||
type T_Vecteur_Element is array (0..N-1) of T_Element;
|
type T_Vecteur_Element is array (0..N-1) of T_Element;
|
||||||
type T_Vecteur_Natural is array (0..N-1) of Natural;
|
type T_Vecteur_Natural is array (0..N-1) of Natural;
|
||||||
|
type T_Vecteur_Links is array (0..N_links-1) of Natural;
|
||||||
|
|
||||||
-- on permet l'affichage direct des T_Element
|
-- on permet l'affichage direct des T_Element
|
||||||
package Text_T_Element is
|
package Text_T_Element is
|
||||||
new Ada.Text_IO.Float_IO(Num => T_Element);
|
new Ada.Text_IO.Float_IO(Num => T_Element);
|
||||||
|
|
||||||
|
|
||||||
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element);
|
procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element);
|
||||||
procedure initialize(vec: in out T_Vecteur_Natural);
|
procedure initialize(vec: in out T_Vecteur_Natural);
|
||||||
|
@ -21,11 +22,14 @@ package Vector is
|
||||||
function sum(vec: in T_Vecteur_Element) return T_Element;
|
function sum(vec: in T_Vecteur_Element) return T_Element;
|
||||||
|
|
||||||
procedure put(vec: in T_Vecteur_Element);
|
procedure put(vec: in T_Vecteur_Element);
|
||||||
|
procedure put(vec: in T_Vecteur_Links);
|
||||||
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element);
|
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element);
|
||||||
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Natural);
|
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Natural);
|
||||||
|
|
||||||
|
procedure sort_insert(vec: in out T_Vecteur_Links);
|
||||||
procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural);
|
procedure sort_insert_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural);
|
||||||
|
|
||||||
procedure quicksort(vec: in out T_Vecteur_Element; low, high: Natural);
|
procedure quicksort(vec: in out T_Vecteur_Element; low, high: Natural);
|
||||||
|
procedure quicksort(vec: in out T_Vecteur_Links; low, high: Natural);
|
||||||
|
|
||||||
end Vector;
|
end Vector;
|
||||||
|
|
Loading…
Reference in a new issue