diff --git a/graphe.csv b/graphe.csv index 3278bc97f86fd0756a6db763f3c80f5273be278a..3e4e0d2ce360dff13cebe646b1bc739bf05c53a8 100644 --- a/graphe.csv +++ b/graphe.csv @@ -1,15 +1,15 @@ 8 0 7 0 1 2.0 1 2 5.0 -2 1 1.0 +2 1 5.0 1 3 2.0 3 1 1.0 1 5 2.0 2 3 1.0 -2 6 1.0 +2 6 4.0 3 4 4.0 3 5 2.0 3 6 3.0 -3 7 1.0 +3 7 4.0 4 7 2.0 6 7 2.0 diff --git a/graphe/graphe.c b/graphe/graphe.c index 04506eb151de44af3fb917350210401bf8d69625..0a9648a5d7d04604bd60a7964c9691055cbcfb3e 100644 --- a/graphe/graphe.c +++ b/graphe/graphe.c @@ -1,5 +1,4 @@ #include "graphe.h" -#define RHO 0.01 graph create_graph(int num, int fourmiliere, int nourriture) { graph gr = malloc(sizeof(g)); @@ -284,6 +283,7 @@ void export_shortest_path(graph g1, char *filename) while (!stack_is_empty(*eclaireuse->path)) { + //afficher le chemin dans le fichier de sortie stack_pop(eclaireuse->path, &trash); fprintf(file, "[%d]", eclaireuse->path->data[ecrit_chemin]); ecrit_chemin++; diff --git a/le_plus_court_chemin.txt b/le_plus_court_chemin.txt index 14ae4e3d4fbf1eb2e6325f0419ba2000de7b8c68..8071ff10caef46d5cc988511d709e95a97b8fb11 100644 --- a/le_plus_court_chemin.txt +++ b/le_plus_court_chemin.txt @@ -1 +1 @@ -the shortest path is [0][1][3][7] with a cost of 5 +the shortest path is [0][1][3][7] with a cost of 8 diff --git a/main.c b/main.c index 2a18b6aba132f1e326e867c985aed86f30e64ba3..1907f1a39f613dff45bd8b6bed4537c0e363f5c6 100644 --- a/main.c +++ b/main.c @@ -5,10 +5,23 @@ int main() //initialisation srand(time(NULL)); int nb_fourmi_perdu = 0; + double rho = 0; + int nb_fourmi = 0; //création du graphe à partir d'un csv graph g1 = main_create_graph("graphe.csv"); + printf("number of ants : "); + scanf("%d", &nb_fourmi); + printf("rate of evaporation [rate < 1 and rate > 0] : "); + scanf("%lf", &rho); + + while(rho >= 1 || rho <= 0) + { + printf("[rate < 1 and rate > 0] : "); + scanf("%lf", &rho); + } + //lancement de la colonisation des fourmis - nb_fourmi_perdu = launch_colonization(g1, 100000, 0.001); + nb_fourmi_perdu = launch_colonization(g1, nb_fourmi, rho); //impression de la matrice des phéromones et des arêtes printf("\n length path matrix \n"); diff --git a/test2.dot b/test2.dot index 3883cbf071052c8cf549746a72c2ba563692263f..b55299990ce95960973609700cb1cdf4be876ac9 100644 --- a/test2.dot +++ b/test2.dot @@ -3,14 +3,14 @@ digraph Test { 1->2[penwidth=2, label= 5.000000] 1->3[penwidth=2, label= 2.000000] 1->5[penwidth=2, label= 2.000000] -2->1[penwidth=2, label= 1.000000] +2->1[penwidth=2, label= 5.000000] 2->3[penwidth=2, label= 1.000000] -2->6[penwidth=2, label= 1.000000] +2->6[penwidth=2, label= 4.000000] 3->1[penwidth=2, label= 1.000000] 3->4[penwidth=2, label= 4.000000] 3->5[penwidth=2, label= 2.000000] 3->6[penwidth=2, label= 3.000000] -3->7[penwidth=2, label= 1.000000] +3->7[penwidth=2, label= 4.000000] 4->7[penwidth=2, label= 2.000000] 6->7[penwidth=2, label= 2.000000] } \ No newline at end of file diff --git a/test2.dot.png b/test2.dot.png index b5281d2b0711f689167e95ace32c8effbb814986..0f3bd97af945318467c84b10d6e3a863bf6f41b2 100644 Binary files a/test2.dot.png and b/test2.dot.png differ diff --git a/tp_fourmi b/tp_fourmi index a256ec5d48575123f4602c362955ff8dcf26c6f7..d17ce93c5315f4c3094f59e6faf87ceec5994e74 100755 Binary files a/tp_fourmi and b/tp_fourmi differ