chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 Mar 2014 13:22:08 +0000 (13:22 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 Mar 2014 13:22:08 +0000 (13:22 +0000)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
main.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b25c15b
--- /dev/null
@@ -0,0 +1 @@
+*~
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..af97bd2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+CFLAGS += -Wall -Wwrite-strings -Wstrict-prototypes
+LC_CTYPE=C
+
+all: main
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..0c694c8
--- /dev/null
+++ b/main.c
@@ -0,0 +1,58 @@
+
+typedef uint32_t AdjWord;
+#define PRADJ PRIx32
+
+static int n, m;
+static AdjWord adjmatrix[n];
+static AdjWord adjall;
+
+static double best;
+static AdjWord adjmatrix_best[n];
+
+static void prep(void) {
+  adjall = ~((~(AdjWord)0) << m);
+}
+
+static int count_set_adj_bits(AdjWord w) {
+  for (int j=0, total=0; j<m; j++)
+    total += !!(w & ((AdjWord)1 << j));
+  return total;
+}
+
+static void optimise(void) {
+  for (i=0; i<n; i++) {
+    printf("%"PRADJ" ", adjmatrix[i]);
+    double maxminsize = (double)m / count_set_adj_bits(adjmatrix[i]);
+    if (maxminsize < best) {
+      printf(" too fine\n");
+      return;
+    }
+  }
+
+  printf("nyi\n");
+}
+
+static void iterate_recurse(int i, AdjWord min) {
+  if (i > n) {
+    optimise();
+    return;
+  }
+  for (adjmatrix[i] = min;
+       ;
+       adjmatrix[i]++) {
+    iterate_recurse(i+1, adjmatrix[i]);
+  }
+}
+
+static void iterate(void) {
+  iterate_recurse(0, 1);
+}
+
+int main(int argc, char **argv) {
+  n = atoi(argv[1]);
+  m = atoi(argv[2]);
+  prep();
+  iterate();
+  if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); }
+  return 0;
+}