9 typedef uint32_t AdjWord;
10 #define PRADJ "08"PRIx32
13 static AdjWord *adjmatrix;
14 static AdjWord adjall;
18 static void prep(void) {
19 adjall = ~((~(AdjWord)0) << m);
20 adjmatrix = xmalloc(sizeof(*adjmatrix)*n);
23 static int count_set_adj_bits(AdjWord w) {
25 for (j=0, total=0; j<m; j++)
26 total += !!(w & ((AdjWord)1 << j));
30 static void optimise(void) {
33 printf("%"PRADJ" ", adjmatrix[i]);
34 double maxminsize = (double)m / count_set_adj_bits(adjmatrix[i]);
35 if (maxminsize < best) {
36 printf(" too fine\n");
42 * We formulate our problem as an LP problem as follows.
43 * In this file "n" and "m" are the matchstick numbers.
45 * Each set bit in the adjacency matrix corresponds to taking a
46 * fragment from old match i and making it part of new match j.
48 * The structural variables (columns) are:
49 * x_fragsz_i_j the size of that fragment
50 * x_minimum minimum size of any fragment
52 * The auxiliary variables (rows, constraints) are:
53 * x_total_i total length for each input match (fixed variable)
54 * x_total_j total length for each output match (fixed variable)
55 * x_fragmin_i_j amount by which fragment is > minimum (lower bound 0)
57 * The objective function is simply to maximise x_minimum
63 static void iterate_recurse(int i, AdjWord min) {
68 for (adjmatrix[i] = min;
71 iterate_recurse(i+1, adjmatrix[i]);
72 if (adjmatrix[i] == adjall)
77 static void iterate(void) {
78 iterate_recurse(0, 1);
81 int main(int argc, char **argv) {
86 if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); }