about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/get_best_net.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_net.c
parent57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff)
downloadBNW-c4f926438dcb8abe805e910399940f79ff643c4b.tar.gz
Add files via upload
Diffstat (limited to 'sourcecodes/k-best/src/get_best_net.c')
-rw-r--r--sourcecodes/k-best/src/get_best_net.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/sourcecodes/k-best/src/get_best_net.c b/sourcecodes/k-best/src/get_best_net.c
new file mode 100644
index 00000000..5ed6ebfb
--- /dev/null
+++ b/sourcecodes/k-best/src/get_best_net.c
@@ -0,0 +1,63 @@
+#include "cfg.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "files.h"
+#include "varpar.h"
+
+void get_best_net(int nof_vars, char* ordfile, FILE** bpsfiles, varset_t* net)
+{
+  FILE* ordf = fopen(ordfile,"r");
+  varset_t parcands = 0;
+  int i;
+  for(i=0;i<nof_vars; ++i){
+    varset_t parset;
+    int v;
+//    printf("Parcands = %u",parcands);
+
+    fscanf(ordf, "%d", &v);
+  //  printf("  v= %d",v);
+    fseek(bpsfiles[v], varset2parset(v,parcands)*sizeof(varset_t), SEEK_SET);
+    fread(&parset, sizeof(varset_t), 1, bpsfiles[v]);
+   // printf("Parset =%u ",parset);
+    parcands |= 1U<<v;
+   // printf("Parcands = %u",parcands);
+    net[v] = parset2varset(v, parset);
+   // printf("net %d = %u",v,net[v]);
+  }
+  fclose(ordf);
+}
+
+
+int main(int argc, char* argv[])
+{
+
+  if (argc!=5) {
+    fprintf(stderr, "Usage: get_best_net nof_vars dirname ordfile netfile\n");
+    return 1;
+  }
+  
+  {
+    int nof_vars = atoi(argv[1]);
+
+    varset_t* net    = malloc(nof_vars*sizeof(varset_t));
+    FILE** files = open_files(nof_vars, argv[2],".bps", "rb");
+    get_best_net(nof_vars, argv[3], files, net);
+    free_files(nof_vars, files);
+
+    {
+      FILE* netf = fopen(argv[4],"w");
+      int i;
+      for (i=0;i<nof_vars;++i){
+	fprintf(netf, "%u\n", net[i]);
+      }
+      fclose(netf);
+    }
+
+    free(net);
+  }
+    
+  return 0;
+}