From 695673f9b5f11eacf349279e8947b65123c94962 Mon Sep 17 00:00:00 2001 From: lfainsin Date: Wed, 23 Dec 2020 13:43:03 +0000 Subject: [PATCH] quelques modifications mineures git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210346 e13453a9-b01f-0410-a051-f404c4f0c485 --- src/google_creux.adb | 13 ------ src/google_creux.ads | 4 +- src/google_naive.adb | 2 +- src/google_naive.ads | 1 - src/pagerank.adb | 10 ++-- src/vector.adb | 106 ++++++++++++++++++++++++++++++++++++++++--- src/vector.ads | 7 +-- 7 files changed, 109 insertions(+), 34 deletions(-) diff --git a/src/google_creux.adb b/src/google_creux.adb index 2def15d..3fcc39a 100644 --- a/src/google_creux.adb +++ b/src/google_creux.adb @@ -1,26 +1,13 @@ with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; -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 Ada.Text_IO.Text_Streams; - - package body Google_Creux is - -- construction simple, de compléxité N^2 - -- on peut diminuer la compléxité en triant d'abord le réseau - -- on passerait à une complexité 2*N + N*Log(2, N) procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is row, col: Natural; nb: Natural := 0; - stdout: constant Ada.Text_IO.File_Type := Ada.Text_IO.Standard_Output; begin mat.rows(0) := 0; for i in 0..N-1 loop - String'Write(Ada.Text_IO.Text_Streams.Stream(stdout), - ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(N-1)); reset(file, In_File); skip_line(file); for j in 0..N_links-1 loop diff --git a/src/google_creux.ads b/src/google_creux.ads index c8d7a36..f6ab694 100644 --- a/src/google_creux.ads +++ b/src/google_creux.ads @@ -25,9 +25,9 @@ package Google_Creux is rows: T_Rows; end record; - function calcul(vec: T_Vecteur_Element; mat :T_Google; alpha: in T_Element) return T_Vecteur_Element; - procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type); + + function calcul(vec: T_Vecteur_Element; mat :T_Google; alpha: in T_Element) return T_Vecteur_Element; procedure put(mat: in T_Google); diff --git a/src/google_naive.adb b/src/google_naive.adb index c248e74..713105a 100644 --- a/src/google_naive.adb +++ b/src/google_naive.adb @@ -6,7 +6,6 @@ package body Google_Naive is vec: T_Vecteur_Element; c: T_Element; begin - initialize(vec); -- garder ? for i in 0..N-1 loop c := 0.0; for j in 0..N-1 loop @@ -69,6 +68,7 @@ package body Google_Naive is end create_G; procedure put(mat: in T_Google) is + use Text_T_Element; begin for i in 0..N-1 loop for j in 0..N-1 loop diff --git a/src/google_naive.ads b/src/google_naive.ads index e826247..75b8756 100644 --- a/src/google_naive.ads +++ b/src/google_naive.ads @@ -12,7 +12,6 @@ package Google_Naive 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; diff --git a/src/pagerank.adb b/src/pagerank.adb index a27f282..4bf5b24 100644 --- a/src/pagerank.adb +++ b/src/pagerank.adb @@ -152,7 +152,7 @@ procedure pageRank is begin - initialize(pi); + initialize(pi, 1.0/T_Double(N)); put_line("initialized pi"); -- put(pi); new_line; @@ -205,7 +205,7 @@ procedure pageRank is begin - initialize(pi); + initialize(pi, 1.0/T_Double(N)); put_line("initialized pi:"); -- put(pi); new_line; @@ -220,9 +220,9 @@ procedure pageRank is ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(ite_max)); end loop; new_line; - new_line; - put_line("final pi:"); - put(pi); + -- new_line; + -- put_line("final pi:"); + -- put(pi); end algorithm_creux; diff --git a/src/vector.adb b/src/vector.adb index 101e823..1bd2d1c 100644 --- a/src/vector.adb +++ b/src/vector.adb @@ -2,13 +2,6 @@ with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; package body vector is - procedure initialize(vec: in out T_Vecteur_Element) is - begin - for i in 0..N-1 loop - vec(i) := 1.0/T_Element(N); - end loop; - end initialize; - procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element) is begin for i in 0..N-1 loop @@ -33,6 +26,7 @@ package body vector is end sum; procedure put(vec: in T_Vecteur_Element) is + use Text_T_Element; begin for i in 0..N-1 loop put(vec(i)); new_line; @@ -40,6 +34,7 @@ package body vector is end put; procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Element) is + use Text_T_Element; begin for i in 0..N-1 loop put(file, vec(i), Fore=>1, Aft=>10); @@ -79,6 +74,46 @@ package body vector is end loop; end sort_with_index_desc; +<<<<<<< .mine +||||||| .r210321 + procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is + pivot: Natural := a; + i: Natural := a; + tmp: T_Element; + begin + if b - a > 1 then + for j in a..b loop + if vec(j) <= vec(pivot) then + i := i + 1; + tmp := vec(i); + vec(i) := vec(j); + vec(j) := tmp; + else + null; + end if; + end loop; + + tmp := vec(i); + vec(i) := vec(pivot); + vec(pivot) := tmp; + + pivot := i; + + put(vec); new_line; + + if pivot - 1 > 0 then + quicksort(vec, vec_index, a, pivot-1); + elsif b - pivot - 1 > 0 then + quicksort(vec, vec_index, pivot+1, b); + else + null; + end if; + else + null; + end if; + end quicksort; + +======= procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is pivot: Natural := a; i: Natural := a; @@ -116,7 +151,63 @@ package body vector is end if; end quicksort; +>>>>>>> .r210345 end vector; +<<<<<<< .mine +||||||| .r210321 + +-- 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) + +-- procedure Quick_Sort (A : in out Element_Array) is + +-- procedure Swap(Left, Right : Index) is +-- Temp : Element := A (Left); +-- begin +-- A (Left) := A (Right); +-- A (Right) := Temp; +-- end Swap; + +-- begin +-- if A'Length > 1 then +-- declare +-- Pivot_Value : Element := A (A'First); +-- Right : Index := A'Last; +-- Left : Index := A'First; +-- begin +-- loop +-- while Left < Right and not (Pivot_Value < A (Left)) loop +-- Left := Index'Succ (Left); +-- end loop; +-- while Pivot_Value < A (Right) loop +-- Right := Index'Pred (Right); +-- end loop; +-- exit when Right <= Left; +-- Swap (Left, Right); +-- Left := Index'Succ (Left); +-- Right := Index'Pred (Right); +-- end loop; +-- if Right = A'Last then +-- Right := Index'Pred (Right); +-- Swap (A'First, A'Last); +-- end if; +-- if Left = A'First then +-- Left := Index'Succ (Left); +-- end if; +-- Quick_Sort (A (A'First .. Right)); +-- Quick_Sort (A (Left .. A'Last)); +-- end; +-- end if; +-- end Quick_Sort;======= -- def triRapide(L): # Quicksort -- if len(L) <= 1: @@ -170,3 +261,4 @@ end vector; -- end; -- end if; -- end Quick_Sort; +>>>>>>> .r210345 diff --git a/src/vector.ads b/src/vector.ads index 835130e..02b6bc5 100644 --- a/src/vector.ads +++ b/src/vector.ads @@ -9,13 +9,12 @@ package Vector is type T_Vecteur_Element is array (0..N-1) of T_Element; type T_Vecteur_Natural is array (0..N-1) of Natural; - + -- 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; + - procedure initialize(vec: in out T_Vecteur_Element); procedure initialize(vec: in out T_Vecteur_Element; value: in T_Element); procedure initialize(vec: in out T_Vecteur_Natural); @@ -27,6 +26,4 @@ package Vector is procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural); - procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural); - end Vector;