chiark / gitweb /
93dc7ebe5325269db8fda05f5fe954a081489ed3
[matchsticks-search.git] / main.c
1 /*
2  * Searches for "good" ways to divide n matchsticks up and reassemble them
3  * into m matchsticks.  "Good" means the smallest fragment is as big
4  * as possible.
5  *
6  * Invoke as   ./main n m
7  *
8  * The algorithm is faster if the arguments are ordered so that n > m.
9  */
10
11 /*
12  * matchsticks/main.c  Copyright 2014 Ian Jackson
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  */
24
25 #define _GNU_SOURCE
26
27 #include <publib.h>
28
29 #include <stdio.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <assert.h>
34 #include <unistd.h>
35 #include <stdbool.h>
36 #include <inttypes.h>
37 #include <math.h>
38 #include <sys/types.h>
39 #include <sys/wait.h>
40 #include <sys/uio.h>
41 #include <sys/fcntl.h>
42
43 #include <glpk.h>
44
45 #ifndef VERSION
46 #define VERSION "(unknown-version)"
47 #endif
48
49 /*
50  * Algorithm.
51  *
52  * Each input match contributes, or does not contribute, to each
53  * output match; we do not need to consider multiple fragments
54  * relating to the same input/output pair this gives an n*m adjacency
55  * matrix (bitmap).  Given such an adjacency matrix, the problem of
56  * finding the best sizes for the fragments can be expressed as a
57  * linear programming problem.
58  *
59  * We search all possible adjacency matrices, and for each one we run
60  * GLPK's simplex solver.  We represent the adjacency matrix as an
61  * array of bitmaps: one word per input stick, with one bit per output
62  * stick.
63  *
64  * However, there are a couple of wrinkles:
65  *
66  * To best represent the problem as a standard LP problem, we separate
67  * out the size of each fragment into a common minimum size variable,
68  * plus a fragment-specific extra size variable.  This reduces the LP
69  * problem size at the cost of making the problem construction, and
70  * interpretation of the results, a bit fiddly.
71  *
72  * Many of the adjacency matrices are equivalent.  In particular,
73  * permutations of the columns, or of the rows, do not change the
74  * meaning.  It is only necessasry to consider any one permutation.
75  * We make use of this by considering only adjacency matrices whose
76  * bitmap array contains bitmap words whose numerical values are
77  * nondecreasing in array order.
78  *
79  * Once we have a solution, we also avoid considering any candidate
80  * which involves dividing one of the input sticks into so many
81  * fragment that the smallest fragment would necessarily be no bigger
82  * than our best solution.  That is, we reject candidates where any of
83  * the hamming weights of the adjacency bitmap words are too large.
84  *
85  * And, we want to do the search in order of increasing maximum
86  * hamming weight.  This is because in practice optimal solutions tend
87  * to have low hamming weight, and having found a reasonable solution
88  * early allows us to eliminate a lot of candidates without doing the
89  * full LP.
90  */
91
92 typedef uint32_t AdjWord;
93 #define PRADJ "08"PRIx32
94
95 #define FOR_BITS(j,m) for (j=0, j##bit=1; j < (m); j++, j##bit<<=1)
96
97 static int n, m, maxhamweight;
98 static AdjWord *adjmatrix;
99 static AdjWord adjall;
100
101 static double best;
102 static glp_prob *best_prob;
103 static AdjWord *best_adjmatrix;
104
105 static int n_max_frags, m_max_frags;
106 static int *weight;
107
108 static unsigned printcounter;
109
110 static void iterate(void);
111 static void iterate_recurse(int i, AdjWord min);
112 static bool preconsider_ok(int nwords, bool doprint);
113 static bool maxhamweight_ok(void);
114 static void optimise(bool doprint);
115
116 static void progress_eol(void) {
117   fprintf(stderr,"        \r");
118   fflush(stderr);
119 }
120
121 static void set_best(double new_best) {
122   best = new_best;
123   /*
124    * When computing n_max_frags, we want to set a value that will skip
125    * anything that won't provide strictly better solutions.  So we
126    * want
127    *             frags <      n / best
128    *                        _          _
129    *   <=>       frags <   |  n / best  |
130    *                        _          _
131    *   <=>       frags <=  |  n / best  | - 1
132    */
133   n_max_frags = ceil(n / best) - 1;
134   m_max_frags = ceil(m / best) - 1;
135 }
136
137 /*----- multicore support -----*/
138
139 /*
140  * Multicore protocol
141  *
142  * We fork into:
143  *   - master (parent)
144  *   - generator
145  *   - ncpu workers
146  *
147  * ipc facilities:
148  *   - one pipe ("work") from generator to workers
149  *   - ever-extending file ("bus") containing new "best" values
150  *   - one file for each worker giving maxhamweight and adjmatrix for best
151  *
152  * generator runs iterate_recurse to a certain depth and writes the
153  * candidates to a pipe
154  *
155  * workers read candidates from the pipe and resume iterate_recurse
156  * halfway through the recursion
157  *
158  * whenever a worker does a doprint, it checks the bus for new best
159  * value; actual best values are appended
160  *
161  * master waits for generator and all workers to finish and then
162  * runs optimise() for each worker's best, then prints
163  */ 
164
165 static int ncpus = 0, multicore_iteration_boundary = INT_MAX;
166
167 static int mc_bus, mc_work[2];
168 static off_t mc_bus_read;
169
170 typedef struct {
171   int w;
172   FILE *results;
173   pid_t pid;
174 } Worker;
175 static Worker *mc_us;
176 static bool mc_am_generator;
177
178 static void multicore_check_for_new_best(void);
179
180 #define MAX_NIOVS 4
181 static AdjWord mc_iter_min;
182 static int mc_niovs;
183 static size_t mc_iovlen;
184 static struct iovec mc_iov[MAX_NIOVS];
185
186 #define IOV0 (mc_niovs = mc_iovlen = 0)
187
188 #define IOV(obj, count) ({                              \
189     assert(mc_niovs < MAX_NIOVS);                       \
190     mc_iov[mc_niovs].iov_base = &(obj);                 \
191     mc_iov[mc_niovs].iov_len = sizeof(obj) * (count);   \
192     mc_iovlen += mc_iov[mc_niovs].iov_len;              \
193     mc_niovs++;                                         \
194   })
195
196 static void mc_rwvsetup_outer(void) {
197   IOV0;
198   IOV(maxhamweight, 1);
199   IOV(mc_iter_min, 1);
200   IOV(*adjmatrix, multicore_iteration_boundary);
201   IOV(*weight, m);
202 }
203
204 static void mc_rwvsetup_full(void) {
205   IOV0;
206   IOV(*adjmatrix, n);
207 }
208
209 static void vlprintf(const char *fmt, va_list al) {
210   vfprintf(stderr,fmt,al);
211   progress_eol();
212 }
213
214 static void LPRINTF(const char *fmt, ...) {
215   va_list al;
216   va_start(al,fmt);
217   vlprintf(fmt,al);
218   va_end(al);
219 }
220
221 static void mc_awaitpid(int wnum, pid_t pid) {
222   LPRINTF("master awaiting %2d [%ld]",wnum,(long)pid);
223   int status;
224   pid_t got = waitpid(pid, &status, 0);
225   assert(got == pid);
226   if (status) {
227     fprintf(stderr,"\nFAILED SUBPROC %2d [%ld] %d\n",
228             wnum, (long)pid, status);
229     exit(-1);
230   }
231 }
232
233 static void multicore_outer_iteration(int i, AdjWord min) {
234   static unsigned check_counter;
235
236   assert(i == multicore_iteration_boundary);
237   mc_iter_min = min;
238   mc_rwvsetup_outer();
239   ssize_t r = writev(mc_work[1], mc_iov, mc_niovs);
240   assert(r == mc_iovlen);
241   /* effectively, this writev arranges to transfers control
242    * to some worker's instance of iterate_recurse via mc_iterate_worker */
243
244   if (!(check_counter++ & 0xff))
245     multicore_check_for_new_best();
246 }
247
248 static void mc_iterate_worker(void) {
249   for (;;) {
250     mc_rwvsetup_outer();
251     ssize_t r = readv(mc_work[0], mc_iov, mc_niovs);
252     if (r == 0) break;
253     assert(r == mc_iovlen);
254     
255     bool ok = maxhamweight_ok();
256     if (!ok) continue;
257
258     ok = preconsider_ok(multicore_iteration_boundary, 1);
259     progress_eol();
260     if (!ok) continue;
261
262     /* stop iterate_recurse from trying to run multicore_outer_iteration */
263     int mc_org_it_bound = multicore_iteration_boundary;
264     multicore_iteration_boundary = INT_MAX;
265     iterate_recurse(mc_org_it_bound, mc_iter_min);
266     multicore_iteration_boundary = mc_org_it_bound;
267   }
268   if (best_adjmatrix) {
269     LPRINTF("worker %2d reporting",mc_us->w);
270     adjmatrix = best_adjmatrix;
271     mc_rwvsetup_full();
272     ssize_t r = writev(fileno(mc_us->results), mc_iov, mc_niovs);
273     assert(r == mc_iovlen);
274   }
275   LPRINTF("worker %2d ending",mc_us->w);
276   exit(0);
277 }
278
279 static void multicore(void) {
280   Worker *mc_workers;
281   int w;
282   pid_t genpid;
283
284   multicore_iteration_boundary = n / 2;
285
286   FILE *busf = tmpfile();  assert(busf);
287   mc_bus = fileno(busf);
288   int r = fcntl(mc_bus, F_GETFL);  assert(r >= 0);
289   r |= O_APPEND;
290   r = fcntl(mc_bus, F_SETFL, r);  assert(r >= 0);
291
292   r = pipe(mc_work);  assert(!r);
293
294   mc_workers = xmalloc(sizeof(*mc_workers) * ncpus);
295   for (w=0; w<ncpus; w++) {
296     mc_workers[w].w = w;
297     mc_workers[w].results = tmpfile();  assert(mc_workers[w].results);
298     mc_workers[w].pid = fork();  assert(mc_workers[w].pid >= 0);
299     if (!mc_workers[w].pid) {
300       mc_us = &mc_workers[w];
301       close(mc_work[1]);
302       LPRINTF("worker %2d running", w);
303       mc_iterate_worker();
304       exit(0);
305     }
306   }
307
308   close(mc_work[0]);
309
310   genpid = fork();  assert(genpid >= 0);
311   if (!genpid) {
312     mc_am_generator = 1;
313     LPRINTF("generator running");
314     iterate();
315     exit(0);
316   }
317
318   close(mc_work[1]);
319   mc_awaitpid(-1, genpid);
320   for (w=0; w<ncpus; w++)
321     mc_awaitpid(w, mc_workers[w].pid);
322
323   for (w=0; w<ncpus; w++) {
324     mc_rwvsetup_full();
325     LPRINTF("reading report from %2d",w);
326     ssize_t sr = preadv(fileno(mc_workers[w].results), mc_iov, mc_niovs, 0);
327     if (!sr) continue;
328     LPRINTF("got report from %2d",w);
329     maxhamweight = 0;
330     optimise(1);
331   }
332 }
333
334 static void multicore_check_for_new_best(void) {
335   if (!(mc_us || mc_am_generator))
336     return;
337
338   for (;;) {
339     double msg;
340     ssize_t got = pread(mc_bus, &msg, sizeof(msg), mc_bus_read);
341     if (!got) break;
342     assert(got == sizeof(msg));
343     if (msg > best)
344       set_best(msg);
345     mc_bus_read += sizeof(msg);
346   }
347 }
348
349 static void multicore_found_new_best(void) {
350   if (!mc_us)
351     return;
352
353   if (mc_us /* might be master */) fprintf(stderr,"    w%-2d ",mc_us->w);
354   ssize_t wrote = write(mc_bus, &best, sizeof(best));
355   assert(wrote == sizeof(best));
356 }
357
358 /*----- end of multicore support -----*/
359
360 static AdjWord *xalloc_adjmatrix(void) {
361   return xmalloc(sizeof(*adjmatrix)*n);
362 }
363
364 static void prep(void) {
365   adjall = ~((~(AdjWord)0) << m);
366   adjmatrix = xalloc_adjmatrix();
367   glp_term_out(GLP_OFF);
368   setlinebuf(stderr);
369   weight = calloc(sizeof(*weight), m);  assert(weight);
370   n_max_frags = INT_MAX;
371   m_max_frags = INT_MAX;
372 }
373
374 #if 0
375 static AdjWord one_adj_bit(int bitnum) {
376   return (AdjWord)1 << bitnum;
377 }
378 #endif
379
380 static int count_set_adj_bits(AdjWord w) {
381   int j, total = 0;
382   AdjWord jbit;
383   FOR_BITS(j,m)
384     total += !!(w & jbit);
385   return total;
386 }
387
388 #define PRINTF(...) if (!doprint) ; else fprintf(stderr, __VA_ARGS__)
389
390 static int totalfrags;
391
392 static bool maxhamweight_ok(void) {
393   return maxhamweight <= m_max_frags;
394 }
395
396 static bool preconsider_ok(int nwords, bool doprint) {
397   int i;
398
399   PRINTF("%2d ", maxhamweight);
400
401   bool had_max = 0;
402   for (i=0, totalfrags=0; i<nwords; i++) {
403     int frags = count_set_adj_bits(adjmatrix[i]);
404     PRINTF("%"PRADJ" ", adjmatrix[i]);
405     if (frags > m_max_frags) {
406       PRINTF(" too fine");
407       goto out;
408     }
409     had_max += (frags >= maxhamweight);
410     totalfrags += frags;
411   }
412   if (!had_max) {
413     /* Skip this candidate as its max hamming weight is lower than
414      * we're currently looking for (which means we must have done it
415      * already).  (The recursive iteration ensures that none of the
416      * words have more than the max hamming weight.) */
417     PRINTF(" nomaxham");
418     goto out;
419   }
420   return 1;
421
422  out:
423   return 0;
424 }
425
426 static void optimise(bool doprint) {
427   /* Consider the best answer (if any) for a given adjacency matrix */
428   glp_prob *prob = 0;
429   int i, j;
430   AdjWord jbit;
431
432   /*
433    * Up to a certain point, optimise() can be restarted.  We use this
434    * to go back and print the debugging output if it turns out that we
435    * have an interesting case.  The HAVE_PRINTED macro does this: its
436    * semantics are to go back in time and make sure that we have
437    * printed the description of the search case.
438    */
439 #define HAVE_PRINTED ({                                         \
440       if (!doprint) { doprint = 1; goto retry_with_print; }     \
441     })
442  retry_with_print:
443   if (prob) {
444     glp_delete_prob(prob);
445     prob = 0;
446   }
447
448   bool ok = preconsider_ok(n, doprint);
449   if (!ok)
450     goto out;
451
452   /*
453    * We formulate our problem as an LP problem as follows.
454    * In this file "n" and "m" are the matchstick numbers.
455    *
456    * Each set bit in the adjacency matrix corresponds to taking a
457    * fragment from old match i and making it part of new match j.
458    *
459    * The structural variables (columns) are:
460    *   x_minimum        minimum size of any fragment (bounded below by 0)
461    *   x_morefrag_i_j   the amount by which the size of the fragment
462    *                     i,j exceeds the minimum size (bounded below by 0)
463    *
464    * The auxiliary variables (rows) are:
465    *   x_total_i       total length for each input match (fixed variable)
466    *   x_total_j       total length for each output match (fixed variable)
467    *
468    * The objective function is simply
469    *   maximise x_minimum
470    *
471    * We use X_ and Y_ to refer to GLPK's (1-based) column and row indices.
472    * ME_ refers to entries in the list of constraint matrix elements
473    * which we build up as we go.
474    */
475
476   prob = glp_create_prob();
477
478   int Y_totals_i = glp_add_rows(prob, n);
479   int Y_totals_j = glp_add_rows(prob, m);
480   int X_minimum = glp_add_cols(prob, 1);
481
482   {
483   int next_matrix_entry = 1; /* wtf GLPK! */
484   int matrix_entries_size = next_matrix_entry + n + m + totalfrags*2;
485   double matrix_entries[matrix_entries_size];
486   int matrix_entries_XY[2][matrix_entries_size];
487
488 #define ADD_MATRIX_ENTRY(Y,X) ({                        \
489       assert(next_matrix_entry < matrix_entries_size);  \
490       matrix_entries_XY[0][next_matrix_entry] = (X);    \
491       matrix_entries_XY[1][next_matrix_entry] = (Y);    \
492       matrix_entries[next_matrix_entry] = 0;            \
493       next_matrix_entry++;                              \
494     })
495
496   int ME_totals_i__minimum = next_matrix_entry;
497   for (i=0; i<n; i++) ADD_MATRIX_ENTRY(Y_totals_i+i, X_minimum);
498
499   int ME_totals_j__minimum = next_matrix_entry;
500   for (j=0; j<m; j++) ADD_MATRIX_ENTRY(Y_totals_j+j, X_minimum);
501
502   /* \forall_i x_total_i = m */
503   /* \forall_i x_total_j = n */
504   for (i=0; i<n; i++) glp_set_row_bnds(prob, Y_totals_i+i, GLP_FX, m,m);
505   for (j=0; j<m; j++) glp_set_row_bnds(prob, Y_totals_j+j, GLP_FX, n,n);
506
507   /* x_minimum >= 0 */
508   glp_set_col_bnds(prob, X_minimum, GLP_LO, 0, 0);
509   glp_set_col_name(prob, X_minimum, "minimum");
510
511   /* objective is maximising x_minimum */
512   glp_set_obj_dir(prob, GLP_MAX);
513   glp_set_obj_coef(prob, X_minimum, 1);
514
515   for (i=0; i<n; i++) {
516     FOR_BITS(j,m) {
517       if (!(adjmatrix[i] & jbit))
518         continue;
519       /* x_total_i += x_minimum */
520       /* x_total_j += x_minimum */
521       matrix_entries[ ME_totals_i__minimum + i ] ++;
522       matrix_entries[ ME_totals_j__minimum + j ] ++;
523
524       /* x_morefrag_i_j >= 0 */
525       int X_morefrag_i_j = glp_add_cols(prob, 1);
526       glp_set_col_bnds(prob, X_morefrag_i_j, GLP_LO, 0, 0);
527       if (doprint) {
528         char buf[255];
529         snprintf(buf,sizeof(buf),"mf %d,%d",i,j);
530         glp_set_col_name(prob, X_morefrag_i_j, buf);
531       }
532
533       /* x_total_i += x_morefrag_i_j */
534       /* x_total_j += x_morefrag_i_j */
535       int ME_totals_i__mf_i_j = ADD_MATRIX_ENTRY(Y_totals_i+i, X_morefrag_i_j);
536       int ME_totals_j__mf_i_j = ADD_MATRIX_ENTRY(Y_totals_j+j, X_morefrag_i_j);
537       matrix_entries[ME_totals_i__mf_i_j] = 1;
538       matrix_entries[ME_totals_j__mf_i_j] = 1;
539     }
540   }
541
542   assert(next_matrix_entry == matrix_entries_size);
543
544   glp_load_matrix(prob, matrix_entries_size-1,
545                   matrix_entries_XY[1], matrix_entries_XY[0],
546                   matrix_entries);
547
548   int r = glp_simplex(prob, NULL);
549   PRINTF(" glp=%d", r);
550
551 #define OKERR(e) \
552   case e: PRINTF(" " #e ); goto out;
553 #define BADERR(e) \
554   case e: HAVE_PRINTED; printf(" " #e " CRASHING\n"); exit(-1);
555 #define DEFAULT \
556   default: HAVE_PRINTED; printf(" ! CRASHING\n"); exit(-1);
557
558   switch (r) {
559   OKERR(GLP_ESING);
560   OKERR(GLP_ECOND);
561   OKERR(GLP_EBOUND);
562   OKERR(GLP_EFAIL);
563   OKERR(GLP_ENOPFS);
564   OKERR(GLP_ENODFS);
565   BADERR(GLP_EBADB);
566   BADERR(GLP_EOBJLL);
567   BADERR(GLP_EOBJUL);
568   BADERR(GLP_EITLIM);
569   BADERR(GLP_ETMLIM);
570   BADERR(GLP_EINSTAB);
571   BADERR(GLP_ENOCVG);
572   case 0: break;
573   DEFAULT;
574   }
575
576   r = glp_get_status(prob);
577   PRINTF(" status=%d", r);
578
579   switch (r) {
580   OKERR(GLP_NOFEAS);
581   OKERR(GLP_UNDEF);
582   BADERR(GLP_FEAS);
583   BADERR(GLP_INFEAS);
584   BADERR(GLP_UNBND);
585   case GLP_OPT: break;
586   DEFAULT;
587   }
588
589   double got = glp_get_obj_val(prob);
590   PRINTF("  %g", got);
591   if (got <= best)
592     goto out;
593
594   HAVE_PRINTED;
595
596   set_best(got);
597   multicore_found_new_best();
598
599   if (best_prob) glp_delete_prob(best_prob);
600   best_prob = prob;
601
602   free(best_adjmatrix);
603   best_adjmatrix = xalloc_adjmatrix();
604   memcpy(best_adjmatrix, adjmatrix, sizeof(*adjmatrix)*n);
605
606   PRINTF(" BEST        \n");
607   return;
608
609   }
610  out:
611   if (prob)
612     glp_delete_prob(prob);
613   if (doprint) progress_eol();
614   if (doprint) multicore_check_for_new_best();
615 }
616
617 static void iterate_recurse(int i, AdjWord min) {
618   int j;
619   AdjWord jbit;
620
621   if (i >= n) {
622     printcounter++;
623     optimise(!(printcounter & 0xfff));
624     return;
625   }
626   if (i >= multicore_iteration_boundary) {
627     multicore_outer_iteration(i, min);
628     return;
629   }
630   for (adjmatrix[i] = min;
631        ;
632        adjmatrix[i]++) {
633     if (count_set_adj_bits(adjmatrix[i]) > maxhamweight)
634       goto again;
635     if (i == 0 && (adjmatrix[i] & (1+adjmatrix[i])))
636       goto again;
637
638     FOR_BITS(j,m)
639       if (adjmatrix[i] & jbit)
640         weight[j]++;
641     for (int j = 0; j < m; j++)
642       if (weight[j] >= n_max_frags)
643         goto takeout;
644
645     iterate_recurse(i+1, adjmatrix[i]);
646
647   takeout:
648     FOR_BITS(j,m)
649       if (adjmatrix[i] & jbit)
650         weight[j]--;
651
652   again:
653     if (adjmatrix[i] == adjall)
654       return;
655   }
656 }
657
658 static void iterate(void) {
659   for (maxhamweight=1; maxhamweight<=m; maxhamweight++) {
660     if (!maxhamweight_ok())
661       continue;
662
663     iterate_recurse(0, 1);
664   }
665 }
666
667 static void report(void) {
668   fprintf(stderr, "\n");
669   if (best_prob) {
670     double min = glp_get_obj_val(best_prob);
671     double a[n][m];
672     int i, j, cols;
673     for (i = 0; i < n; i++)
674       for (j = 0; j < m; j++)
675         a[i][j] = 0;
676     cols = glp_get_num_cols(best_prob);
677     for (i = 1; i <= cols; i++) {
678       int x, y;
679       if (2 != sscanf(glp_get_col_name(best_prob, i), "mf %d,%d", &x, &y))
680         continue;
681       a[x][y] = min + glp_get_col_prim(best_prob, i);
682     }
683     printf("%d into %d: min fragment %g   [%s]\n", n, m, min, VERSION);
684     for (i = 0; i < n; i++) {
685       for (j = 0; j < m; j++) {
686         if (a[i][j])
687           printf(" %9.3f", a[i][j]);
688         else
689           printf("          ");
690       }
691       printf("\n");
692     }
693   }
694   if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); }
695 }
696  
697 int main(int argc, char **argv) {
698   int opt;
699   while ((opt = getopt(argc,argv,"j:")) >= 0) {
700     switch (opt) {
701     case 'j': ncpus = atoi(optarg); break;
702     case '+': assert(!"bad option");
703     default: abort();
704     }
705   }
706   argc -= optind-1;
707   argv += optind-1;
708   assert(argc==3);
709   n = atoi(argv[1]);
710   m = atoi(argv[2]);
711
712   prep();
713
714   if (ncpus) multicore();
715   else iterate();
716
717   report();
718   return 0;
719 }