La présentation est en train de télécharger. S'il vous plaît, attendez

La présentation est en train de télécharger. S'il vous plaît, attendez

Structures de données IFT-10541 Abder Alikacem Linéarisation des matrices Département dinformatique et de génie logiciel Édition septembre 2009.

Présentations similaires


Présentation au sujet: "Structures de données IFT-10541 Abder Alikacem Linéarisation des matrices Département dinformatique et de génie logiciel Édition septembre 2009."— Transcription de la présentation:

1 Structures de données IFT-10541 Abder Alikacem Linéarisation des matrices Département dinformatique et de génie logiciel Édition septembre 2009

2 matrice dadjacence : (avec graphe non orienté) On peut, pour un graphe non-orienté, économiser de l'espace en ne stockant que le triangle supérieur de la matrice symétrique. Matrice triangulaire possède 1 + 2 + 3 +... + n = [n (n+1)] / 2 éléments. On la représente dans un vecteur ayant ce même nombre d'éléments. Si on la range par ligne, alors le vecteur aura l'allure suivante : A 11 A 21 A 22 A 31 A 32 A 33 A 41... A nn 4 2 5 3 1 Matrice triangulaire

3 matrice dadjacence : (avec graphe non orienté) Matrice triangulaire. Si A 11 est en position 1 (indice inférieur du vecteur), alors l'adresse de A ij est donnée par : Adresse = A 0 + ( i - 1 ) * i / 2 + j Ainsi, la position de A 42 est A 0 + 8. à Des matrices symétriques, pour lesquelles A ij = A ji pour peuvent être également représentées de cette façon. 4 2 5 3 1 Matrice triangulaire

4 Linéarisation dune matrice int main() { int *tab; int i, j, k=0; tab=(int*)calloc( MAX_LIGNES*MAX_COLONNES,sizeof(int)); for (i=0; i<MAX_LIGNES; i++) { for (j=0; j<MAX_COLONNES; j++) set(tab, k++, i, j); } for (i=0; i<MAX_LIGNES; i++) { for (j=0; j<MAX_COLONNES; j++) { printf("%d ", get(tab, i, j)); } printf("\n"); } free(tab); return 0; } void set (int *tab, int x, int i, int j) { tab[MAX_COLONNES*i + j] = x; } int get(int *tab, int i, int j) { return tab[MAX_COLONNES*i + j]; }

5 Linéarisation dune matrice triangulaire int main() { int *tab; int i, j, k=0; tab=(int*) calloc( MAX_LIGNES*( MAX_LIGNES+1)/2, sizeof(int)); for (i=0; i<MAX_LIGNES; i++) { for (j=0; j<=i; j++) set(tab, k++, i, j); } for (i=0; i<MAX_LIGNES; i++) { for (j=0; j<=i; j++) { printf("%d ", get(tab, i, j) ); } printf("\n"); } free(tab); return 0; } void set (int *tab, int x, int i, int j) { tab[i*(i+1)/2 + j] = x; } int get(int *tab, int i, int j) { return tab[i*(i+1)/2 + j]; }

6 #include "ModeleImplantationTabInt.h" #define OK 0 #define PAM 1 TabInt initTabInt(int *err); /*..*/ int * set (int *tab, int x, int i, int j, int *err); /* permet de placer la donnée x dans la matrice en (i, j) exactement si on aurait à faire: tab[i][j] */ int get(int *tab, int i, int j, int *err); /* get permet de lire l'élément de matrice en (i,j) */ TabInt destroyTabInt(TabInt tab, int *err); /* */ #include #define MAX_LIGNES2 #define MAX_COLONNES3 typedef int * TabInt;

7 #include "TabInt.h" int main() { TabInt tab; int i, j, k=0; int err; tab= initTabInt(&err); /* tab= initTab(INT, 2, 3, &err);*/ for (i=0; i<MAX_LIGNES; i++) {for (j=0; j<MAX_COLONNES; j++) set(tab, k++, i, j, &err); } for (i=0; i<MAX_LIGNES; i++) {for (j=0; j<MAX_COLONNES; j++) { printf("%d ", get(tab, i, j, &err)); } printf("\n"); } tab= destroyTabInt(tab, &err); return 0; }


Télécharger ppt "Structures de données IFT-10541 Abder Alikacem Linéarisation des matrices Département dinformatique et de génie logiciel Édition septembre 2009."

Présentations similaires


Annonces Google