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
|
/**Fonction qui construit le graphe en mémoire**/
T_sommet **Construction_Graphe(T_sommet **Graphe, int *ordre){
FILE *fichier_graphe;
T_sommet *temp = NULL;
double vitesse_temp;
int nb_succ = 0;
int i, j;
fichier_graphe = fopen(".\\graphe.txt", "r");
if (fichier_graphe == NULL) printf("Probleme d'ouverture fichier");
else{
fscanf(fichier_graphe, "%d", ordre);
printf("ordre = %d\n", *ordre);
Graphe = (T_sommet**)malloc(sizeof(T_sommet*));
for(i=0 ; i<(*ordre) ; i++){
printf("sommet %d\n", i);
Graphe[i] = (T_sommet*)malloc(sizeof(T_sommet));
Graphe[i] = NULL;
fscanf(fichier_graphe, "%d", &nb_succ);
printf("nb_succ = %d\n", nb_succ);
if(nb_succ != 0){
for(j=0 ; j<nb_succ ; j++){
temp = (T_sommet*)malloc(sizeof(T_sommet));
fscanf(fichier_graphe, "%d %d %d", &(temp->id), &(temp->distance), &(temp->vitessemax));
vitesse_temp = Conversion_kmh_ms(temp->vitessemax); //On convertit les km/h en m/s avec 2 chiffres après la virgule
temp->temps = Tronquer_Centieme((temp->distance)/vitesse_temp);
temp->vitesse = temp->vitessemax;
temp->densitemax = ((temp->distance)/(((temp->vitessemax)/10)+2));
temp->densite = 0;
printf("id = %d, dist = %dm, vit = %lfm/s, tmps = %lfs, densmx = %d\n", (temp->id), (temp->distance), vitesse_temp, (temp->temps), (temp->densitemax));
Graphe[i] = Ajouter_Sommet(Graphe[i], temp);
}
}
}
fclose(fichier_graphe);
return Graphe;
}
} |
Partager