Index: pcb-mincut/main.c =================================================================== --- pcb-mincut/main.c (revision 12727) +++ pcb-mincut/main.c (revision 12728) @@ -23,7 +23,7 @@ fprintf(stderr, "Failed to load input, exiting\n"); exit(1); } - best = solve(g); + best = solve(g, NULL); for(n = 0; best[n*2] != -1; n++) printf("%s-%s\n", strempty(g->node2name[best[n*2+0]]), strempty(g->node2name[best[n*2+1]])); Index: pcb-mincut/solve.c =================================================================== --- pcb-mincut/solve.c (revision 12727) +++ pcb-mincut/solve.c (revision 12728) @@ -19,6 +19,7 @@ #include #include #include +#include #include "solve.h" #include "compat_misc.h" @@ -204,11 +205,12 @@ } #define strempty(s) ((s) == NULL ? "" : (s)) -int *solve(gr_t *g) +int *solve(gr_t *g, int (*progress)(int so_far, int total, const char *msg)) { - int n, best, res, till, cuts_size; + int n, best, res, till, cuts_size, have_progress = 0; double nd; int *cuts, *best_cuts; + time_t currt, nextt; /* count how many nodes we really have - the ones not cut down from the graph by the preprocessor */ nd = 0; @@ -226,7 +228,17 @@ best_cuts = malloc(cuts_size); best = BAD; + nextt = time(NULL)+2; for(n = 0; n < till; n++) { + if ((progress != NULL) && ((n % 128) == 0)) { + currt = time(NULL); + if (currt >= nextt) { + have_progress = 1; + if (progress(n, till, "Optimizing shortcircuit indication\nusing mincut... Press cancel\nto get a dumb indication")) + break; + nextt = currt+1; + } + } res = solve_(g, cuts); #ifdef DEBUG_SOLVE printf("solution %d=%d\n", n, res); @@ -239,6 +251,9 @@ break; } + if (have_progress) + progress(0, 0, NULL); + #ifdef DEBUG_SOLVE printf("Best solution cuts %d edge%s:", best, best == 1 ? "" : "s"); for(n = 0; best_cuts[n*2] != -1; n++) { Index: pcb-mincut/solve.h =================================================================== --- pcb-mincut/solve.h (revision 12727) +++ pcb-mincut/solve.h (revision 12728) @@ -2,4 +2,4 @@ /* returns a list of object ID pairs (each nth and n+1th element) terminated by a -1;-1. Cutting these vertices would separate g. */ -int *solve(gr_t *g); +int *solve(gr_t *g, int (*progress)(int so_far, int total, const char *msg)); Index: rats_mincut.c =================================================================== --- rats_mincut.c (revision 12727) +++ rats_mincut.c (revision 12728) @@ -275,7 +275,7 @@ #endif if (!bad_gr) { - solution = solve(g); + solution = solve(g, pcb_gui->progress); if (solution != NULL) { debprintf("Would cut:\n");