Commit d462686c authored by Julien David's avatar Julien David
Browse files

Ajout des premiers programmes

parents
CLASSIC_FILE=src/main.o src/recherche.o
RAND_FILE=src/mainRand.o src/randWord.o src/recherche.o
FICHIER_FILE=src/mainFichier.o src/randWord.o src/recherche.o
CFLAGS=-g -Wall -ansi -pedantic -O3
all:naif naifRand naifFichier naifint naifRandint naifFichierint mp mpRand mpFichier kmp kmpRand kmpFichier bord KMPbord randWord bm bmRand
naif: src/naif.o $(CLASSIC_FILE)
gcc $(CFLAGS) src/naif.o $(CLASSIC_FILE) -o naif
naifint: src/naifint.o $(CLASSIC_FILE)
gcc $(CFLAGS) src/naifint.o $(CLASSIC_FILE) -o naifint
naifRand: src/naif.o $(RAND_FILE)
gcc $(CFLAGS) src/naif.o $(RAND_FILE) -o naifRand
naifRandint: src/naifint.o $(RAND_FILE)
gcc $(CFLAGS) src/naifint.o $(RAND_FILE) -o naifRandint
naifFichier:src/naif.o $(FICHIER_FILE)
gcc $(CFLAGS) src/naif.o $(FICHIER_FILE) -o naifFichier
naifFichier:src/naifint.o $(FICHIER_FILE)
gcc $(CFLAGS) src/naifint.o $(FICHIER_FILE) -o naifFichierint
randWord:src/randWordMain.o src/randWord.o
gcc $(CFLAGS) src/randWordMain.o src/randWord.o -o randWord
bord:src/bord.o
gcc $(CFLAGS) src/bord.o -o bord
KMPbord:src/KMPbord.o
gcc $(CFLAGS) src/KMPbord.o -o KMPbord
mp:src/morris_pratt.o $(CLASSIC_FILE)
gcc $(CFLAGS) src/morris_pratt.o $(CLASSIC_FILE) -o mp
mpRand:src/morris_pratt.o $(RAND_FILE)
gcc $(CFLAGS) src/morris_pratt.o $(RAND_FILE) -o mpRand
mpFichier:src/morris_pratt.o $(FICHIER_FILE)
gcc $(CFLAGS) src/morris_pratt.o $(FICHIER_FILE) -o mpFichier
kmp:src/kmp.o $(CLASSIC_FILE)
gcc $(CFLAGS) src/kmp.o $(CLASSIC_FILE) -o kmp
kmpRand:src/kmp.o $(RAND_FILE)
gcc $(CFLAGS) src/kmp.o $(RAND_FILE) -o kmpRand
kmpFichier:src/kmp.o $(FICHIER_FILE)
gcc $(CFLAGS) src/kmp.o $(FICHIER_FILE) -o kmpFichier
bm:src/bm.o $(CLASSIC_FILE)
gcc $(CFLAGS) src/bm.o $(CLASSIC_FILE) -o bm
bmRand:src/bm.o $(RAND_FILE)
gcc $(CFLAGS) src/bm.o $(RAND_FILE) -o bmRand
clean:
rm -rf *.o
rm -rf *~
rm -rf naif
rm -rf naifRand
rm -rf naifFichier
rm -rf randWord
rm -rf bord
rm -rf KMPbord
rm -rf mp
rm -rf mpRand
rm -rf mpFichier
rm -rf kmp
rm -rf kmpRand
rm -rf kmpFichier
rm -rf bm
rm -rf bmRand
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
CAGATTTTTAAATGAGGGAAGACACCAAGTAAAACACCACCTTATTTTGTAGCCAGGAAACAGATTTTTAAATGAGGGAAGACACCAAGTAAAACACCACCTTATTTTGTAGCCAGGAAACAGATTTTTAAATGAGGGAAGACACCAAGTAAAACACCACCTTATTTTGTAGCCAGGAAAC
This diff is collapsed.
This diff is collapsed.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "recherche.h"
int main(int argc,char ** argv){
int n,m,k;
int nb_occ;
if(argc==4){
n=strlen(argv[1]);
m=strlen(argv[2]);
k=atoi(argv[3]);
nb_occ=recherche(argv[1],argv[2],n,m,k);
printf("%d occurrences trouvées en %d comparaisons\n",nb_occ,nb_comparaisons);
}
return EXIT_SUCCESS;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "recherche.h"
#include <sys/stat.h>
char * charger_texte(const char * path,int * n){
FILE * f;
struct stat st;
char * buffer=NULL;
if((f=fopen(path,"r"))!=NULL){
stat(path, &st);
*n=st.st_size;
buffer=(char *)malloc(sizeof(char)*st.st_size);
if(fread(buffer,sizeof(char),*n,f)!=*n)
printf("Erreur de lecture\n");
}
fclose(f);
return buffer;
}
int main(int argc, char ** argv){
int n,m,nb_occ;
char * texte;
char * motif;
if(argc==3){
texte=charger_texte(argv[1],&n);
motif=argv[2];
m=strlen(motif);
nb_occ=recherche(texte,motif,n,m,0);
printf("%d occurrences ont été trouvées après %d comparaisons\n",nb_occ,nb_comparaisons);
free(texte);
}
else
printf("./naif [fichier_source] [motif]\n");
return EXIT_SUCCESS;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include "randWord.h"
#include "recherche.h"
#define NB_TEST 10000
int main(int argc, char ** argv){
int n,m,k,nb_occ,i,nb_moyen;
char * texte,*motif;
srand(time(NULL));
if(argc==4){
n=atoi(argv[1]);
m=atoi(argv[2]);
k=atoi(argv[3]);
printf("n=%d, m=%d et k=%d\n",n,m,k);
texte=(char*)malloc(sizeof(int)*(n+1));
motif=(char*)malloc(sizeof(int)*(m+1));
for(i=0,nb_moyen=0;i<NB_TEST;i++){
nb_comparaisons=0;
randWord2(texte,n,k);
randWord2(motif,m,k);
nb_occ=recherche(texte,motif,n,m,k);
nb_moyen+=nb_comparaisons;
/*printf("%d occurrences ont été trouvées après %d comparaisons\n",nb_occ,nb_comparaisons);*/
}
printf("En moyenne, le nombre de comparaisons par lettre est égal à %f\n",((double)nb_moyen)/(n*NB_TEST));
free(texte);
free(motif);
}
else
printf("./naif [longueur_texte] [longueur_motif] [taille_alphabet]\n");
return EXIT_SUCCESS;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "naif.h"
#include"recherche.h"
int algorithme_naif(char * texte,char * motif,int n,int m){
int i,j;
int res;
for(i=0,res=0;i<=(n-m);i++){
j=0;
while(j<m&&comparer_lettre(texte[i+j],motif[j]))
j++;
if(j==m)
res++;
}
return res;
}
int recherche(char * texte,char * motif,int n,int m,int k){
return algorithme_naif(texte,motif,n,m);
}
#ifndef NAIF_H
#define NAIF_H
int algorithme_naif(char * texte,char * motif,int n,int m);
#endif
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"randWord.h"
char * randWord(int n,int k){
char * res;
int i;
res=(char*)malloc(sizeof(char)*(n+1));
for(i=0;i<n;i++)
res[i]=(char)('a'+rand()%k);
res[n]='\0';
return res;
}
void randWord2(char * res,int n,int k){
int i;
for(i=0;i<n;i++)
res[i]=(char)('a'+rand()%k);
res[n]='\0';
}
char * randWord(int n,int k);
void randWord2(char * res, int n,int k);
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"randWord.h"
int main(int argc,char ** argv){
int n,k;
char * res;
if(argc==3){
n=atoi(argv[1]);
k=atoi(argv[2]);
printf("%d %d\n",n,k);
srand(time(NULL));
res=randWord(n,k);
printf("%s\n",res);
free(res);
}
else
printf("./randWord size AlphabetSize\n");
return EXIT_SUCCESS;
}
#include"recherche.h"
int comparer_lettre(char l1,char l2){
nb_comparaisons++;
return (l1==l2)?1:0;
}
int comparer_lettres(unsigned int l1,unsigned int l2){
nb_comparaisons++;
return (l1==l2)?1:0;
}
#ifndef RECHERCHE_H
#define RECHERCHE_H
int nb_comparaisons;
int recherche(char * texte,char * motif,int n,int m,int k);
int comparer_lettre(char l1,char l2);
int comparer_lettres(unsigned int l1,unsigned int l2);
#endif
Markdown is supported
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