Skip to content
Snippets Groups Projects
Commit 20bce8c8 authored by Ukhanov Ilya's avatar Ukhanov Ilya
Browse files

TP2 continuation

parents 4b3a232c 7c4e1807
No related merge requests found
all: main
main : tri_fusion.o tri_insertion.o tri_rapide.o utils.o main.c
gcc -o main -Wall utils.o tri_fusion.o tri_insertion.o tri_rapide.o -g main.c
tri_fusion.o : tri_fusion.c tri_fusion.h
gcc -c -Wall -g tri_fusion.c
tri_insertion.o : tri_insertion.c tri_insertion.h
gcc -c -Wall -g tri_insertion.c
tri_rapide.o : tri_rapide.c tri_rapide.h
gcc -c -Wall -g tri_rapide.c
utils.o : utils.c utils.h
gcc -c -g utils.c
clean :
rm *.o
Projet/ggossaprodansR.png

61.7 KiB

#include <stdio.h>
#include <stdlib.h>
#include "tri_insertion.h"
#include "tri_rapide.h"
#include "tri_fusion.h"
#include "utils.h"
int main(int argc, char *argv[]) {
if(argc != 5) {
printf("Usage: %s [typeAlgo] [taille] [typeTableau] [isAfficher]\n", argv[0]);
exit(1);
}
char typeAlgo = argv[1][0];
long taille = (long) atoi(argv[2]);
long MAX = 50;
long tab[taille];
char typeTable = argv[3][0];
size_t afficher = (size_t) atoi(argv[4]);
genTab(tab, taille, typeTable, MAX);
switch(typeAlgo) {
case 'i':
triInsertion(tab,taille);
if(afficher) {
printf("Tri Insertion: \n");
affichertab(tab,taille);
}
break;
case 'r':
triRapide(tab, taille);
if(afficher) {
printf("Tri Rapide: \n");
affichertab(tab,taille);
}
break;
case 'f':
triFusion(tab, taille);
if(afficher) {
printf("Tri Fusion: \n");
affichertab(tab,taille);
}
break;
}
return 0;
}
library(ggplot2)
perf <- read.table("test.dat", header = TRUE)
ggplot(perf, aes(x=taille, y=temps, group=algo, colour=as.character(algo))) + facet_grid(algo ~ typeTableau) +
geom_point() + geom_smooth() +
ggtitle("Graphes Comparaison Algos")
ggsave("graphe.png")
-e iTest taille temps mem algo typeTableau
-e 1 59296 2.17 1772 i a
-e 1 59296 0.00 1704 i r
-e 1 59296 4.47 1656 i i
-e 1 59296 0.00 1700 i c
-e 1 59296 0.23 1848 r a
-e 1 59296 11.35 5416 r r
-e 1 59296 7.77 5412 r i
-e 1 59296 11.25 5412 r c
-e 1 59296 0.01 1992 f a
-e 1 59296 0.01 1964 f r
-e 1 59296 0.00 2032 f i
-e 1 59296 0.00 1956 f c
-e 2 97794 6.03 1988 i a
-e 2 97794 0.00 1988 i r
-e 2 97794 12.13 1928 i i
-e 2 97794 0.00 2012 i c
-e 2 97794 0.61 2116 r a
-e 2 97794 30.32 8036 r r
-e 2 97794 20.98 8116 r i
-e 2 97794 30.33 8100 r c
-e 2 97794 0.01 2604 f a
-e 2 97794 0.01 2544 f r
-e 2 97794 0.01 2680 f i
-e 2 97794 0.01 2556 f c
-e 3 41540 1.08 1496 i a
-e 3 41540 0.00 1576 i r
-e 3 41540 2.17 1456 i i
-e 3 41540 0.00 1628 i c
-e 3 41540 0.11 1628 r a
-e 3 41540 5.49 4080 r r
-e 3 41540 3.82 4152 r i
-e 3 41540 5.39 4224 r c
-e 3 41540 0.00 1908 f a
-e 3 41540 0.00 1892 f r
-e 3 41540 0.00 1836 f i
-e 3 41540 0.00 1972 f c
-e 4 97964 5.95 1936 i a
-e 4 97964 0.00 2040 i r
-e 4 97964 12.07 1992 i i
-e 4 97964 0.00 2048 i c
-e 4 97964 0.62 2124 r a
-e 4 97964 32.03 8192 r r
-e 4 97964 21.83 8080 r i
-e 4 97964 30.63 8024 r c
-e 4 97964 0.02 2560 f a
-e 4 97964 0.01 2564 f r
-e 4 97964 0.01 2544 f i
-e 4 97964 0.01 2492 f c
-e 5 39669 1.00 1544 i a
-e 5 39669 0.00 1496 i r
-e 5 39669 2.03 1504 i i
-e 5 39669 0.00 1536 i c
-e 5 39669 0.10 1552 r a
-e 5 39669 5.03 4032 r r
-e 5 39669 3.44 3984 r i
-e 5 39669 5.00 4024 r c
-e 5 39669 0.00 1792 f a
-e 5 39669 0.00 1820 f r
-e 5 39669 0.00 1840 f i
-e 5 39669 0.00 1884 f c
-e 6 8038 0.04 1300 i a
-e 6 8038 0.00 1300 i r
-e 6 8038 0.08 1220 i i
-e 6 8038 0.00 1288 i c
-e 6 8038 0.00 1300 r a
-e 6 8038 0.20 1756 r r
-e 6 8038 0.14 1812 r i
-e 6 8038 0.21 1808 r c
-e 6 8038 0.00 1448 f a
-e 6 8038 0.00 1448 f r
-e 6 8038 0.00 1332 f i
-e 6 8038 0.00 1364 f c
-e 7 30705 0.59 1468 i a
-e 7 30705 0.00 1524 i r
-e 7 30705 1.19 1480 i i
-e 7 30705 0.00 1492 i c
-e 7 30705 0.06 1472 r a
-e 7 30705 3.02 3440 r r
-e 7 30705 2.08 3408 r i
-e 7 30705 3.00 3384 r c
-e 7 30705 0.00 1688 f a
-e 7 30705 0.00 1688 f r
-e 7 30705 0.00 1616 f i
-e 7 30705 0.00 1696 f c
-e 8 53435 1.81 1660 i a
-e 8 53435 0.00 1700 i r
-e 8 53435 3.66 1656 i i
-e 8 53435 0.00 1640 i c
-e 8 53435 0.18 1676 r a
-e 8 53435 9.15 4892 r r
-e 8 53435 6.50 5000 r i
-e 8 53435 9.16 4928 r c
-e 8 53435 0.01 1996 f a
-e 8 53435 0.00 1904 f r
-e 8 53435 0.00 1988 f i
-e 8 53435 0.00 1992 f c
-e 9 50961 1.61 1676 i a
-e 9 50961 0.00 1640 i r
-e 9 50961 3.30 1624 i i
-e 9 50961 0.00 1592 i c
-e 9 50961 0.17 1716 r a
-e 9 50961 8.31 4888 r r
-e 9 50961 5.85 4832 r i
-e 9 50961 8.27 4852 r c
-e 9 50961 0.00 1860 f a
-e 9 50961 0.00 1928 f r
-e 9 50961 0.00 1884 f i
-e 9 50961 0.00 1884 f c
-e 10 74748 3.49 1832 i a
-e 10 74748 0.00 1828 i r
-e 10 74748 7.11 1744 i i
-e 10 74748 0.00 1772 i c
-e 10 74748 0.37 1932 r a
-e 10 74748 17.97 6456 r r
-e 10 74748 12.53 6388 r i
-e 10 74748 18.00 6496 r c
-e 10 74748 0.01 2360 f a
-e 10 74748 0.01 2424 f r
-e 10 74748 0.01 2380 f i
-e 10 74748 0.01 2360 f c
#!/bin/bash
affichage=0
#taille=100
echo -e "iTest\ttaille\ttemps\tmem\talgo\ttypeTableau"
for iTest in `seq 1 10`
do
taille=$(( `od -An -N4 -tu < /dev/urandom` % 100000))
for algo in 'i' 'r' 'f'
do
for typeTableau in 'a' 'r' 'i' 'c'
do
res=`( /usr/bin/time -f "%U\t%M" ./main $algo $taille $typeTableau $affichage > /dev/null ) 2>&1`
echo -e "$iTest\t$taille\t$res\t$algo\t$typeTableau"
done
done
done
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tri_fusion.h"
void triFusion(long* A, size_t size) {
sousTriFusion(A, 0, size);
}
void sousTriFusion(long* A, size_t first, size_t size) {
if(first+1 <size){ // p < r - 1
size_t middle = floor((first+size)/2);
sousTriFusion(A, first, middle);
sousTriFusion(A, middle, size);
fusion(A, first, middle, size);
}
}
void copySousTable(long* mainT, long* underT, size_t id, size_t size) {
for(size_t i = id; i < id+size; ++i) {
underT[i-id] = mainT[i];
}
}
void fusion(long* A, size_t first, size_t middle, size_t size) {
size_t n1 = middle - first; // Nb elem dans A[p , q] q exclu
size_t n2 = size - middle; // Nb elem dans A[q , r] r exclu
size_t indg = 0;
size_t indd = 0;
long* ag = malloc(sizeof(long) * n1);
long* ad = malloc(sizeof(long) * n2);
copySousTable(A, ag, first, n1);
copySousTable(A, ad, middle, n2);
int i = first;
while(i < size) {
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);
}
\ No newline at end of file
#ifndef TRIS_F
#define TRIS_F
#include <stdint.h>
#include <stdlib.h>
void triFusion(long* A, size_t size);
void sousTriFusion(long* A, size_t first, size_t size);
void fusion(long* A, size_t first, size_t middle, size_t size);
#endif //TRIS_H
\ No newline at end of file
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tri_insertion.h"
void triInsertion(long* A, size_t n) {
for(size_t i = 1; i <= n-1; i++){
long cle = A[i];
size_t j = i - 1;
while(j+1 >= j && A[j] > cle){
A[j+1] = A[j];
j = j-1;
}
A[j+1] = cle;
}
}
\ No newline at end of file
#ifndef TRIS_I
#define TRIS_I
#include <stdint.h>
#include <stdlib.h>
void triInsertion(long* A, size_t n);
#endif //TRIS_H
\ No newline at end of file
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tri_rapide.h"
void triRapide(long* A, size_t n) {
sousTriRapide(A,0,n);
}
void sousTriRapide(long* A, size_t first, size_t size){
if(first+1 < size){
size_t middle = partition(A,first,size);
sousTriRapide(A,first,middle);
sousTriRapide(A,middle+1,size);
}
}
size_t partition(long* A, size_t first, size_t size) {
long pivot = A[size-1];
size_t i = first;
for(int j = first; j+2 <= size; j++){
if(A[j] <= pivot){
permuter(A,i,j);
i++;
}
}
permuter(A,i,size-1);
return i;
}
void permuter(long* A,size_t i,size_t j) {
long inter = A[i];
A[i] = A[j];
A[j] = inter;
}
#ifndef TRIS_R
#define TRIS_R
#include <stdint.h>
#include <stdlib.h>
void triRapide(long* A, size_t n);
void sousTriRapide(long* A, size_t first, size_t size);
size_t partition(long* A, size_t first, size_t size);
void permuter(long* A,size_t i,size_t j);
#endif //TRIS_H
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
void affichertab(long *T, int s)
{
printf("[ ");
for (int i = 0; i < s - 1; i++)
{
printf("%d , ", T[i]);
}
printf("%d ]\n", T[s - 1]);
}
void genTab(long *T, long taille, char type, long MAX)
{
switch (type)
{
case 'a':
//Tableau Aleatoire
for (long i = 0; i < taille; ++i)
{
T[i] = rand() % MAX;
}
break;
case 'r':
//Tableau Rangé
for (long i = 0; i < taille; ++i)
{
T[i] = i;
}
break;
case 'i':
//Tableau Rangé Inversé
for (long i = 0; i < taille; ++i)
{
T[i] = taille - i;
}
break;
case 'c':
//Tableau Constant
for (long i = 0; i < taille; ++i)
{
T[i] = 0;
}
break;
default:
break;
}
}
#include <stdio.h>
#include <stdlib.h>
void affichertab(long* T, int s);
void genTab(long *T, long taille, char type, long MAX);
TP2/ggossaprodansR.png

