about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/get_best_order.c
diff options
context:
space:
mode:
authorziejd22017-09-14 15:39:41 -0500
committerziejd22017-09-14 15:57:50 -0500
commitc4f926438dcb8abe805e910399940f79ff643c4b (patch)
tree3146d05ada5cf4b48d9bdd16c1baa498e8df7192 /sourcecodes/k-best/src/get_best_order.c
parent57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff)
downloadBNW-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.c54
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;
+}