diff options
author | Alexandre Jesus <adbjesus@gmail.com> | 2016-11-02 21:39:39 +0000 |
---|---|---|
committer | Alexandre Jesus <adbjesus@gmail.com> | 2016-11-02 21:39:39 +0000 |
commit | 3333e0c5a1a8e39c74fb178ac124940844463520 (patch) | |
tree | e9ef4744df6068e4662921a18ce2edcc4c1ef30e | |
parent | ada2511a52067ff1fd006993831279faba79241f (diff) | |
download | libuknapsack-3333e0c5a1a8e39c74fb178ac124940844463520.tar.gz libuknapsack-3333e0c5a1a8e39c74fb178ac124940844463520.zip |
Also update random generator on online
-rw-r--r-- | src/main/online.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main/online.c b/src/main/online.c index fb400ef..fbec660 100644 --- a/src/main/online.c +++ b/src/main/online.c @@ -2,6 +2,7 @@ #include <time.h> #include <stdlib.h> #include <string.h> +#include <sys/time.h> #include "common.h" #include "structs.h" #include "dfs.h" @@ -22,7 +23,10 @@ int main(int argc, char * argv[]){ data = input(argv[5]); /* Sort data */ - srand(time(NULL)); + struct timeval tv; + gettimeofday(&tv, NULL); + srand(tv.tv_sec + tv.tv_usec); + if(strcmp(argv[3], "random") == 0) { qsort(data->items, data->N, sizeof(struct item), cmp_items_random); } else if(strcmp(argv[3], "ratio") == 0) { @@ -39,7 +43,7 @@ int main(int argc, char * argv[]){ } /* Run algorithm2, if it hasn't finished yet*/ - if(ret.tree!=NULL){ + if(ret.tree != NULL && ret.front != NULL){ if(strcmp(argv[2], "dfs") == 0) { ret = dfs_online(data, ret.front, ret.tree, 100); } else if(strcmp(argv[2], "random_heuristic") == 0) { |