61.7 KiB

TP2/graphe.png

146 KiB

......@@ -7,8 +7,8 @@
#include "utils.h"
int main(int argc, char *argv[]) {
if(argc != 4) {
printf("Usage: %s [typeAlgo] [taille] [isAfficher]\n", argv[0]);
if(argc != 5) {
printf("Usage: %s [typeAlgo] [taille] [typeTableau] [isAfficher]\n", argv[0]);
exit(1);
}
......@@ -16,9 +16,10 @@ int main(int argc, char *argv[]) {
long taille = (long) atoi(argv[2]);
long MAX = 50;
long tab[taille];
size_t afficher = (size_t) atoi(argv[3]);
char typeTable = argv[3][0];
size_t afficher = (size_t) atoi(argv[4]);
genTab(tab, taille, MAX);
genTab(tab, taille, typeTable, MAX);
switch(typeAlgo) {
case 'i':
......
library(ggplot2)
perf <- read.table("test.dat", header = TRUE)
ggplot(perf, aes(x=taille, y=temps, group=algo, colour=as.character(algo))) +
ggplot(perf, aes(x=taille, y=temps, group=algo, colour=as.character(algo))) + facet_grid(algo ~ typeTableau) +
geom_point() + geom_smooth() +
ggtitle("Graphe Tri insertion")
ggtitle("Graphes Comparaison Algos")
ggsave("testInsertion.png")
ggsave("graphe.png")
iTest taille temps mem algo
1 29547 0.50 1536 i
1 29547 0.05 1500 r
1 29547 0.00 1616 f
2 95952 5.42 2024 i
2 95952 0.52 2044 r
2 95952 0.02 2496 f
3 76455 3.37 1820 i
3 76455 0.33 1928 r
3 76455 0.02 2448 f
4 18234 0.20 1308 i
4 18234 0.02 1440 r
4 18234 0.00 1588 f
5 63457 2.34 1748 i
5 63457 0.23 1820 r
5 63457 0.00 2148 f
6 64394 2.41 1808 i
6 64394 0.24 1820 r
6 64394 0.00 2072 f
7 62040 2.24 1736 i
7 62040 0.22 1816 r
7 62040 0.01 1984 f
8 29203 0.50 1512 i
8 29203 0.05 1552 r
8 29203 0.00 1604 f
9 17117 0.17 1324 i
9 17117 0.02 1292 r
9 17117 0.00 1512 f
10 47762 1.34 1616 i
10 47762 0.13 1684 r
10 47762 0.00 2024 f
-e iTest taille temps mem algo typeTableau
-e 1 59296 2.17 1772 i a
-e 1 59296 0.00 1704 i r
-e 1 59296 4.47 1656 i i
-e 1 59296 0.00 1700 i c
-e 1 59296 0.23 1848 r a
-e 1 59296 11.35 5416 r r
-e 1 59296 7.77 5412 r i
-e 1 59296 11.25 5412 r c
-e 1 59296 0.01 1992 f a
-e 1 59296 0.01 1964 f r
-e 1 59296 0.00 2032 f i
-e 1 59296 0.00 1956 f c
-e 2 97794 6.03 1988 i a
-e 2 97794 0.00 1988 i r
-e 2 97794 12.13 1928 i i
-e 2 97794 0.00 2012 i c
-e 2 97794 0.61 2116 r a
-e 2 97794 30.32 8036 r r
-e 2 97794 20.98 8116 r i
-e 2 97794 30.33 8100 r c
-e 2 97794 0.01 2604 f a
-e 2 97794 0.01 2544 f r
-e 2 97794 0.01 2680 f i
-e 2 97794 0.01 2556 f c
-e 3 41540 1.08 1496 i a
-e 3 41540 0.00 1576 i r
-e 3 41540 2.17 1456 i i
-e 3 41540 0.00 1628 i c
-e 3 41540 0.11 1628 r a
-e 3 41540 5.49 4080 r r
-e 3 41540 3.82 4152 r i
-e 3 41540 5.39 4224 r c
-e 3 41540 0.00 1908 f a
-e 3 41540 0.00 1892 f r
-e 3 41540 0.00 1836 f i
-e 3 41540 0.00 1972 f c
-e 4 97964 5.95 1936 i a
-e 4 97964 0.00 2040 i r
-e 4 97964 12.07 1992 i i
-e 4 97964 0.00 2048 i c
-e 4 97964 0.62 2124 r a
-e 4 97964 32.03 8192 r r
-e 4 97964 21.83 8080 r i
-e 4 97964 30.63 8024 r c
-e 4 97964 0.02 2560 f a
-e 4 97964 0.01 2564 f r
-e 4 97964 0.01 2544 f i
-e 4 97964 0.01 2492 f c
-e 5 39669 1.00 1544 i a
-e 5 39669 0.00 1496 i r
-e 5 39669 2.03 1504 i i
-e 5 39669 0.00 1536 i c
-e 5 39669 0.10 1552 r a
-e 5 39669 5.03 4032 r r
-e 5 39669 3.44 3984 r i
-e 5 39669 5.00 4024 r c
-e 5 39669 0.00 1792 f a
-e 5 39669 0.00 1820 f r
-e 5 39669 0.00 1840 f i
-e 5 39669 0.00 1884 f c
-e 6 8038 0.04 1300 i a
-e 6 8038 0.00 1300 i r
-e 6 8038 0.08 1220 i i
-e 6 8038 0.00 1288 i c
-e 6 8038 0.00 1300 r a
-e 6 8038 0.20 1756 r r
-e 6 8038 0.14 1812 r i
-e 6 8038 0.21 1808 r c
-e 6 8038 0.00 1448 f a
-e 6 8038 0.00 1448 f r
-e 6 8038 0.00 1332 f i
-e 6 8038 0.00 1364 f c
-e 7 30705 0.59 1468 i a
-e 7 30705 0.00 1524 i r
-e 7 30705 1.19 1480 i i
-e 7 30705 0.00 1492 i c
-e 7 30705 0.06 1472 r a
-e 7 30705 3.02 3440 r r
-e 7 30705 2.08 3408 r i
-e 7 30705 3.00 3384 r c
-e 7 30705 0.00 1688 f a
-e 7 30705 0.00 1688 f r
-e 7 30705 0.00 1616 f i
-e 7 30705 0.00 1696 f c
-e 8 53435 1.81 1660 i a
-e 8 53435 0.00 1700 i r
-e 8 53435 3.66 1656 i i
-e 8 53435 0.00 1640 i c
-e 8 53435 0.18 1676 r a
-e 8 53435 9.15 4892 r r
-e 8 53435 6.50 5000 r i
-e 8 53435 9.16 4928 r c
-e 8 53435 0.01 1996 f a
-e 8 53435 0.00 1904 f r
-e 8 53435 0.00 1988 f i
-e 8 53435 0.00 1992 f c
-e 9 50961 1.61 1676 i a
-e 9 50961 0.00 1640 i r
-e 9 50961 3.30 1624 i i
-e 9 50961 0.00 1592 i c
-e 9 50961 0.17 1716 r a
-e 9 50961 8.31 4888 r r
-e 9 50961 5.85 4832 r i
-e 9 50961 8.27 4852 r c
-e 9 50961 0.00 1860 f a
-e 9 50961 0.00 1928 f r
-e 9 50961 0.00 1884 f i
-e 9 50961 0.00 1884 f c
-e 10 74748 3.49 1832 i a
-e 10 74748 0.00 1828 i r
-e 10 74748 7.11 1744 i i
-e 10 74748 0.00 1772 i c
-e 10 74748 0.37 1932 r a
-e 10 74748 17.97 6456 r r
-e 10 74748 12.53 6388 r i
-e 10 74748 18.00 6496 r c
-e 10 74748 0.01 2360 f a
-e 10 74748 0.01 2424 f r
-e 10 74748 0.01 2380 f i
-e 10 74748 0.01 2360 f c
......@@ -3,7 +3,7 @@
affichage=0
#taille=100
echo -e "iTest\ttaille\ttemps\tmem\talgo"
echo -e "iTest\ttaille\ttemps\tmem\talgo\ttypeTableau"
for iTest in `seq 1 10`
do
......@@ -12,7 +12,10 @@ do
for algo in 'i' 'r' 'f'
do
res=`( /usr/bin/time -f "%U\t%M" ./main $algo $taille $affichage > /dev/null ) 2>&1`
echo -e "$iTest\t$taille\t$res\t$algo"
for typeTableau in 'a' 'r' 'i' 'c'
do
res=`( /usr/bin/time -f "%U\t%M" ./main $algo $taille $typeTableau $affichage > /dev/null ) 2>&1`
echo -e "$iTest\t$taille\t$res\t$algo\t$typeTableau"
done
done
done
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment