copie de raffinage.txt sur le repo + test création premiers fichiers source
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@207178 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
bcf56781ea
commit
b4aa8ad7d3
8
Makefile
Normal file
8
Makefile
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
make:
|
||||||
|
cd build/ && \
|
||||||
|
gnat make -gnatwa -gnata -g ../src/*.adb
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cd build/ && \
|
||||||
|
gnat clean ../src/*.adb
|
||||||
|
|
|
@ -41,20 +41,18 @@ communiquez avec votre coéquipier !
|
||||||
|
|
||||||
# Organisation du dépôt SVN
|
# Organisation du dépôt SVN
|
||||||
|
|
||||||
src/
|
. \
|
||||||
|
├── build \
|
||||||
: pour les sources de votre projet (fichiers .adb, ads, etc.)
|
├── doc \
|
||||||
|
├── livrables \
|
||||||
livrables/
|
│ ├── raffinages.txt \
|
||||||
|
│ └── rapport.pdf \
|
||||||
: les fichiers qui sont demandés dans le sujet. Attention à
|
├── Makefile \
|
||||||
respecter les noms. Certains sont déjà là. Il suffit de les remplacer.
|
├── README.md \
|
||||||
|
└── src \
|
||||||
docs/
|
├── googleNaive.ada \
|
||||||
|
├── googleNaive.ads \
|
||||||
: c'est ici que vous pouvez mettre les fichiers qui vous permettent
|
└── pageRank.ada \
|
||||||
d'obtenir le rapport (par exemple fichier LaTeX, markdown, etc.)
|
|
||||||
|
|
||||||
|
|
||||||
# Autres informations
|
# Autres informations
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
Ce raffinage décrit l'implémentation de l'algorithme de PageRank dans le cas d'une implémentation de matrice naives.
|
||||||
|
Une syntaxe proche du python3 est adoptée pour simplifier l'écriture et la lisibilité.
|
||||||
|
DISCLAIMER: raffinages pas encore finis
|
||||||
|
On suppose que les procédures/fonctions suivantes sont élémentaires:
|
||||||
|
Std:
|
||||||
|
- Arguments
|
||||||
|
- Longueur
|
||||||
|
- Exception
|
||||||
|
- Écrire
|
||||||
|
- Lire
|
||||||
|
- Ouvrir
|
||||||
|
- Fermer
|
||||||
|
- Fin // end of file
|
||||||
|
- Abs
|
||||||
|
- Somme
|
||||||
|
|
||||||
|
Matrice:
|
||||||
|
- Transposer
|
||||||
|
- Ones
|
||||||
|
- Zeros
|
||||||
|
- Les opérations binaires: * / +
|
||||||
|
- L'accès via les [ ]
|
||||||
|
- Trier
|
||||||
|
|
||||||
|
|
||||||
|
R0: Calculer le PageRank et le poids de chaque nœud d'un réseau
|
||||||
|
|
||||||
|
R1: Comment « Calculer le PageRank et le poids de chaque nœud d'un réseau » ?
|
||||||
|
Récuperer les arguments de la ligne de commande out: filename, ite_max, alpha, naif
|
||||||
|
Initialiser les variables out: pi, G, epsilon, N
|
||||||
|
Éxecuter l'algorithme itératif in out: pi ; in: G, epsilon
|
||||||
|
Écrire les résultats dans des fichiers in: pi, filename, N
|
||||||
|
|
||||||
|
R2: Comment « Récupérer les arguments de la ligne de commande » ?
|
||||||
|
args ← Arguments()
|
||||||
|
len_args ← Longueur(args)
|
||||||
|
Si non 0 < len_args <= 6 Alors
|
||||||
|
Exception(ERROR_ARGS)
|
||||||
|
Sinon
|
||||||
|
Traiter les arguments in: args, len_args ; out: filename, ite_max, alpha, naif
|
||||||
|
FinSi
|
||||||
|
Si Exception(QUELCONQUE)
|
||||||
|
Afficher les consignes d'utilisation
|
||||||
|
Fin Si
|
||||||
|
|
||||||
|
R2: Comment « Traiter les arguments » ?
|
||||||
|
ite_max ← 150
|
||||||
|
alpha ← 0.85
|
||||||
|
naif ← False
|
||||||
|
i ← 0
|
||||||
|
Répéter
|
||||||
|
Si args[i] = "-I" Alors
|
||||||
|
ite_max ← args[i+1]
|
||||||
|
i ← i + 2
|
||||||
|
SinonSi args[i] = "-A" Alors
|
||||||
|
alpha ← args[i+1]
|
||||||
|
i ← i + 2
|
||||||
|
SinonSi args[i][-4:-1] == ".net" Alors
|
||||||
|
filename ← args[i][0:-4]
|
||||||
|
i ← i + 1
|
||||||
|
SinonSi args[i] == "-P" Alors
|
||||||
|
naif ← True
|
||||||
|
i ← i + 1
|
||||||
|
Sinon
|
||||||
|
Exception(ERROR_ARGS)
|
||||||
|
FinSi
|
||||||
|
SortirQuand i < len_args
|
||||||
|
FinRépéter
|
||||||
|
|
||||||
|
R3: Comment « Afficher les consignes d'utilisation » ?
|
||||||
|
Écrire("Erreur lors de la saisi de la commande")
|
||||||
|
Écrire("Usage: pagerank [-I max_iterations] [-A alpha] fichier_reseau.net")
|
||||||
|
|
||||||
|
R2: Comment « Initialiser les variables » ?
|
||||||
|
epsilon ← 0.01
|
||||||
|
Créer H out: H, N
|
||||||
|
Créer S in: H, N ; out: S
|
||||||
|
pi ← Ones(N, N)/N
|
||||||
|
E ← Ones(N, N) * (1-alpha)/N
|
||||||
|
G ← alpha * S + E
|
||||||
|
|
||||||
|
R3: Comment « Créer H » ?
|
||||||
|
fichier ← Ouvrir(filename + ".net")
|
||||||
|
N ← Lire(fichier)
|
||||||
|
|
||||||
|
H ← Zeros(N, N)
|
||||||
|
TantQue non Fin(fichier) Faire
|
||||||
|
i ← Lire(fichier)
|
||||||
|
j ← Lire(fichier)
|
||||||
|
H[i, j] ← 1
|
||||||
|
FinTantQue
|
||||||
|
Fermer(fichier)
|
||||||
|
|
||||||
|
Pour i de 0 à N-1 Faire
|
||||||
|
H[i,:] ← H[i,:]/Somme(H[i,:])
|
||||||
|
FinPour
|
||||||
|
|
||||||
|
R3: Comment « Créer S » ?
|
||||||
|
X ← Ones(N, 1)
|
||||||
|
V ← H * X
|
||||||
|
S ← H
|
||||||
|
Pour i de 0 a N-1 Faire
|
||||||
|
Si V[i] = 0 Alors
|
||||||
|
S[i,:] = 1/N
|
||||||
|
Fin Si
|
||||||
|
FinPour
|
||||||
|
|
||||||
|
R2: Comment « Éxecuter l'algorithme itératif » ?
|
||||||
|
i ← 0
|
||||||
|
Répéter
|
||||||
|
pi_last ← pi
|
||||||
|
pi ← Transposer(G) * pi
|
||||||
|
i ← i + 1
|
||||||
|
SortirQuand i >= ite_max ou Abs(pi - pi_last) < epsilon
|
||||||
|
FinRépéter
|
||||||
|
|
||||||
|
R2: Comment « Écrire les résultats dans des fichiers » ?
|
||||||
|
Coupler les poids et leur indice in: pi ; out: pi_couple
|
||||||
|
pi_couple ← Trier(pi_couple, 'c', 0) // on trie selon la première colonne
|
||||||
|
|
||||||
|
fichier ← Ouvrir(filename + ".p")
|
||||||
|
Écrire(fichier, pi_couple[:,0])
|
||||||
|
Fermer(fichier)
|
||||||
|
|
||||||
|
fichier ← Ouvrir(filename + ".ord")
|
||||||
|
Écrire(fichier, pi_couple[:,1])
|
||||||
|
Fermer(fichier)
|
||||||
|
|
||||||
|
R3: Comment « Coupler les poids et leur indice » ?
|
||||||
|
pi_couple ← Zeros(N, 2)
|
||||||
|
pi_couple[:, 0] = pi
|
||||||
|
Pour i de 0 N-1 Faire
|
||||||
|
pi_couple[i, 1] ← i
|
||||||
|
FinPour
|
5
src/googleNaive.ada
Normal file
5
src/googleNaive.ada
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package body googleNaive is
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
|
||||||
|
end googleNaive;
|
37
src/googleNaive.ads
Normal file
37
src/googleNaive.ads
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
generic
|
||||||
|
|
||||||
|
type T_Element is private;
|
||||||
|
CAPACITY: Positive;
|
||||||
|
|
||||||
|
package googleNaive is
|
||||||
|
|
||||||
|
type T_Row is limited private;
|
||||||
|
type T_Google is limited private;
|
||||||
|
|
||||||
|
function "*"(left, right: T_Google) return T_Google;
|
||||||
|
function "+"(left, right: T_Google) return T_Google;
|
||||||
|
|
||||||
|
function "*"(left: T_Google; right: Integer) return T_Google;
|
||||||
|
function "/"(left: T_Google; right: Integer) return T_Google;
|
||||||
|
|
||||||
|
function isEmpty(mat: T_Google) return Boolean;
|
||||||
|
|
||||||
|
procedure initialize(mat: in out T_Google) with
|
||||||
|
Post => isEmpty(mat);
|
||||||
|
|
||||||
|
function ones(rows, cols: Positive) return T_Google;
|
||||||
|
function zeros(rows, cols: Positive) return T_Google;
|
||||||
|
|
||||||
|
procedure insert(mat: in out T_Google; i, j: Natural; elm: T_Element);
|
||||||
|
|
||||||
|
function transpose(mat: in T_Google) return T_Google;
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
type T_Row is array (0..CAPACITY-1) of T_Element;
|
||||||
|
type T_Google is record
|
||||||
|
dimension: array (0..1) of Positive;
|
||||||
|
matrix: array (0..CAPACITY-1) of T_Row;
|
||||||
|
end record;
|
||||||
|
|
||||||
|
end googleNaive;
|
7
src/pageRank.ada
Normal file
7
src/pageRank.ada
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
procedure pageRank is
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
|
||||||
|
end pageRank;
|
Loading…
Reference in a new issue