Beispiel #1
0
void cree_graphe_non_oriente_value(char* nom_fich, int nbs, int nba)
/* format du fichier :
   nbsommets nbaretes
   aretes sous forme de triplets origine extremité valuation                 */ {
    FILE *fich;
    GRAPH g;
    int ori, ext;
    float val;
    int iare;

    fich = fopen(nom_fich, "wt");

    fprintf(fich, "%d %d\n", nbs, nba);

    init_graphe(nbs, nba, &g);

    /* génération d'aretes aléatoires */
    for (iare = 1; iare <= nba; iare++) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
        } while ((ori == ext) || (g.matrix[ori][ext]));
        /* pour interdire les boucles et ne pas générer 2 fois la meme arete */

        do val = (rand() % (int) (10 * MAXVALUATION)) / 10.; while (val == 0.0);
        /* pour n'avoir qu'une décimale */
        g.matrix[ori][ext] = g.matrix[ext][ori] = val;
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    fclose(fich);
}
Beispiel #2
0
void cree_graphe_oriente_non_value(char* nom_fich, int nbs, int nba)
/* format du fichier :
   nbsommets nbarcs
   aretes sous forme de triplets origine extremité                           */ {
    FILE *fich;
    GRAPH g;
    int ori, ext;
    int iarc;

    fich = fopen(nom_fich, "wt");

    fprintf(fich, "%d %d\n", nbs, nba);

    init_graphe(nbs, nba, &g);

    /* génération d'arcs aléatoires */
    for (iarc = 1; iarc <= nba; iarc++) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
        } while (g.matrix[ori][ext]);
        /* pour ne pas générer 2 fois le meme arc */

        g.matrix[ori][ext] = 1;
        fprintf(fich, "%d %d\n", ori, ext);
    }

    fclose(fich);
}
Beispiel #3
0
/* format du fichier : 
nbsommets nbaretes
aretes sous forme de triplets origine extremité                           */
void cree_graphe_non_oriente_non_value(char *nom_fich, int nbs, int nba)
{ 
	FILE *fich; 
	graphe g;
	int ori, ext;
	int iare;

	fich = fopen(nom_fich,"w");

	fprintf(fich,"%d %d\n",nbs,nba);

	init_graphe(nbs,nba,&g);    

	for (iare = 1; iare <= nba ; iare++)
	{
		do 
		{
			ori = random()%nbs;
			ext = random()%nbs;
		} while ((ori == ext)||(g.matrice[ori][ext]));

		g.matrice[ori][ext] = g.matrice[ext][ori] = 1;
		fprintf(fich,"%d %d\n",ori,ext);
	} 

	fclose(fich);
}   
Beispiel #4
0
void cree_graphe_connexe_value(char* nom_fich, int nbs, int nba)
/* format du fichier :
   nbsommets nbaretes
   aretes sous forme de triplets origine extremité                           */ {
    FILE *fich;
    GRAPH g;
    t_ens e;
    int ori, ext;
    int i, rori, rext;
    float val;

    fich = fopen(nom_fich, "wt");

    fprintf(fich, "%d %d\n", nbs, nba);

    init_graphe(nbs, nba, &g);
    init_ens(nbs, &e);

    /* génération aléatoire de nbs-1 aretes pour assurer la connexité du graphe */
    while (e.nbClass > 1) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
            rori = trouver(ori, &e);
            rext = trouver(ext, &e);
        } while ((ori == ext) || (g.matrix[ori][ext]) || (rori == rext));
        /* pour interdire les boucles et ne pas générer 2 fois la meme arete */

        do {
            val = (rand() % (int) (10 * MAXVALUATION)) / 10.;
        } while (val == 0.0);
        /* pour n'avoir qu'une décimale */
        g.matrix[ori][ext] = g.matrix[ext][ori] = val;
        reunir(rori, rext, &e);
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    /* on complète à nba avec des aretes aléatoires */
    for (i = nbs; i <= nba; i++) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
        } while ((ori == ext) || (g.matrix[ori][ext]));
        /* pour interdire les boucles et ne pas générer 2 fois la meme arete */

        do {
            val = (rand() % (int) (10 * MAXVALUATION)) / 10.;
        } while (val == 0.0);
        /* pour n'avoir qu'une décimale */
        g.matrix[ori][ext] = g.matrix[ext][ori] = val;
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    fclose(fich);
}
Beispiel #5
0
int main()
{
    printf("*** Algorithme de Ford-Fulkerson ***\n");
    printf("Ouverture du fichier contenant la matrice\n");

    graphe g = init_graphe();
    int flot = fordFulkerson(g);

    printf("Le flot maximum est : %d\n",flot);

    return 0;
}
Beispiel #6
0
graphe fich2Graf (char* fichier){
	graphe g;
	int nbA, nbS, i,ori, ext;


	FILE* f = fopen(fichier,"r");
	if(f==NULL){
		printf("Erreur : mauvais fichier.");
		init_graphe(0,0,&g);
	}else{
		fscanf(f,"%d %d",&nbS,&nbA);

		init_graphe(nbS,nbA,&g);

		for(i=0; i <= nbA; i++){
			fscanf(f,"%d %d", &ori, &ext);

			g.matrice[ori][ext] = g.matrice[ext][ori] = 1;
		}
		fclose(f);
	}
	return g;
}
Beispiel #7
0
void cree_graphe_topo_value(char* nom_fich, int nbs, int nba)
/* format du fichier :
   nbsommets nbarcs
   arcs sous forme de triplets origine extremité valuation                  */ {
    FILE *fich;
    GRAPH g;
    int ori, ext;
    float val;
    int iarc;

    fich = fopen(nom_fich, "wt");

    fprintf(fich, "%d %d\n", nbs, nba);

    init_graphe(nbs, nba, &g);

    /* on s'assure d'abord d'avoir au moins un arc bien orienté
       du type origine -> origine+1 */

    for (iarc = 0; iarc < nbs - 1; iarc++) {
        ori = iarc;
        ext = iarc + 1;
        do val = (rand() % (int) (10 * MAXVALUATION)) / 10.; while (val == 0.0);
        /* pour n'avoir qu'une décimale */

        g.matrix[ori][ext] = val;
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    /* ensuite, on complète avec des arcs aléatoires */
    for (iarc = nbs; iarc <= nba; iarc++) {
        do {
            ori = rand() % nbs;
            ext = rand() % nbs;
        } while ((ori == 0) || (ori == nbs - 1)
                || (ext <= ori) /* pour assurer la "bonne" orientation des arcs */
                || (g.matrix[ori][ext]));
        /* pour ne pas générer 2 fois le meme arc */

        do val = (rand() % (int) (10 * MAXVALUATION)) / 10.; while (val == 0.0);
        /* pour n'avoir qu'une décimale */

        g.matrix[ori][ext] = val;
        fprintf(fich, "%d %d %5.1f\n", ori, ext, val);
    }

    fclose(fich);
}