chiark
/
gitweb
/
~ianmdlvl
/
matchsticks-search.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Check max Hamming weight in the other direction.
[matchsticks-search.git]
/
main.c
diff --git
a/main.c
b/main.c
index 6f0df725949c9b26fccb613768f74c283bc9e591..3c1b123b2e71155b058bdc34d45f058f6db592f9 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-86,6
+86,9
@@
static double best;
static glp_prob *best_prob;
static AdjWord *best_adjmatrix;
static glp_prob *best_prob;
static AdjWord *best_adjmatrix;
+static int n_over_best;
+static int *weight;
+
static unsigned printcounter;
static AdjWord *xalloc_adjmatrix(void) {
static unsigned printcounter;
static AdjWord *xalloc_adjmatrix(void) {
@@
-96,6
+99,9
@@
static void prep(void) {
adjall = ~((~(AdjWord)0) << m);
adjmatrix = xalloc_adjmatrix();
glp_term_out(GLP_OFF);
adjall = ~((~(AdjWord)0) << m);
adjmatrix = xalloc_adjmatrix();
glp_term_out(GLP_OFF);
+ n_over_best = n / best;
+ weight = (int *)malloc(m*sizeof(int));
+ for (int j = 0; j < m; j++) weight[j] = 0;
}
static AdjWord one_adj_bit(int bitnum) {
}
static AdjWord one_adj_bit(int bitnum) {
@@
-300,6
+306,7
@@
static void optimise(int doprint) {
HAVE_PRINTED;
best = got;
HAVE_PRINTED;
best = got;
+ n_over_best = n / best;
if (best_prob) glp_delete_prob(best_prob);
best_prob = prob;
if (best_prob) glp_delete_prob(best_prob);
best_prob = prob;
@@
-331,9
+338,20
@@
static void iterate_recurse(int i, AdjWord min) {
goto again;
if (i == 0 && (adjmatrix[i] & (1+adjmatrix[i])))
goto again;
goto again;
if (i == 0 && (adjmatrix[i] & (1+adjmatrix[i])))
goto again;
+ for (int j = 0; j < m; j++)
+ if (adjmatrix[i] & (1 << j))
+ weight[j]++;
+ for (int j = 0; j < m; j++)
+ if (weight[j] >= n_over_best)
+ goto takeout;
iterate_recurse(i+1, adjmatrix[i]);
iterate_recurse(i+1, adjmatrix[i]);
+ takeout:
+ for (int j = 0; j < m; j++)
+ if (adjmatrix[i] & (1 << j))
+ weight[j]--;
+
again:
if (adjmatrix[i] == adjall)
return;
again:
if (adjmatrix[i] == adjall)
return;