diff options
| author | ziejd2 | 2017-09-14 15:39:41 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-14 15:57:50 -0500 |
| commit | c4f926438dcb8abe805e910399940f79ff643c4b (patch) | |
| tree | 3146d05ada5cf4b48d9bdd16c1baa498e8df7192 /sourcecodes/k-best/src/get_best_order.c | |
| parent | 57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff) | |
| download | BNW-c4f926438dcb8abe805e910399940f79ff643c4b.tar.gz | |
Add files via upload
Diffstat (limited to 'sourcecodes/k-best/src/get_best_order.c')
| -rw-r--r-- | sourcecodes/k-best/src/get_best_order.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sourcecodes/k-best/src/get_best_order.c b/sourcecodes/k-best/src/get_best_order.c new file mode 100644 index 00000000..232956aa --- /dev/null +++ b/sourcecodes/k-best/src/get_best_order.c @@ -0,0 +1,54 @@ +#include "cfg.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +void get_best_order(int nof_vars, char* sinkfile, char* ord) +{ + FILE* sinkf = fopen(sinkfile, "rb"); + varset_t set = LARGEST_SET(nof_vars); + // printf("\n\n\nset = %u",set); + int i; + for(i=nof_vars-1; i>=0;--i){ + char sink; + // printf("\n\n\n\nset =%u",set); + fseek(sinkf, set, SEEK_SET); + + fread(&sink, sizeof(char), 1, sinkf); +// printf(" sink = %d",sink); + ord[i] = sink; + + set ^= 1U<<sink; + // printf(" new set = %u",set); + } + fclose(sinkf); +} + + +int main(int argc, char* argv[]) +{ + + if (argc!=4) { + fprintf(stderr, "Usage: get_best_net nof_vars sinkfile ordfile\n"); + return 1; + } + + { + int nof_vars = atoi(argv[1]); + char* ord = malloc(nof_vars*sizeof(char)); + + get_best_order(nof_vars, argv[2], ord); + + { + FILE* ordf = fopen(argv[3], "w"); + int i; + for(i=0;i<nof_vars;++i){ + fprintf(ordf, "%d%c", ord[i], i==nof_vars-1 ? '\n' : ' '); + } + fclose(ordf); + } + } + + return 0; +} |
