1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| #include <stdio.h>
#include <stdlib.h>
//Structure du graphe
struct Graphe{
int matadj[9][9];
char listeadj[9][9];
char nomsom[9];
int nbrsom;
int orient;
};
//Initialisation de toutes les fonctions
void InitGraph(Graphe GrapheCharge);
void MatriceAdj(char *matadj1,char *matadj2,Graphe GrapheCharge);
void ChargerGraphe(char chemin[],Graphe GrapheCharge);
void ListeAdj(char *matadj1,char *matadj2,Graphe GrapheCharge);
void Connexe(Graphe GrapheCharge);
void FortementConnexe();
//Initialisation du graphe
void InitGraph(Graphe GrapheCharge){
int l,c;
for(l=0;l<10;l++){
GrapheCharge.nomsom[l]=0;
}
GrapheCharge.nbrsom = 0;
GrapheCharge.orient = 0;
for(l=0;l<10;l++){
for(c=0;c<10;c++){
GrapheCharge.listeadj[l][c]=0;
GrapheCharge.matadj[l][c]=0;
}
}
}
//Cette fonction charge un graphe à partir d'un fichier texte
void ChargerGraphe(char chemin[],Graphe GrapheCharge){
//Chargement du fichier et initialisation du graphe
FILE *pFile;
char ligne_lue[20];
int ligne;
ligne = 0;
int i,l,c;
char matadj1,matadj2;
pFile = fopen("chemin","r");
//Lecture du fichier, inscription des informations du graphe dans GrapheCharge.
if(pFile!=NULL){
while(fgets(ligne_lue, 500, pFile) != NULL){
if(ligne==0){
fscanf(pFile,"Orientation : %d",GrapheCharge.orient);
}
if(ligne==1 && GrapheCharge.orient==0){
fscanf(pFile, "%c %c %c %c %c %c %c %c %c %c", GrapheCharge.nomsom[0],GrapheCharge.nomsom[1],GrapheCharge.nomsom[2],GrapheCharge.nomsom[3],GrapheCharge.nomsom[4],GrapheCharge.nomsom[5],GrapheCharge.nomsom[6],GrapheCharge.nomsom[7],GrapheCharge.nomsom[8],GrapheCharge.nomsom[9]);
for(i=0;i<10;i++){
if(GrapheCharge.nomsom[i]!=0){
GrapheCharge.nbrsom++;
}
}
ligne++;
}
//Après avoir déterminé si le graphe est orienté (1) ou non (0) ainsi que le nom et nombre de sommets, on lance les autres fonction pour determiner matrice et liste d'adjacence.
if(GrapheCharge.orient==0 && ligne!=0 && ligne!=1){
fscanf(pFile, "%c %c",matadj1,matadj2);
MatriceAdj(&matadj1,&matadj2,GrapheCharge);
}
}
}else{
printf("Impossible d'ouvrir le fichier %s\n", chemin);
exit(1);
}
}
//Cette fonction génère la matrice d'adjacence.
void MatriceAdj(char *matadj1,char *matadj2,Graphe GrapheCharge){
int l,c;
if(matadj1=="A"){l = 0;}
if(matadj1=="B"){l = 1;}
if(matadj1=="C"){l = 2;}
if(matadj1=="D"){l = 3;}
if(matadj1=="E"){l = 4;}
if(matadj1=="F"){l = 5;}
if(matadj1=="G"){l = 6;}
if(matadj1=="H"){l = 7;}
if(matadj1=="I"){l = 8;}
if(matadj1=="J"){l = 9;}
if(matadj2=="A"){c = 0;}
if(matadj2=="B"){c = 1;}
if(matadj2=="C"){c = 2;}
if(matadj2=="D"){c = 3;}
if(matadj2=="E"){c = 4;}
if(matadj2=="F"){c = 5;}
if(matadj2=="G"){c = 6;}
if(matadj2=="H"){c = 7;}
if(matadj2=="I"){c = 8;}
if(matadj2=="J"){c = 9;}
if(GrapheCharge.orient=0){
GrapheCharge.matadj[l][c]=1;
GrapheCharge.matadj[c][l]=1;
}else{
GrapheCharge.matadj[l][c]=1;
}
}
void ListeAdj(char *matadj1,char *matadj2,Graphe GrapheCharge){
int l,c;
if(matadj1=="A"){l = 0;}
if(matadj1=="B"){l = 1;}
if(matadj1=="C"){l = 2;}
if(matadj1=="D"){l = 3;}
if(matadj1=="E"){l = 4;}
if(matadj1=="F"){l = 5;}
if(matadj1=="G"){l = 6;}
if(matadj1=="H"){l = 7;}
if(matadj1=="I"){l = 8;}
if(matadj1=="J"){l = 9;}
while(GrapheCharge.listeadj[l][c]!=0){
c++;
}
GrapheCharge.listeadj[l][c]=*matadj2;
}
//Cette fonction détermine si le graphe est connexe
void Connexe(Graphe GrapheCharge){
int l,c;
}
//Initialisation du programme
int main(int argc, char *argv[]){
Graphe GrapheCharge;
char chemin[50];
printf("Bienvenue dans l'algorithme de manipulation des graphes.\nVeuillez entrer un chemin de fichier texte (Absolu) : ");
scanf ("%s",&chemin);
InitGraph(GrapheCharge);
ChargerGraphe(chemin,GrapheCharge);
return 0;
} |
Partager