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;
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.