about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/get_best_sinks.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_sinks.c
parent57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff)
downloadBNW-c4f926438dcb8abe805e910399940f79ff643c4b.tar.gz
Add files via upload
Diffstat (limited to 'sourcecodes/k-best/src/get_best_sinks.c')
-rw-r--r--sourcecodes/k-best/src/get_best_sinks.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/sourcecodes/k-best/src/get_best_sinks.c b/sourcecodes/k-best/src/get_best_sinks.c
new file mode 100644
index 00000000..4d83d217
--- /dev/null
+++ b/sourcecodes/k-best/src/get_best_sinks.c
@@ -0,0 +1,78 @@
+#include "cfg.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "files.h"
+
+void get_best_sinks(int nof_vars, FILE** files, char* sinkfile)
+{
+
+  FILE* sinkf        = fopen(sinkfile, "wb");
+FILE *fp = fopen("/home/grad/lram/RA stuff/check/src/sinks.txt","w");
+  
+score_t* scores    = malloc((1U<<nof_vars) * sizeof(score_t));
+  score_t best_score = 0.0;
+
+  varset_t varset;
+  for(varset=0; varset < (1U<<nof_vars); ++varset){
+//    printf("\n\n\nVarset %u",varset);
+    int sink;
+    char best_sink = -1;
+
+    for(sink=0; sink<nof_vars; ++sink){ /* could use ffs */
+  //    printf("\nTry Sink %d",sink);
+      varset_t sinkleton = 1U<<sink;
+
+      if (varset & sinkleton) {
+//printf("  True!!");
+	score_t new_score = scores[varset & ~sinkleton];
+
+//printf("New score = %f + ",new_score);
+//printf("Scores[ %d ] +",varset & ~sinkleton);
+
+	score_t par_score;
+	fread(&par_score, sizeof(score_t), 1, files[sink]);
+//printf(" New score + %f",par_score);
+//printf(" Score is [%d .bss,???] ",sink);
+	new_score += par_score;
+	if (best_sink == -1 || best_score < new_score){
+//printf("This is better than previous");
+	  best_score = new_score;
+	  best_sink  = sink;
+
+	}
+      }
+    }
+    
+    scores[varset] = best_score;
+
+    fwrite(&best_sink, sizeof(char), 1, sinkf);
+
+fprintf(fp,"Best score: %f",best_score);
+fprintf(fp,"Best sink: %d", best_sink);
+  }
+
+  free(scores);
+  fclose(sinkf);
+}
+
+
+int main(int argc, char* argv[])
+{
+
+  if (argc!=4) {
+    fprintf(stderr, "Usage: get_best_net nof_vars dirname sinkfile\n");
+    return 1;
+  }
+  
+  {
+    int nof_vars = atoi(argv[1]);
+    FILE** files = open_files(nof_vars, argv[2],".bss", "rb");
+    get_best_sinks(nof_vars, files, argv[3]);
+    free_files(nof_vars, files);
+  }
+  
+  return 0;
+}