diff --git a/generator.c b/generator.c index c4176b6..1800402 100644 --- a/generator.c +++ b/generator.c @@ -7,6 +7,7 @@ #include "common.h" #include +#include static const char *pname; @@ -105,9 +106,9 @@ void parse(int argc, char *argv[]) str = orig_copy = strdup(edge); int count = 0; while ((token = strsep(&str, "-"))) { - if (str == NULL) { + if (strcmp(token, edge) == 0 && str == NULL) { fprintf(stderr, "[%s] An edge consists of two " - "nodes separated by a dash\n", pname); + "nodes separated by a dash\n", pname); free(orig_copy); return; } @@ -190,6 +191,23 @@ void cleanup() free(graph.array); } +void genSolution(int permutation[]) +{ + int r; + + for (int i = 0; i < graph.V; i++) { + permutation[i] = i; + } + + for (int i = (graph.V - 1); i > 0; i--) { + r = rand() % (i+1); + int tmp = permutation[r]; + permutation[r] = permutation[i]; + permutation[i] = tmp; + } + +} + int main(int argc, char *argv[]) { if (argc == 1) @@ -225,9 +243,20 @@ int main(int argc, char *argv[]) */ parse(argc, argv); + + srand(time(NULL)); + + int permutation[graph.V]; while (quit == 0) { - printGraph(); + for (int i = 0; i < 10; i++) { + genSolution(permutation); + printf("["); + for (int i = 0; i < (graph.V - 1); i++) { + printf("%d, ", permutation[i]); + } + printf("%d]\n", permutation[graph.V-1]); + } break; }