10 Fevrier
This commit is contained in:
parent
991fb4d62a
commit
0c05731f22
@ -72,7 +72,7 @@ void voisinage(graphe g,int s){
|
||||
}
|
||||
}
|
||||
|
||||
void nbrVoisin(graphe g,int s){
|
||||
int nbrVoisin(graphe g,int s){
|
||||
int i;
|
||||
int nbrVoisin=0;
|
||||
int nbrVoisinEntrant=0;
|
||||
@ -83,6 +83,7 @@ void nbrVoisin(graphe g,int s){
|
||||
nbrVoisin++;
|
||||
}
|
||||
} printf("Le sommet %d possede %d voisin(s)\n",s,nbrVoisin);
|
||||
return nbrVoisin;
|
||||
} else{
|
||||
for(i=0;i<g.ordre;i++){
|
||||
if(g.adj[i][s]==1){
|
||||
@ -94,6 +95,104 @@ void nbrVoisin(graphe g,int s){
|
||||
nbrVoisinSortant++;
|
||||
}
|
||||
} printf("Le sommet %d possede %d voisin(s) sortant(s)\n",s,nbrVoisinSortant);
|
||||
} return nbrVoisinSortant+nbrVoisinEntrant;
|
||||
}
|
||||
|
||||
void afficherMatrice(int **m,int taille){
|
||||
int i;
|
||||
int j;
|
||||
putchar('\n');
|
||||
for (i=0;i<taille;i++){
|
||||
for (j=0;j<taille;j++){
|
||||
printf("%3d ",m[i][j]);
|
||||
} putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void afficherAdjacence(graphe g){
|
||||
int i;
|
||||
int j;
|
||||
putchar('\n');
|
||||
for (i=0;i<g.ordre;i++){
|
||||
for (j=0;j<g.ordre;j++){
|
||||
printf("%3d ",g.adj[i][j]);
|
||||
} putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
int** multiplicationMatriceCarre(int **a,int **b,int taille){
|
||||
int** res=calloc(taille,sizeof(int*));
|
||||
int i,j,k;
|
||||
for(i=0;i<taille;i++){
|
||||
res[i]=calloc(taille,sizeof(int));
|
||||
} for(i=0;i<taille;i++){
|
||||
for(j=0;j<taille;j++){
|
||||
for(k=0;k<taille;k++){
|
||||
res[i][j]+=a[i][k]*b[k][j];
|
||||
}
|
||||
}
|
||||
} return res;
|
||||
}
|
||||
|
||||
int** additionMatriceCarre(int **a,int **b,int taille){
|
||||
int** res=calloc(taille,sizeof(int*));
|
||||
int i,j,k;
|
||||
for(i=0;i<taille;i++){
|
||||
res[i]=calloc(taille,sizeof(int));
|
||||
} for(i=0;i<taille;i++){
|
||||
for(j=0;j<taille;j++){
|
||||
for(k=0;k<taille;k++){
|
||||
res[i][j]=a[i][k]+b[k][j];
|
||||
}
|
||||
}
|
||||
} return res;
|
||||
}
|
||||
|
||||
int** nombreDeChemins(graphe g,int longueur){
|
||||
int** res=calloc(g.ordre,sizeof(int*));
|
||||
int i,j;
|
||||
for(i=0;i<g.ordre;i++){
|
||||
res[i]=calloc(g.ordre,sizeof(int));
|
||||
} for (i=0;i<g.ordre;i++){
|
||||
for (j=0;j<g.ordre;j++){
|
||||
res[i][j]=g.adj[i][j];
|
||||
}
|
||||
} for (i=0;i<longueur-1;i++){
|
||||
res=multiplicationMatriceCarre(res,g.adj,g.ordre);
|
||||
} return res;
|
||||
}
|
||||
|
||||
int estConnexe(graphe g){
|
||||
int v=1;
|
||||
int** res=calloc(g.ordre,sizeof(int*));
|
||||
int i,j;
|
||||
for(i=0;i<g.ordre;i++){
|
||||
res[i]=calloc(g.ordre,sizeof(int));
|
||||
} for (i=0;i<g.ordre;i++){
|
||||
res=additionMatriceCarre(res,(nombreDeChemins(g,i)),g.ordre);
|
||||
} for (i=0;i<g.ordre;i++){
|
||||
for (j=0;j<g.ordre;j++){
|
||||
if(res[i][j]==0){
|
||||
v=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} return v;
|
||||
}
|
||||
|
||||
int estEulerien(graphe g){
|
||||
int v=1;
|
||||
int i;
|
||||
int deg;
|
||||
if(estConnexe(g)){
|
||||
for(i=0;i<g.ordre;i++){
|
||||
deg=nbrVoisin(g,i);
|
||||
if(deg%2==1){
|
||||
v=0;
|
||||
}
|
||||
} return v;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,28 +234,3 @@ void visuelGraphe(graphe g){
|
||||
Touche();
|
||||
FermerGraphique();
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]){
|
||||
graphe Graphe;
|
||||
Graphe=creergraphe(7,0);
|
||||
ajoutArete(Graphe,0,1); /*0=France,1=Belgique*/
|
||||
ajoutArete(Graphe,0,2); /*2=Luxembourg*/
|
||||
ajoutArete(Graphe,0,3); /*3=Allemagne*/
|
||||
ajoutArete(Graphe,0,4); /*4=Suisse*/
|
||||
ajoutArete(Graphe,0,5); /*5=Italie*/
|
||||
ajoutArete(Graphe,0,6); /*6=Espagne*/
|
||||
ajoutArete(Graphe,1,2);
|
||||
ajoutArete(Graphe,1,3);
|
||||
ajoutArete(Graphe,1,4);
|
||||
ajoutArete(Graphe,2,3);
|
||||
ajoutArete(Graphe,2,4);
|
||||
ajoutArete(Graphe,3,4);
|
||||
voisinage(Graphe,0);
|
||||
nbrVoisin(Graphe,0);
|
||||
voisinage(Graphe,4);
|
||||
nbrVoisin(Graphe,4);
|
||||
voisinage(Graphe,5);
|
||||
nbrVoisin(Graphe,5);
|
||||
visuelGraphe(Graphe);
|
||||
return 0;
|
||||
}
|
51
Graphes/testgraphe.c
Normal file
51
Graphes/testgraphe.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "FichierDef.h"
|
||||
|
||||
|
||||
int main(int argc, char const *argv[]){
|
||||
graphe Graphe;
|
||||
int connexe;
|
||||
int eulerien;
|
||||
Graphe=creergraphe(7,0);
|
||||
ajoutArete(Graphe,0,1);
|
||||
ajoutArete(Graphe,0,2);
|
||||
ajoutArete(Graphe,0,3);
|
||||
ajoutArete(Graphe,0,4);
|
||||
ajoutArete(Graphe,0,5);
|
||||
ajoutArete(Graphe,0,6);
|
||||
ajoutArete(Graphe,1,2);
|
||||
ajoutArete(Graphe,1,3);
|
||||
ajoutArete(Graphe,1,4);
|
||||
ajoutArete(Graphe,2,3);
|
||||
ajoutArete(Graphe,2,4);
|
||||
ajoutArete(Graphe,3,4);
|
||||
ajoutArete(Graphe,5,4);
|
||||
ajoutArete(Graphe,6,2);
|
||||
ajoutArete(Graphe,6,5);
|
||||
ajoutArete(Graphe,4,5);
|
||||
ajoutArete(Graphe,2,5);
|
||||
ajoutArete(Graphe,6,4);
|
||||
voisinage(Graphe,0);
|
||||
nbrVoisin(Graphe,0);
|
||||
voisinage(Graphe,4);
|
||||
nbrVoisin(Graphe,4);
|
||||
voisinage(Graphe,5);
|
||||
nbrVoisin(Graphe,5);
|
||||
afficherAdjacence(Graphe);
|
||||
afficherMatrice(nombreDeChemins(Graphe,2),Graphe.ordre);
|
||||
connexe=estConnexe(Graphe);
|
||||
if(connexe==1){
|
||||
printf("Le graphe est connexe.\n");
|
||||
}else{
|
||||
printf("Le graphe n'est pas connexe.\n");
|
||||
}
|
||||
eulerien=estEulerien(Graphe);
|
||||
if(eulerien==1){
|
||||
printf("Le graphe est eulerien.\n");
|
||||
}else{
|
||||
printf("Le graphe n'est pas eulerien.\n");
|
||||
}
|
||||
visuelGraphe(Graphe);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user