diff --git a/Evaluation.md b/Evaluation.md index 87243b5f503ad918fe27ec99eded6abca2dd236f..bed29f812d894399c279596e11b90d6321d5bed6 100644 --- a/Evaluation.md +++ b/Evaluation.md @@ -1,46 +1,46 @@ ## Etendue et qualité de l'étude - Nombre de tris - - [ ] Insertion, Fusion, Rapide et au moins un autre tri sont traités. + - [x] Insertion, Fusion, Rapide et au moins un autre tri sont traités. - [ ] Insertion, Fusion et Rapide sont traités. - - [x] Insertion, Fusion et Rapide ne sont pas tous traités. + - [ ] Insertion, Fusion et Rapide ne sont pas tous traités. - Type de jeu de test - - [ ] Aléatoire, Trié, Tri inversé et au moins un autre jeu sont traités. + - [x] Aléatoire, Trié, Tri inversé et au moins un autre jeu sont traités. - [ ] Aléatoire, Trié et Tri inversé sont traités. - - [x] Aléatoire, Trié et Tri inversé ne sont pas tous traités. + - [ ] Aléatoire, Trié et Tri inversé ne sont pas tous traités. - Aspects - - [ ] Consommation mémoire et CPU sont traitées. + - [x] Consommation mémoire et CPU sont traitées. - [ ] Consommation mémoire ou CPU sont traitées. - - [x] Consommation mémoire et CPU ne sont pas traitées. + - [ ] Consommation mémoire et CPU ne sont pas traitées. - Qualité - [ ] L'absence de fuite mémoire a été expérimentalement vérifiée. - - [ ] Il n'y a pas de problème apparent de fuite mémoire. - - [x] Il y a des problèmes apparents de fuite mémoire. + - [x] Il n'y a pas de problème apparent de fuite mémoire. + - [ ] Il y a des problèmes apparents de fuite mémoire. ## Rédaction et analyses - Description du problème - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Application - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Environnement de test - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Description de la démarche systématique - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Analyse des résultats préalables - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Discussion des résultats préalables - - [ ] La section est pertinente, succincte et précise. + - [x] La section est pertinente, succincte et précise. - [ ] La section est pertinente. - - [x] La section n'est pas pertinente. + - [ ] La section n'est pas pertinente. - Hypothèse - [ ] La section est pertinente, succincte et précise. - [ ] La section est pertinente. @@ -65,28 +65,28 @@ ## Résultats - Nombre - [ ] Les tests sont suffisament nombreux pour observer des épiphénomènes - - [ ] Les tests sont suffisament nombreux pour observer des phénomènes - - [x] Les tests ne sont pas suffisament nombreux pour observer des phénomènes + - [x] Les tests sont suffisament nombreux pour observer des phénomènes + - [ ] Les tests ne sont pas suffisament nombreux pour observer des phénomènes - Echantillon - - [ ] L'échantillon choisi a un bon équilbre entre temps d'exécution et observations + - [x] L'échantillon choisi a un bon équilbre entre temps d'exécution et observations - [ ] L'échantillon choisi néglige les temps d'exécution - - [x] L'échantillon choisi néglige les observations + - [ ] L'échantillon choisi néglige les observations - Artefacts - - [ ] Les observations excluent tout artefacts + - [x] Les observations excluent tout artefacts - [ ] Certains artefacts, comme des pas d'horloge, sont visibles - - [x] Seuls des artefacts sont observables + - [ ] Seuls des artefacts sont observables - Décoration - - [ ] Les plots contiennent légende et titre + - [x] Les plots contiennent légende et titre - [ ] Les plots contiennent légende ou titre - - [x] Les plots ne contiennent ni légende ni titre + - [ ] Les plots ne contiennent ni légende ni titre - Lisibilité - - [ ] Les plots permettent de lire clairement toutes les séries + - [x] Les plots permettent de lire clairement toutes les séries - [ ] Les plots permettent de lire clairement la plupart des séries - - [x] Les plots permettent pas de lire clairement la plupart des séries + - [ ] Les plots permettent pas de lire clairement la plupart des séries - Echelles - - [ ] Les échelles sont respectées pour permettre la visualisation et la comparaison des séries entre plots + - [x] Les échelles sont respectées pour permettre la visualisation et la comparaison des séries entre plots - [ ] Les échelles sont respectées pour permettre la visualisation des séries entre plots - - [x] Les échelles ne sont pas respectées pour permettre la visualisation des séries entre plots + - [ ] Les échelles ne sont pas respectées pour permettre la visualisation des séries entre plots ## Hypothèse - Originalité diff --git a/README.md b/README.md index 4a51454c37a9fed7ca4e46f953349f8f23a41449..927df94c14a5c4d89c11513a24f04766382af0b1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +BURCKEL Luc, BOUVIER Lilian +=========================== # P4z : Analyse de performances de différents tris @@ -6,74 +8,114 @@ ## Problème -Description du Problème. +Comme on l'a vu, il est facile de rechercher un élément particulier dans un ensemble trié, c'est pourquoi avoir une solution efficace pour trier un ensemble d'éléments est une question cruciale en informatique. Au travers de ce projet, nous allons chercher comment minimiser les ressources utilisées pour trier différents ensembles d'élements en choisissant intelligemment l'algorithme utilisé. -Description de tous les paramètres exploratoires du problème +Nous étudions le comportement de différents algorithmes de tris (tri par insertion, tri fusion et tri rapide) en variant leurs environnements d'éxecution (tableau trié, trié à l'envers, valeurs aléatoires et valeurs aléatoires avec négatifs) afin d'observer et comparer le comportement de chacuns de ces algorithmes et en déduire des phénomènes. ## Dispositif expérimental ### Application -[code source de l'application](chemin) +[code source de l'application](./main.c) ``` -Description de l'application et des arguments +./main <taille_tab> <algo> <type_tab> ``` +L'application prends trois paramètres : la taille du tableau souhaitée, l'algorithme à tester et le type de tableau (aleatoire / trie / trieInverse / trieNegatif ). ### Environnement de test Description de la plateforme de test ``` -Extrait pertinent de /proc/cpuinfo +Serveur sterne +OS : Linux Debian 10 +cpu family : 15 +model : 6 +model name : Common KVM processor +cache size : 16384 KB +cpu cores : 2 ``` ### Description de la démarche systématique -Description de la démarche systématique et de l'espace d'exploration pour chaque paramètres. +Pour optimiser l'utilisation de notre main, nous avons un script shell recherche.sh qui sauvegarde les données dans un fichier test.csv. +Nous obtenons une sortie de ce style : ``` -Suite des commandes, ou script, à exécuter pour produire les données. +Algo Type Taille Temps Mem +triInsertion aleatoire 17483 0.25 1776 +triInsertion aleatoire 62935 3.14 1904 +triInsertion aleatoire 43316 1.53 1856 +triInsertion aleatoire 85654 6.07 1864 +triInsertion aleatoire 82160 5.58 1908 +triInsertion aleatoire 73663 4.31 1908 +... ``` +Ensuite, nous séparons à la main les données dans différents fichiers csv, puis nous utilisons le mode intéractif R pour générer des graphiques et analyser nos résultats. + +Voici la suite des commandes pour produire l'un des graphiques : + +``` +test<-read.csv(file="aleatoire.csv",header=TRUE,sep=" ") +``` +(Lecture des données.) +``` +library(ggplot2) +``` +(importation de ggplot) +``` +graphe<-ggplot(data=test,aes(x=Taille,y=Temps,color=factor(Algo))) +``` +(Définition des axes et variables du graphique) +``` +graphe<-graphe+geom_smooth()+ggtitle("Aléatoire")+theme(plot.title=element_text(hjust=0.5))+ylab("Temps CPU (s)")+xlab("Taille (éléments)")+scale_color_discrete(name="Algorithme")+geom_point() +``` +(Mise en forme globale du graphique.) +``` +ggsave("Rplots.pdf") +``` +(Sauvegarde dans un pdf.) + + + ## Résultats préalables ### Temps d'exécution -| Jeu de test | Tri par Insertion | Tri Fusion | Tri Rapide | -|----------------------|---------------------------|---------------------------|---------------------------| -| Aléatoire |  |  |  | -| Trié |  |  |  | -| Tri inversé |  |  |  | + + + ### Consommation mémoire -| Jeu de test | Tri par Insertion | Tri Fusion | Tri Rapide | -|----------------------|---------------------------|---------------------------|---------------------------| -| Aléatoire |  |  |  | -| Trié |  |  |  | -| Tri inversé |  |  |  | + +  + ### Analyse des résultats préalables -Explications précises et succinctes des résultats préalables. +A partir de ces résultats, on peut déduire plusieurs choses, premièrement, le tri fusion est constant en temps d'éxecution sur tous nos tests, mais requiert beaucoup de mémoire pour les tableaux non triés. + +Ensuite le tri par insertion se comporte bien avec les tableaux déjà triés, mais son temps d'exécution explose pour tous les autres tableaux. +En revenche, il utilise peu de mémoire en général. + +Enfin, le tri rapide est à l'aise sur les tableaux aléatoires que ce soit en temps d'exécution ou en mémoire, mais est beaucoup moins performants sur les autres types de tableaux. ### Discussion des résultats préalables -Explications précises et succinctes des limites des résultats -préalables et ce qu'ils ne permettent pas de vérifier. +Tout d'abord, ces résultats théoriques montrent les performences de trois algorithmes de tris en fonction du contexte d'éxecution, mais les données triées sont réparties de façon aléatoires. Dans une application réelle en revenche, on pourrait très bien imaginer que la répartition soit bien plus chaotique, et nos tests ne permettent donc pas vraiment d'affirmer les performances des algorithmes dans ce cadre. ## Etude approfondie ### Hypothèse -Expression précise et succincte d'une hypothèse. +Nous avons constaté dans nos précédents résultats que la consommation mémoire du tri rapide était énorme pour les tableaux triés et triés à l'envers. Nous allons essayer de vérifier si cette consommation mémoire excessive ne serait pas du à l'implémentation récursive de cet algorithme. ### Protocole expérimental de vérification de l'hypothèse -Expression précise et succincte du protocole. +Nous allons, dans un premier temps, essayer l'option de compilation -O2 de gcc, qui devrait permettre de limiter un maximum les appels récursifs. -``` -Suite des commandes, ou script, à exécuter pour produire les données. -``` +Ensuite, nous allons écrire notre propre implémentation itérative du tri rapide et comparer nos résultats. ### Résultats expérimentaux diff --git a/TP1/tris.c b/TP1/tris.c new file mode 100644 index 0000000000000000000000000000000000000000..251ccb031296d8d0203c25462040b53a8f3a39a2 --- /dev/null +++ b/TP1/tris.c @@ -0,0 +1,107 @@ +#include "tris.h" + +/** + * Algo de tri par insertion +*/ +void triInsertion(long* A, size_t n) { + int cle,j; + for(int i=1; i < n; i++){ + cle=A[i]; + j=i-1; + while(j >= 0 && A[j] > cle){ + A[j+1]=A[j]; + j--; + } + A[j+1]=cle; + } +} + +/** + * Algo de tri par fusion +*/ +void triFusion(long* A, size_t n) { + sousTriFusion(A,0,n); +} + +void sousTriFusion(long* A, size_t p, size_t r){ + if(p<r-1){ + size_t q=(p+r)/2; + sousTriFusion(A,p,q); + sousTriFusion(A,q,r); + fusion(A,p,q,r); + } +} + +void fusion(long *A,size_t p, size_t q, size_t r){ + int n1 = (int)q - (int)p; + int n2 = (int)r - (int)q; + + long* Ag = malloc(sizeof(long)*n1); + long* Ad = malloc(sizeof(long)*n2); + + memcpy(Ag, &A[p], n1*sizeof(long)); + memcpy(Ad, &A[q], n2*sizeof(long)); + + size_t indG = 0; + size_t indD = 0; + size_t i = p; + + while(i < r) { + if(indG == n1) { + A[i] = Ad[indD]; + indD++; + } + else if( indD == n2) { + A[i] = Ag[indG]; + indG++; + } + else if (Ag[indG] < Ad[indD]) { + A[i] = Ag[indG]; + indG++; + } + else { + A[i] = Ad[indD]; + indD++; + } + i++; + } + free(Ag); + free(Ad); +} + +/** + * Algo de tri "rapide" +*/ +void triRapide(long* A, size_t n) { + sousTriRapide(A, 0, n); +} + +void sousTriRapide(long *A, size_t p, size_t r){ + size_t max = -1; + if(r-1 != max && p < r-1){ + size_t q = partition(A,p,r); + sousTriRapide(A,p,q); + sousTriRapide(A,q+1,r); + } +} + +size_t partition(long* A, size_t p, size_t r) +{ + long mem, pivot = A[r-1]; + size_t i = p; + + for(size_t j = p; j <= r - 2; j++) { + if(A[j] <= pivot) { + mem = A[i]; + A[i] = A[j]; + A[j] = mem; + i++; + } + } + + mem = A[i]; + A[i] = A[r - 1]; + A[r-1] = mem; + + return i; +} \ No newline at end of file diff --git a/TP1/tris.h b/TP1/tris.h new file mode 100644 index 0000000000000000000000000000000000000000..062a69dea7b2435472d8cd6b8d36ee64239b942a --- /dev/null +++ b/TP1/tris.h @@ -0,0 +1,10 @@ +#include <stdlib.h> +#include <string.h> + +void triInsertion(long* A, size_t n); +void triFusion(long* A, size_t n); +void sousTriFusion(long* A, size_t p, size_t r); +void fusion(long* A, size_t p, size_t q, size_t r); +void triRapide(long* A, size_t n); +void sousTriRapide(long* A, size_t p, size_t r); +size_t partition(long* A, size_t p, size_t r); \ No newline at end of file diff --git a/aleatoire.csv b/aleatoire.csv new file mode 100644 index 0000000000000000000000000000000000000000..ad50c7a34aac44ffeafa6690330695932595f1f3 --- /dev/null +++ b/aleatoire.csv @@ -0,0 +1,61 @@ +Algo Taille Temps Mem +triInsertion 17483 0.25 1776 +triInsertion 62935 3.14 1904 +triInsertion 43316 1.53 1856 +triInsertion 85654 6.07 1864 +triInsertion 82160 5.58 1908 +triInsertion 73663 4.31 1908 +triInsertion 97099 7.12 2156 +triInsertion 74608 4.25 1896 +triInsertion 19898 0.31 1772 +triInsertion 60683 2.86 1920 +triInsertion 68106 3.68 1920 +triInsertion 23673 0.46 1836 +triInsertion 87165 5.99 1900 +triInsertion 24615 0.47 1784 +triInsertion 85494 5.65 1904 +triInsertion 62202 3.04 1968 +triInsertion 45965 1.62 1768 +triInsertion 20491 0.34 1872 +triInsertion 81113 4.88 1896 +triInsertion 49301 1.78 1872 +triFusion 10160 0.00 2024 +triFusion 10321 0.00 2000 +triFusion 14700 0.00 2084 +triFusion 84506 0.01 2748 +triFusion 94735 0.02 2808 +triFusion 19732 0.00 1908 +triFusion 46470 0.01 2276 +triFusion 12818 0.00 2064 +triFusion 50964 0.01 2188 +triFusion 39657 0.01 2124 +triFusion 74550 0.01 2628 +triFusion 86582 0.01 2764 +triFusion 91621 0.02 2804 +triFusion 99998 0.02 2956 +triFusion 72548 0.01 2744 +triFusion 37550 0.00 2168 +triFusion 26140 0.00 1880 +triFusion 70805 0.01 2720 +triFusion 72135 0.01 2648 +triFusion 73684 0.01 2620 +triRapide 60938 0.49 2128 +triRapide 83064 0.93 2448 +triRapide 16244 0.04 1964 +triRapide 50253 0.35 1968 +triRapide 81103 0.89 2092 +triRapide 50316 0.35 2032 +triRapide 85192 1.02 2392 +triRapide 86984 1.07 2440 +triRapide 60422 0.53 2240 +triRapide 14254 0.03 2052 +triRapide 23986 0.08 1796 +triRapide 50867 0.36 1980 +triRapide 27843 0.11 1884 +triRapide 15973 0.03 2068 +triRapide 79923 0.92 2248 +triRapide 50116 0.36 2092 +triRapide 44378 0.28 1972 +triRapide 79256 0.91 2172 +triRapide 96282 1.32 2480 +triRapide 27580 0.10 1868 \ No newline at end of file diff --git a/helpers.c b/helpers.c new file mode 100644 index 0000000000000000000000000000000000000000..983f7a477375b0b21c08555b124265066e195a55 --- /dev/null +++ b/helpers.c @@ -0,0 +1,55 @@ +#include "helpers.h" + +/** + * Affiche un tableau + */ +void afficheTab(int n,long *a){ + for(int i=0;i<n;i++) + printf("%ld ",a[i]); + printf("\n"); +} + +/** + * Génère un tableau de taille n +*/ +long *generer_tableau(long long unsigned int n) { + long *tableau = malloc(n*sizeof(long)); + long long unsigned int i; + + for (i=0; i<n; i++) { + tableau[i] = rand() % MAX_VALEUR; + } + + return tableau; +} + +long *generer_tableau_negatif(long long unsigned int n) { + long *tableau = malloc(n*sizeof(long)); + long long unsigned int i; + + for (i=0; i<n; i++) { + tableau[i] = rand() % (MAX_VALEUR * 2) - MAX_VALEUR; + } + + return tableau; +} + +long *generer_tableau_trier(long long unsigned int n) { + long *tableau = malloc(n*sizeof(long)); + long long unsigned int i; + + for (i=0; i<n; i++) { + tableau[i] = i; + } + return tableau; +} + +long *generer_tableau_trier_inverser(long long unsigned int n) { + long *tableau = malloc(n*sizeof(long)); + long long unsigned int i; + + for (i=0; i<n; i++) { + tableau[i] = n-i; + } + return tableau; +} \ No newline at end of file diff --git a/helpers.h b/helpers.h new file mode 100644 index 0000000000000000000000000000000000000000..a197ac3fdfd361b7d0a326d44a10eb6c471230c8 --- /dev/null +++ b/helpers.h @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define MAX_VALEUR 15 + +void afficheTab(int n,long *a); +long *generer_tableau(long long unsigned int n); +long *generer_tableau_negatif(long long unsigned int n); +long *generer_tableau_trier(long long unsigned int n); +long *generer_tableau_trier_inverser(long long unsigned int n); \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000000000000000000000000000000000000..8c92e017cfa6571e9935701f2e06b0ce54660bac --- /dev/null +++ b/main.c @@ -0,0 +1,43 @@ +#include "helpers.h" +#include "tris.h" + + +int main(int argc, char *argv[]) { + long *tableau; + int taille; + + if (argc<4) { + printf("Usage: %s taille algo type_tab\n",argv[0]); + exit(1); + } + taille = strtoull(argv[1], (char **) NULL, 10); + srand(time(NULL)); + if(strcmp(argv[3],"aleatoire")==0) + tableau = generer_tableau(taille); + else if(strcmp(argv[3],"trie")==0) + tableau = generer_tableau_trier(taille); + else if(strcmp(argv[3],"trieInverse")==0) + tableau = generer_tableau_trier_inverser(taille); + else if(strcmp(argv[3],"trieNegatif")==0) + tableau = generer_tableau_negatif(taille); + else{ + printf("mauvais type_tab: {aleatoire,trieNegatif,trie,trieInverse}\n"); + exit(EXIT_FAILURE); + } + if(strcmp(argv[2],"triInsertion")==0){ + triInsertion(tableau, taille); + } + else if(strcmp(argv[2],"triFusion")==0){ + triFusion(tableau, taille); + } + else if(strcmp(argv[2],"triRapide")==0){ + triRapide(tableau, taille); + } + else{ + printf("algo: {triInsertion,triFusion,triRapide}\n"); + exit(EXIT_FAILURE); + } + afficheTab(taille,tableau); + free(tableau); + return 0; +} \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000000000000000000000000000000000000..18f405431d3a16c837b2e9c46903a44ed3c35a9d --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +all: main + +helpers.o: helpers.c helpers.h + gcc -Wall -c helpers.c + +tris.o: tris.c tris.h + gcc -Wall -c tris.c + +main: main.c tris.o helpers.o + gcc -Wall -o main tris.o helpers.o main.c -lm \ No newline at end of file diff --git a/plots/aleatoire.png b/plots/aleatoire.png new file mode 100644 index 0000000000000000000000000000000000000000..26c079915138a2db37afd8fbe7998bd9a04aab8b Binary files /dev/null and b/plots/aleatoire.png differ diff --git a/plots/aleatoire_mem.png b/plots/aleatoire_mem.png new file mode 100644 index 0000000000000000000000000000000000000000..cce946a13488cf5d0a9fc5a79eafc22fae019375 Binary files /dev/null and b/plots/aleatoire_mem.png differ diff --git a/plots/aleatoire_neg.png b/plots/aleatoire_neg.png new file mode 100644 index 0000000000000000000000000000000000000000..8354635b9135671f092056e07d4ad382bf61ff4e Binary files /dev/null and b/plots/aleatoire_neg.png differ diff --git a/plots/aleatoire_neg_mem.png b/plots/aleatoire_neg_mem.png new file mode 100644 index 0000000000000000000000000000000000000000..05862c05f287142f379941bca061ebc4131f9ef7 Binary files /dev/null and b/plots/aleatoire_neg_mem.png differ diff --git a/plots/trie.png b/plots/trie.png new file mode 100644 index 0000000000000000000000000000000000000000..132f4f0e6189714a4d4a807966963767dbf796b3 Binary files /dev/null and b/plots/trie.png differ diff --git a/plots/trie_inverse.png b/plots/trie_inverse.png new file mode 100644 index 0000000000000000000000000000000000000000..f3f7737e392e204ff2e80ae3ab654ed4b2d65cc8 Binary files /dev/null and b/plots/trie_inverse.png differ diff --git a/plots/trie_inverse_mem.png b/plots/trie_inverse_mem.png new file mode 100644 index 0000000000000000000000000000000000000000..c7a5cd5541631fcbbc2b700d3d2ad8817d0a6f48 Binary files /dev/null and b/plots/trie_inverse_mem.png differ diff --git a/plots/trie_mem.png b/plots/trie_mem.png new file mode 100644 index 0000000000000000000000000000000000000000..111f2aecdc67e4df526c8d962c4110ca0f43a914 Binary files /dev/null and b/plots/trie_mem.png differ diff --git a/recherche.sh b/recherche.sh new file mode 100755 index 0000000000000000000000000000000000000000..880f39653e552ec3b3ef2cbe9f7dc6941212e47b --- /dev/null +++ b/recherche.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +echo -e "Algo Type Taille Temps Mem" +for type in "aleatoire" "trieNegatif" "trie" "trieInverse" +do + for algo in "triInsertion" "triFusion" "triRapide" + do + n=0 + while [ $n -lt 20 ] + do + taille=$(shuf -i 10000-100000 -n 1) + res=$( (/usr/bin/time -f "%U %M" ./main $taille $algo $type > /dev/null) 2>&1 ) + echo -e "$algo $type $taille $res" + ((n++)) + done + done + echo "" +done +echo "" +echo "" + \ No newline at end of file diff --git a/test.csv b/test.csv new file mode 100644 index 0000000000000000000000000000000000000000..c1b8e33cb49bd5686e8ce2a3c6e8ce6373dcb009 --- /dev/null +++ b/test.csv @@ -0,0 +1,247 @@ +Algo Type Taille Temps Mem +triInsertion aleatoire 17483 0.25 1776 +triInsertion aleatoire 62935 3.14 1904 +triInsertion aleatoire 43316 1.53 1856 +triInsertion aleatoire 85654 6.07 1864 +triInsertion aleatoire 82160 5.58 1908 +triInsertion aleatoire 73663 4.31 1908 +triInsertion aleatoire 97099 7.12 2156 +triInsertion aleatoire 74608 4.25 1896 +triInsertion aleatoire 19898 0.31 1772 +triInsertion aleatoire 60683 2.86 1920 +triInsertion aleatoire 68106 3.68 1920 +triInsertion aleatoire 23673 0.46 1836 +triInsertion aleatoire 87165 5.99 1900 +triInsertion aleatoire 24615 0.47 1784 +triInsertion aleatoire 85494 5.65 1904 +triInsertion aleatoire 62202 3.04 1968 +triInsertion aleatoire 45965 1.62 1768 +triInsertion aleatoire 20491 0.34 1872 +triInsertion aleatoire 81113 4.88 1896 +triInsertion aleatoire 49301 1.78 1872 +triFusion aleatoire 10160 0.00 2024 +triFusion aleatoire 10321 0.00 2000 +triFusion aleatoire 14700 0.00 2084 +triFusion aleatoire 84506 0.01 2748 +triFusion aleatoire 94735 0.02 2808 +triFusion aleatoire 19732 0.00 1908 +triFusion aleatoire 46470 0.01 2276 +triFusion aleatoire 12818 0.00 2064 +triFusion aleatoire 50964 0.01 2188 +triFusion aleatoire 39657 0.01 2124 +triFusion aleatoire 74550 0.01 2628 +triFusion aleatoire 86582 0.01 2764 +triFusion aleatoire 91621 0.02 2804 +triFusion aleatoire 99998 0.02 2956 +triFusion aleatoire 72548 0.01 2744 +triFusion aleatoire 37550 0.00 2168 +triFusion aleatoire 26140 0.00 1880 +triFusion aleatoire 70805 0.01 2720 +triFusion aleatoire 72135 0.01 2648 +triFusion aleatoire 73684 0.01 2620 +triRapide aleatoire 60938 0.49 2128 +triRapide aleatoire 83064 0.93 2448 +triRapide aleatoire 16244 0.04 1964 +triRapide aleatoire 50253 0.35 1968 +triRapide aleatoire 81103 0.89 2092 +triRapide aleatoire 50316 0.35 2032 +triRapide aleatoire 85192 1.02 2392 +triRapide aleatoire 86984 1.07 2440 +triRapide aleatoire 60422 0.53 2240 +triRapide aleatoire 14254 0.03 2052 +triRapide aleatoire 23986 0.08 1796 +triRapide aleatoire 50867 0.36 1980 +triRapide aleatoire 27843 0.11 1884 +triRapide aleatoire 15973 0.03 2068 +triRapide aleatoire 79923 0.92 2248 +triRapide aleatoire 50116 0.36 2092 +triRapide aleatoire 44378 0.28 1972 +triRapide aleatoire 79256 0.91 2172 +triRapide aleatoire 96282 1.32 2480 +triRapide aleatoire 27580 0.10 1868 + +triInsertion trieNegatif 30337 0.73 1856 +triInsertion trieNegatif 26248 0.55 1776 +triInsertion trieNegatif 55298 2.46 1772 +triInsertion trieNegatif 95326 7.09 2216 +triInsertion trieNegatif 45353 1.56 1768 +triInsertion trieNegatif 97394 7.52 2184 +triInsertion trieNegatif 91338 6.86 1908 +triInsertion trieNegatif 90697 6.56 1876 +triInsertion trieNegatif 48125 1.78 1768 +triInsertion trieNegatif 89758 6.36 1908 +triInsertion trieNegatif 15961 0.21 1996 +triInsertion trieNegatif 41684 1.38 1768 +triInsertion trieNegatif 49248 2.07 1776 +triInsertion trieNegatif 63915 3.48 1900 +triInsertion trieNegatif 70589 4.15 1968 +triInsertion trieNegatif 71641 4.20 1864 +triInsertion trieNegatif 36976 1.14 1784 +triInsertion trieNegatif 20843 0.36 1768 +triInsertion trieNegatif 70602 4.05 1876 +triInsertion trieNegatif 15085 0.18 1976 +triFusion trieNegatif 41634 0.00 2156 +triFusion trieNegatif 79335 0.02 2704 +triFusion trieNegatif 56101 0.01 2288 +triFusion trieNegatif 24656 0.00 1988 +triFusion trieNegatif 38138 0.01 2160 +triFusion trieNegatif 88374 0.02 2856 +triFusion trieNegatif 18502 0.00 1944 +triFusion trieNegatif 68399 0.01 2604 +triFusion trieNegatif 77513 0.02 2684 +triFusion trieNegatif 46521 0.01 2160 +triFusion trieNegatif 79420 0.02 2784 +triFusion trieNegatif 45998 0.01 2172 +triFusion trieNegatif 49801 0.01 2180 +triFusion trieNegatif 88243 0.02 2776 +triFusion trieNegatif 56535 0.01 2268 +triFusion trieNegatif 31773 0.00 1908 +triFusion trieNegatif 96771 0.02 2840 +triFusion trieNegatif 32854 0.00 1876 +triFusion trieNegatif 53873 0.00 2300 +triFusion trieNegatif 55893 0.01 2256 +triRapide trieNegatif 16203 0.02 1908 +triRapide trieNegatif 97131 0.68 2168 +triRapide trieNegatif 62177 0.28 1988 +triRapide trieNegatif 75796 0.43 2184 +triRapide trieNegatif 62578 0.29 1940 +triRapide trieNegatif 76621 0.45 2160 +triRapide trieNegatif 93223 0.65 2160 +triRapide trieNegatif 39536 0.11 1960 +triRapide trieNegatif 10817 0.01 1968 +triRapide trieNegatif 80171 0.47 2204 +triRapide trieNegatif 20336 0.04 1808 +triRapide trieNegatif 11403 0.02 1860 +triRapide trieNegatif 61631 0.28 1988 +triRapide trieNegatif 58409 0.26 1900 +triRapide trieNegatif 83352 0.52 2216 +triRapide trieNegatif 38338 0.11 1936 +triRapide trieNegatif 37833 0.11 1848 +triRapide trieNegatif 27124 0.06 1936 +triRapide trieNegatif 51739 0.20 1964 +triRapide trieNegatif 48489 0.17 1924 + +triInsertion trie 53254 0.00 1872 +triInsertion trie 91068 0.01 1912 +triInsertion trie 10370 0.00 1960 +triInsertion trie 54301 0.00 1884 +triInsertion trie 55288 0.00 1772 +triInsertion trie 66900 0.00 1968 +triInsertion trie 80413 0.00 1976 +triInsertion trie 34080 0.00 1724 +triInsertion trie 18249 0.00 1752 +triInsertion trie 39537 0.00 1880 +triInsertion trie 59900 0.00 1896 +triInsertion trie 69045 0.00 1984 +triInsertion trie 68202 0.01 1896 +triInsertion trie 78402 0.00 1896 +triInsertion trie 34558 0.00 1820 +triInsertion trie 93859 0.00 2168 +triInsertion trie 52428 0.00 1824 +triInsertion trie 20768 0.00 1872 +triInsertion trie 27707 0.00 1756 +triInsertion trie 44944 0.00 1868 +triFusion trie 55091 0.01 2232 +triFusion trie 52357 0.01 2236 +triFusion trie 65579 0.01 2356 +triFusion trie 73885 0.01 2752 +triFusion trie 92857 0.01 2868 +triFusion trie 17336 0.00 1908 +triFusion trie 75203 0.01 2656 +triFusion trie 45040 0.00 2148 +triFusion trie 57053 0.01 2280 +triFusion trie 72056 0.01 2720 +triFusion trie 58593 0.01 2324 +triFusion trie 30149 0.00 1984 +triFusion trie 24984 0.00 1880 +triFusion trie 87498 0.01 2788 +triFusion trie 88167 0.01 2792 +triFusion trie 85186 0.01 2772 +triFusion trie 51567 0.01 2196 +triFusion trie 23945 0.00 1948 +triFusion trie 83603 0.02 2764 +triFusion trie 49149 0.01 2208 +triRapide trie 93758 19.43 7960 +triRapide trie 36572 2.99 4156 +triRapide trie 88086 16.80 7420 +triRapide trie 31223 2.13 3724 +triRapide trie 67581 9.97 6124 +triRapide trie 49591 5.24 4976 +triRapide trie 19118 0.81 2940 +triRapide trie 74925 11.91 6652 +triRapide trie 31381 2.02 3832 +triRapide trie 10288 0.21 2436 +triRapide trie 37136 2.85 4116 +triRapide trie 55169 6.31 5324 +triRapide trie 32561 2.23 3748 +triRapide trie 63114 8.37 5880 +triRapide trie 19774 0.81 3008 +triRapide trie 11091 0.25 2556 +triRapide trie 31178 2.01 3640 +triRapide trie 20640 0.90 3036 +triRapide trie 37411 2.85 4108 +triRapide trie 86509 15.83 7448 + +triInsertion trieInverse 71270 8.03 1940 +triInsertion trieInverse 51647 4.65 1776 +triInsertion trieInverse 71915 8.74 1900 +triInsertion trieInverse 89098 12.61 1908 +triInsertion trieInverse 89271 12.84 1952 +triInsertion trieInverse 78251 9.87 1976 +triInsertion trieInverse 92212 13.82 2308 +triInsertion trieInverse 68782 8.19 1968 +triInsertion trieInverse 55371 4.91 1724 +triInsertion trieInverse 33157 1.77 1856 +triInsertion trieInverse 93064 14.71 2288 +triInsertion trieInverse 23051 0.85 1724 +triInsertion trieInverse 63179 6.57 1900 +triInsertion trieInverse 28665 1.32 1856 +triInsertion trieInverse 26433 1.24 1868 +triInsertion trieInverse 89815 13.81 1912 +triInsertion trieInverse 84143 11.45 1896 +triInsertion trieInverse 26777 1.19 1876 +triInsertion trieInverse 73108 9.22 1900 +triInsertion trieInverse 92970 14.22 2280 +triFusion trieInverse 91140 0.01 2796 +triFusion trieInverse 99977 0.02 2952 +triFusion trieInverse 41166 0.01 2128 +triFusion trieInverse 53340 0.01 2340 +triFusion trieInverse 69363 0.01 2708 +triFusion trieInverse 28112 0.00 1992 +triFusion trieInverse 77209 0.01 2700 +triFusion trieInverse 42746 0.01 2176 +triFusion trieInverse 46485 0.01 2188 +triFusion trieInverse 60696 0.00 2308 +triFusion trieInverse 95660 0.02 2916 +triFusion trieInverse 24115 0.00 1916 +triFusion trieInverse 31043 0.00 1984 +triFusion trieInverse 48346 0.00 2292 +triFusion trieInverse 43228 0.00 2240 +triFusion trieInverse 41418 0.00 2168 +triFusion trieInverse 59978 0.01 2280 +triFusion trieInverse 25400 0.00 1896 +triFusion trieInverse 63916 0.01 2376 +triFusion trieInverse 85515 0.02 2812 +triRapide trieInverse 36744 2.41 4160 +triRapide trieInverse 15471 0.41 2856 +triRapide trieInverse 35722 2.28 3952 +triRapide trieInverse 48427 4.29 4896 +triRapide trieInverse 43482 3.35 4568 +triRapide trieInverse 12540 0.27 2664 +triRapide trieInverse 26690 1.27 3416 +triRapide trieInverse 63376 7.19 5856 +triRapide trieInverse 49042 4.49 4920 +triRapide trieInverse 73973 9.98 6476 +triRapide trieInverse 99280 18.01 8272 +triRapide trieInverse 47800 3.99 4992 +triRapide trieInverse 47302 3.95 4736 +triRapide trieInverse 91751 14.95 7732 +triRapide trieInverse 86642 13.55 7420 +triRapide trieInverse 30797 1.71 3676 +triRapide trieInverse 50148 4.57 4904 +triRapide trieInverse 85105 12.65 7144 +triRapide trieInverse 92036 14.75 7716 +triRapide trieInverse 43720 3.29 4452 + + + diff --git a/trie.csv b/trie.csv new file mode 100644 index 0000000000000000000000000000000000000000..e93ea2b6796424ffcf875108ad58eaaf14b8b5b6 --- /dev/null +++ b/trie.csv @@ -0,0 +1,61 @@ +Algo Taille Temps Mem +triInsertion 53254 0.00 1872 +triInsertion 91068 0.01 1912 +triInsertion 10370 0.00 1960 +triInsertion 54301 0.00 1884 +triInsertion 55288 0.00 1772 +triInsertion 66900 0.00 1968 +triInsertion 80413 0.00 1976 +triInsertion 34080 0.00 1724 +triInsertion 18249 0.00 1752 +triInsertion 39537 0.00 1880 +triInsertion 59900 0.00 1896 +triInsertion 69045 0.00 1984 +triInsertion 68202 0.01 1896 +triInsertion 78402 0.00 1896 +triInsertion 34558 0.00 1820 +triInsertion 93859 0.00 2168 +triInsertion 52428 0.00 1824 +triInsertion 20768 0.00 1872 +triInsertion 27707 0.00 1756 +triInsertion 44944 0.00 1868 +triFusion 55091 0.01 2232 +triFusion 52357 0.01 2236 +triFusion 65579 0.01 2356 +triFusion 73885 0.01 2752 +triFusion 92857 0.01 2868 +triFusion 17336 0.00 1908 +triFusion 75203 0.01 2656 +triFusion 45040 0.00 2148 +triFusion 57053 0.01 2280 +triFusion 72056 0.01 2720 +triFusion 58593 0.01 2324 +triFusion 30149 0.00 1984 +triFusion 24984 0.00 1880 +triFusion 87498 0.01 2788 +triFusion 88167 0.01 2792 +triFusion 85186 0.01 2772 +triFusion 51567 0.01 2196 +triFusion 23945 0.00 1948 +triFusion 83603 0.02 2764 +triFusion 49149 0.01 2208 +triRapide 93758 19.43 7960 +triRapide 36572 2.99 4156 +triRapide 88086 16.80 7420 +triRapide 31223 2.13 3724 +triRapide 67581 9.97 6124 +triRapide 49591 5.24 4976 +triRapide 19118 0.81 2940 +triRapide 74925 11.91 6652 +triRapide 31381 2.02 3832 +triRapide 10288 0.21 2436 +triRapide 37136 2.85 4116 +triRapide 55169 6.31 5324 +triRapide 32561 2.23 3748 +triRapide 63114 8.37 5880 +triRapide 19774 0.81 3008 +triRapide 11091 0.25 2556 +triRapide 31178 2.01 3640 +triRapide 20640 0.90 3036 +triRapide 37411 2.85 4108 +triRapide 86509 15.83 7448 \ No newline at end of file diff --git a/trieInverse.csv b/trieInverse.csv new file mode 100755 index 0000000000000000000000000000000000000000..1d3d95a9b0ef20cbe0064a2578d41a0f07f15ecd --- /dev/null +++ b/trieInverse.csv @@ -0,0 +1,61 @@ +Algo Taille Temps Mem +triInsertion 71270 8.03 1940 +triInsertion 51647 4.65 1776 +triInsertion 71915 8.74 1900 +triInsertion 89098 12.61 1908 +triInsertion 89271 12.84 1952 +triInsertion 78251 9.87 1976 +triInsertion 92212 13.82 2308 +triInsertion 68782 8.19 1968 +triInsertion 55371 4.91 1724 +triInsertion 33157 1.77 1856 +triInsertion 93064 14.71 2288 +triInsertion 23051 0.85 1724 +triInsertion 63179 6.57 1900 +triInsertion 28665 1.32 1856 +triInsertion 26433 1.24 1868 +triInsertion 89815 13.81 1912 +triInsertion 84143 11.45 1896 +triInsertion 26777 1.19 1876 +triInsertion 73108 9.22 1900 +triInsertion 92970 14.22 2280 +triFusion 91140 0.01 2796 +triFusion 99977 0.02 2952 +triFusion 41166 0.01 2128 +triFusion 53340 0.01 2340 +triFusion 69363 0.01 2708 +triFusion 28112 0.00 1992 +triFusion 77209 0.01 2700 +triFusion 42746 0.01 2176 +triFusion 46485 0.01 2188 +triFusion 60696 0.00 2308 +triFusion 95660 0.02 2916 +triFusion 24115 0.00 1916 +triFusion 31043 0.00 1984 +triFusion 48346 0.00 2292 +triFusion 43228 0.00 2240 +triFusion 41418 0.00 2168 +triFusion 59978 0.01 2280 +triFusion 25400 0.00 1896 +triFusion 63916 0.01 2376 +triFusion 85515 0.02 2812 +triRapide 36744 2.41 4160 +triRapide 15471 0.41 2856 +triRapide 35722 2.28 3952 +triRapide 48427 4.29 4896 +triRapide 43482 3.35 4568 +triRapide 12540 0.27 2664 +triRapide 26690 1.27 3416 +triRapide 63376 7.19 5856 +triRapide 49042 4.49 4920 +triRapide 73973 9.98 6476 +triRapide 99280 18.01 8272 +triRapide 47800 3.99 4992 +triRapide 47302 3.95 4736 +triRapide 91751 14.95 7732 +triRapide 86642 13.55 7420 +triRapide 30797 1.71 3676 +triRapide 50148 4.57 4904 +triRapide 85105 12.65 7144 +triRapide 92036 14.75 7716 +triRapide 43720 3.29 4452 \ No newline at end of file diff --git a/trieNegatif.csv b/trieNegatif.csv new file mode 100644 index 0000000000000000000000000000000000000000..b66c13344cfb67568cdadf179772fddeca9c2962 --- /dev/null +++ b/trieNegatif.csv @@ -0,0 +1,61 @@ +Algo Taille Temps Mem +triInsertion 30337 0.73 1856 +triInsertion 26248 0.55 1776 +triInsertion 55298 2.46 1772 +triInsertion 95326 7.09 2216 +triInsertion 45353 1.56 1768 +triInsertion 97394 7.52 2184 +triInsertion 91338 6.86 1908 +triInsertion 90697 6.56 1876 +triInsertion 48125 1.78 1768 +triInsertion 89758 6.36 1908 +triInsertion 15961 0.21 1996 +triInsertion 41684 1.38 1768 +triInsertion 49248 2.07 1776 +triInsertion 63915 3.48 1900 +triInsertion 70589 4.15 1968 +triInsertion 71641 4.20 1864 +triInsertion 36976 1.14 1784 +triInsertion 20843 0.36 1768 +triInsertion 70602 4.05 1876 +triInsertion 15085 0.18 1976 +triFusion 41634 0.00 2156 +triFusion 79335 0.02 2704 +triFusion 56101 0.01 2288 +triFusion 24656 0.00 1988 +triFusion 38138 0.01 2160 +triFusion 88374 0.02 2856 +triFusion 18502 0.00 1944 +triFusion 68399 0.01 2604 +triFusion 77513 0.02 2684 +triFusion 46521 0.01 2160 +triFusion 79420 0.02 2784 +triFusion 45998 0.01 2172 +triFusion 49801 0.01 2180 +triFusion 88243 0.02 2776 +triFusion 56535 0.01 2268 +triFusion 31773 0.00 1908 +triFusion 96771 0.02 2840 +triFusion 32854 0.00 1876 +triFusion 53873 0.00 2300 +triFusion 55893 0.01 2256 +triRapide 16203 0.02 1908 +triRapide 97131 0.68 2168 +triRapide 62177 0.28 1988 +triRapide 75796 0.43 2184 +triRapide 62578 0.29 1940 +triRapide 76621 0.45 2160 +triRapide 93223 0.65 2160 +triRapide 39536 0.11 1960 +triRapide 10817 0.01 1968 +triRapide 80171 0.47 2204 +triRapide 20336 0.04 1808 +triRapide 11403 0.02 1860 +triRapide 61631 0.28 1988 +triRapide 58409 0.26 1900 +triRapide 83352 0.52 2216 +triRapide 38338 0.11 1936 +triRapide 37833 0.11 1848 +triRapide 27124 0.06 1936 +triRapide 51739 0.20 1964 +triRapide 48489 0.17 1924 \ No newline at end of file diff --git a/tris.c b/tris.c new file mode 100644 index 0000000000000000000000000000000000000000..251ccb031296d8d0203c25462040b53a8f3a39a2 --- /dev/null +++ b/tris.c @@ -0,0 +1,107 @@ +#include "tris.h" + +/** + * Algo de tri par insertion +*/ +void triInsertion(long* A, size_t n) { + int cle,j; + for(int i=1; i < n; i++){ + cle=A[i]; + j=i-1; + while(j >= 0 && A[j] > cle){ + A[j+1]=A[j]; + j--; + } + A[j+1]=cle; + } +} + +/** + * Algo de tri par fusion +*/ +void triFusion(long* A, size_t n) { + sousTriFusion(A,0,n); +} + +void sousTriFusion(long* A, size_t p, size_t r){ + if(p<r-1){ + size_t q=(p+r)/2; + sousTriFusion(A,p,q); + sousTriFusion(A,q,r); + fusion(A,p,q,r); + } +} + +void fusion(long *A,size_t p, size_t q, size_t r){ + int n1 = (int)q - (int)p; + int n2 = (int)r - (int)q; + + long* Ag = malloc(sizeof(long)*n1); + long* Ad = malloc(sizeof(long)*n2); + + memcpy(Ag, &A[p], n1*sizeof(long)); + memcpy(Ad, &A[q], n2*sizeof(long)); + + size_t indG = 0; + size_t indD = 0; + size_t i = p; + + while(i < r) { + if(indG == n1) { + A[i] = Ad[indD]; + indD++; + } + else if( indD == n2) { + A[i] = Ag[indG]; + indG++; + } + else if (Ag[indG] < Ad[indD]) { + A[i] = Ag[indG]; + indG++; + } + else { + A[i] = Ad[indD]; + indD++; + } + i++; + } + free(Ag); + free(Ad); +} + +/** + * Algo de tri "rapide" +*/ +void triRapide(long* A, size_t n) { + sousTriRapide(A, 0, n); +} + +void sousTriRapide(long *A, size_t p, size_t r){ + size_t max = -1; + if(r-1 != max && p < r-1){ + size_t q = partition(A,p,r); + sousTriRapide(A,p,q); + sousTriRapide(A,q+1,r); + } +} + +size_t partition(long* A, size_t p, size_t r) +{ + long mem, pivot = A[r-1]; + size_t i = p; + + for(size_t j = p; j <= r - 2; j++) { + if(A[j] <= pivot) { + mem = A[i]; + A[i] = A[j]; + A[j] = mem; + i++; + } + } + + mem = A[i]; + A[i] = A[r - 1]; + A[r-1] = mem; + + return i; +} \ No newline at end of file diff --git a/tris.h b/tris.h new file mode 100644 index 0000000000000000000000000000000000000000..062a69dea7b2435472d8cd6b8d36ee64239b942a --- /dev/null +++ b/tris.h @@ -0,0 +1,10 @@ +#include <stdlib.h> +#include <string.h> + +void triInsertion(long* A, size_t n); +void triFusion(long* A, size_t n); +void sousTriFusion(long* A, size_t p, size_t r); +void fusion(long* A, size_t p, size_t q, size_t r); +void triRapide(long* A, size_t n); +void sousTriRapide(long* A, size_t p, size_t r); +size_t partition(long* A, size_t p, size_t r); \ No newline at end of file diff --git a/tris.o b/tris.o new file mode 100644 index 0000000000000000000000000000000000000000..585f941d439dc070ee454728c69272ecfa06799a Binary files /dev/null and b/tris.o differ