chiark / gitweb /
break out preconsider_ok
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 8 Mar 2014 17:31:36 +0000 (17:31 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 8 Mar 2014 17:31:36 +0000 (17:31 +0000)
main.c

diff --git a/main.c b/main.c
index 4ec493586c5a65806188c8fe9f26ec9ddfce25b2..f9402cfeac8965dfe11f79ed5c167442b2d31896 100644 (file)
--- a/main.c
+++ b/main.c
@@ -112,33 +112,17 @@ static int count_set_adj_bits(AdjWord w) {
   return total;
 }
 
-static void optimise(int doprint) {
-  /* Consider the best answer (if any) for a given adjacency matrix */
-  glp_prob *prob = 0;
-  int i, j, totalfrags;
+#define PRINTF(...) if (!doprint) ; else fprintf(stderr, __VA_ARGS__)
 
-  /*
-   * Up to a certain point, optimise() can be restarted.  We use this
-   * to go back and print the debugging output if it turns out that we
-   * have an interesting case.  The HAVE_PRINTED macro does this: its
-   * semantics are to go back in time and make sure that we have
-   * printed the description of the search case.
-   */
-#define HAVE_PRINTED ({                                                \
-      if (!doprint) { doprint = 1; goto retry_with_print; }    \
-    })
- retry_with_print:
-  if (prob) {
-    glp_delete_prob(prob);
-    prob = 0;
-  }
+static int totalfrags;
 
-#define PRINTF(...) if (!doprint) ; else fprintf(stderr, __VA_ARGS__)
+static bool preconsider_ok(int nwords, bool doprint) {
+  int i;
 
   PRINTF("%2d ", maxhamweight);
 
   bool had_max = 0;
-  for (i=0, totalfrags=0; i<n; i++) {
+  for (i=0, totalfrags=0; i<nwords; i++) {
     int frags = count_set_adj_bits(adjmatrix[i]);
     had_max += (frags == maxhamweight);
     totalfrags += frags;
@@ -157,6 +141,36 @@ static void optimise(int doprint) {
     PRINTF(" nomaxham");
     goto out;
   }
+  return 1;
+
+ out:
+  return 0;
+}
+
+static void optimise(bool doprint) {
+  /* Consider the best answer (if any) for a given adjacency matrix */
+  glp_prob *prob = 0;
+  int i, j;
+
+  /*
+   * Up to a certain point, optimise() can be restarted.  We use this
+   * to go back and print the debugging output if it turns out that we
+   * have an interesting case.  The HAVE_PRINTED macro does this: its
+   * semantics are to go back in time and make sure that we have
+   * printed the description of the search case.
+   */
+#define HAVE_PRINTED ({                                                \
+      if (!doprint) { doprint = 1; goto retry_with_print; }    \
+    })
+ retry_with_print:
+  if (prob) {
+    glp_delete_prob(prob);
+    prob = 0;
+  }
+
+  bool ok = preconsider_ok(n, doprint);
+  if (!ok)
+    goto out;
 
   /*
    * We formulate our problem as an LP problem as follows.