|
|
Go to the documentation of this file. 54 static int is_valid( const GRAPH*, const int, const int, const int*, const int *); 55 static void show_flow( const GRAPH*, const int*, const int*); 58 static void cut_statist( void); 59 static void cut_sum( const GRAPH*, const int*, const int*); 63 static int s_pushes = 0; 64 static int n_pushes = 0; 65 static int m_pushes = 0; 66 static int x_pushes = 0; 67 static int relabels = 0; 68 static int s_sleeps = 0; 69 static int m_sleeps = 0; 70 static int searches = 0; 71 static int cutsums = 0; 102 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> mincut_e), p-> knots) ); 103 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> mincut_x), p-> edges) ); 104 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> mincut_r), p-> edges) ); 136 SCIPfreeMemoryArray(scip, &(p-> mincut_e)); 137 SCIPfreeMemoryArray(scip, &(p-> mincut_x)); 138 SCIPfreeMemoryArray(scip, &(p-> mincut_r)); 145 inline static void delete( 153 assert(q_dist != NULL); 154 assert(q_head != NULL); 155 assert(q_prev != NULL); 156 assert(q_next != NULL); 157 assert(q_dist[knot] > 0); 159 if (q_next[knot] != Q_NMOQ) 163 if (q_prev[knot] == Q_LAST) 165 assert(q_dist[knot] >= 0); 166 assert(q_head[q_dist[knot]] == knot); 168 q_head[q_dist[knot]] = q_next[knot]; 172 assert(q_prev[knot] >= 0); 173 assert(q_next[q_prev[knot]] == knot); 175 q_next[q_prev[knot]] = q_next[knot]; 180 if (q_next[knot] != Q_LAST) 182 assert(q_next[knot] >= 0); 183 assert(q_prev[q_next[knot]] == knot); 185 q_prev[q_next[knot]] = q_prev[knot]; 190 assert(q_next[knot] == Q_NMOQ); 191 assert(q_prev[knot] == Q_NMOQ); 203 assert(q_dist != NULL); 204 assert(q_head != NULL); 205 assert(q_prev != NULL); 206 assert(q_next != NULL); 207 assert(q_dist[knot] > 0); 210 if (q_prev[knot] == Q_NMOQ) 213 q_next[knot] = q_head[q_dist[knot]]; 215 if (q_next[knot] != Q_LAST) 216 q_prev[q_next[knot]] = knot; 218 q_head[q_dist[knot]] = knot; 220 if (q_dist[knot] < dmin) 223 assert(q_next[knot] != Q_NMOQ); 224 assert(q_prev[knot] != Q_NMOQ); 225 assert(q_dist[knot] >= dmin); 245 assert(q_temp != NULL); 246 assert(q_dist != NULL); 247 assert(q_numb != NULL); 250 assert(s < p->knots); 252 assert(t < p->knots); 257 q_temp[visited++] = t; 263 for(j = 0; (j < visited) && (visited < p->knots); j++) 265 assert(visited < p->knots); 271 assert(i < p->knots); 272 assert(q_dist[i] >= 0); 273 assert(q_dist[i] < visited); 276 assert((j == 0) || (q_dist[i] >= q_dist[q_temp[j - 1]])); 277 assert((j == visited - 1) || (q_dist[i] <= q_dist[q_temp[j + 1]])); 289 assert(!w[l] || (q_dist[l] >= 0)); 293 q_dist[l] = q_dist[i] + 1; 294 q_temp[visited++] = l; 297 assert(q_dist[l] < p-> knots); 341 assert(s < p->knots); 343 assert(t < p->knots); 345 assert(capa != NULL); 347 assert(q_head != NULL); 348 assert(q_dist != NULL); 349 assert(q_numb != NULL); 350 assert(q_prev != NULL); 351 assert(q_next != NULL); 352 assert(q_temp != NULL); 353 assert(excess != NULL); 354 assert(transx != NULL); 355 assert(residi != NULL); 363 for(i = 0; i < p-> knots; i++) 375 for(k = 0; k < p-> edges; k++) 382 (void) bfs(p, s, t, q_dist, q_numb, q_temp, w); 386 for(i = 0; i < p-> knots; i++) 400 assert(q_dist[s] > 0); 402 assert(q_dist[t] == 0); 420 excess[j] += transx[k]; 423 (void) insert(j, q_dist, q_head, q_prev, q_next, 1); 426 assert(excess[j] > 0); 427 assert((j == t) || (q_next[j] != Q_NMOQ)); 428 assert((j == t) || (q_prev[j] != Q_NMOQ)); 432 assert((p-> mincut_x)[k] <= capa[k]); 436 show_flow(p, capa, w); 439 assert(is_valid(p, s, t, capa, w)); 468 assert(s < p->knots); 470 assert(t < p->knots); 472 assert(capa != NULL); 474 assert(q_head != NULL); 475 assert(q_dist != NULL); 476 assert(q_numb != NULL); 477 assert(q_prev != NULL); 478 assert(q_next != NULL); 479 assert(q_temp != NULL); 480 assert(excess != NULL); 481 assert(transx != NULL); 482 assert(residi != NULL); 488 wt = (w[t] == 0) ? p-> knots + 1 : w[t]; 491 for(i = 0; i < p->knots; i++) 498 if ((w[i] == 0) || (w[i] >= wt)) 508 visited = bfs(p, s, t, q_dist, q_numb, q_temp, w); 512 for(i = 0; i < p-> knots; i++) 518 for(k = 0; k < p-> edges; k += 2) 527 excess[i] += transx[k + 1] - transx[k]; 528 excess[j] += transx[k] - transx[k + 1]; 532 residi[k + 1] = capa[k + 1]; 536 assert(q_dist[t] == 0); 537 assert(q_temp[0] == t); 541 for(i = 1; i < visited; i++) 543 assert(w[q_temp[i]] == 0); 544 assert(q_temp[i] != s); 545 assert(q_temp[i] != t); 547 if (excess[q_temp[i]] > 0) 548 (void) insert(q_temp[i], q_dist, q_head, q_prev, q_next, 1); 551 show_flow(p, capa, w); 554 assert(is_valid(p, s, t, capa, w)); 596 assert(s < p->knots); 598 assert(t < p->knots); 600 assert(capa != NULL); 623 (void)printf( "graph_mincut_exec(p, s=%d, t=%d, capa, w, rerun=%d)\n", 628 initialise(p, s, t, capa, dist, numb, head, prev, next, temp, e, x, r, w, &dmax); 630 reinitialise(p, s, t, capa, dist, numb, head, prev, next, temp, e, x, r, w, &dmax); 637 assert(is_valid(p, s, t, capa, w)); 645 while((dmin < p->knots) && (head[dmin] == Q_LAST)) 648 if (dmin == p-> knots) 655 assert(prev[i] == Q_LAST); 674 if ((r[k] <= 0) || (w[p-> head[k]])) 681 if (dist[i] != dist[p-> head[k]] + 1) 683 assert(dist[i] <= dist[p-> head[k]]); 685 if ((dist[p-> head[k]] < min_dist) 686 || ((dist[p-> head[k]] == min_dist) && (r[k] > min_capa))) 688 min_knot = p-> head[k]; 689 min_dist = dist[min_knot]; 699 assert( Min(e[i], r[k]) > 0); 706 (e[i] == r[k]) ? x_pushes++ : n_pushes++; 711 e[p-> head[k]] += e[i]; 714 assert(e[p-> head[k]] > 0); 715 assert(w[p-> head[k]] == 0); 718 dmin = insert(p-> head[k], dist, head, prev, next, dmin); 721 assert(r[k] == capa[k] - x[k] + x[ Edge_anti(k)]); 731 e[p-> head[k]] += r[k]; 737 dmin = insert(p-> head[k], dist, head, prev, next, dmin); 740 assert(r[k] == capa[k] - x[k] + x[ Edge_anti(k)]); 752 delete(i, dist, head, prev, next); 754 assert(prev[i] == Q_NMOQ); 755 assert(next[i] == Q_NMOQ); 762 assert(numb[dist[i]] > 0); 764 if (numb[dist[i]] == 1) 768 assert(dmax <= p->knots); 770 for(k = 0; k < p-> knots; k++) 774 if (!w[k] && (dist[i] <= dist[k])) 779 delete(k, dist, head, prev, next); 781 assert(prev[k] == Q_NMOQ); 782 assert(next[k] == Q_NMOQ); 802 assert(dmax <= p->knots); 804 delete(i, dist, head, prev, next); 806 assert(prev[i] == Q_NMOQ); 807 assert(next[i] == Q_NMOQ); 814 assert(min_dist < p->knots); 815 assert(min_capa > 0); 816 assert(min_knot >= 0); 817 assert(min_arc >= 0); 819 delete(i, dist, head, prev, next); 823 dist[i] = min_dist + 1; 825 (void) insert(i, dist, head, prev, next, dmin); 829 assert(dist[i] < p-> knots); 831 assert(min_capa > 0); 832 assert(min_capa == r[min_arc]); 833 assert(p-> head[min_arc] == min_knot); 834 assert(p-> tail[min_arc] == i); 835 assert(dist[i] == dist[min_knot] + 1); 836 assert(w[min_knot] == 0); 841 if (e[i] <= min_capa) 849 if (p-> head[min_arc] != t) 850 dmin = insert(p-> head[min_arc], dist, head, prev, next, dmin); 852 delete(i, dist, head, prev, next); 854 assert(r[min_arc] + r[ Edge_anti(min_arc)] == capa[min_arc] + capa[ Edge_anti(min_arc)]); 855 assert(r[min_arc] >= 0); 856 assert(r[min_arc] == capa[min_arc] - x[min_arc] + x[ Edge_anti(min_arc)]); 873 show_flow(p, capa, w); 876 assert(is_valid(p, s, t, capa, w)); 881 static void cut_statist( void) 883 (void)printf( "Mincut Statistics:\n"); 884 (void)printf( "Node-Searches=%d, Cut Sums=%d\n", 886 (void)printf( "S-Pushes=%d, N-Pushes=%d, X-Pushes=%d, M-Pushes=%d\n", 887 s_pushes, n_pushes, x_pushes, m_pushes); 888 (void)printf( "Relabels=%d, S-Sleeps=%d, M-Sleeps=%d\n\n", 889 relabels, s_sleeps, m_sleeps); 913 assert(capa != NULL); 916 for(k = 0; k < p-> edges; k++) 921 if ((w[i] && !w[j]) || (!w[i] && w[j])) 925 (void)printf( "Cut Sum=%d\n", sum); 954 for(j = 0; j < p-> knots; j++) 957 if ((q[j] >= 0) && (a[q[j]] != j)) 958 return(( void)fprintf(stderr, "Queue Error 1 Knot %d\n", j), FALSE); 960 if (!w[j] && (q[j] < 0) && (e[j] > 0) && (j != t)) 961 return(( void)fprintf(stderr, "Queue Error 2 Knot %d\n", j), FALSE); 963 if (!w[j] && (q[j] >= 0) && (e[j] == 0)) 964 return(( void)fprintf(stderr, "Queue Error 3 Knot %d\n", j), FALSE); 966 if (w[j] && (q[j] >= 0)) 967 return(( void)fprintf(stderr, "Queue Error 4 Knot %d\n", j), FALSE); 970 return(( void)fprintf(stderr, "Negativ Execess Knot %d\n", j), FALSE); 973 return(( void)fprintf(stderr, "Distance too big Knot %d\n", j), FALSE); 981 if ((w[j] && !w[p-> head[k]]) || (w[j] && (w[j] < w[p-> head[k]]))) 983 (void)printf( "k=%d r[k]=%d head=%d tail=%d w[h]=%d w[t]=%d\n", 986 return(( void)fprintf(stderr, "Extended Dormacy Violation Knot %d\n", j), FALSE); 991 for(j = 0; j < p-> edges; j++) 994 return(( void)fprintf(stderr, "Negativ Residual Edge %d\n", j), FALSE); 997 return(( void)fprintf(stderr, "Negativ Flow Edge %d\n", j), FALSE); 1000 return(( void)fprintf(stderr, "Wrong Capacity Equation Edge %d\n", j), FALSE); 1002 if (r[j] != capa[j] - x[j] + x[ Edge_anti(j)]) 1003 return(( void)fprintf(stderr, "Wrong Residual Equation Edge %d\n", j), FALSE); 1008 static void show_flow( 1043 for(j = 0; j < p-> edges; j++) 1044 ( void)printf( "%6d ", j); 1045 (void)fputc( '\n', stdout); 1047 (void)printf( "ta:"); 1048 for(j = 0; j < p-> edges; j++) 1049 ( void)printf( "%6d ", p-> tail[j]); 1050 (void)fputc( '\n', stdout); 1052 (void)printf( "he:"); 1053 for(j = 0; j < p-> edges; j++) 1054 ( void)printf( "%6d ", p-> head[j]); 1055 (void)fputc( '\n', stdout); 1057 (void)printf( "x: "); 1058 for(j = 0; j < p-> edges; j++) 1059 ( void)printf( "%6d ", x[j]); 1060 (void)fputc( '\n', stdout); 1062 (void)printf( "r: "); 1063 for(j = 0; j < p-> edges; j++) 1064 ( void)printf( "%6d ", r[j]); 1065 (void)fputc( '\n', stdout); 1067 (void)printf( "ca:"); 1068 for(j = 0; j < p-> edges; j++) 1069 ( void)printf( "%6d ", capa[j]); 1070 (void)fputc( '\n', stdout); 1072 (void)printf( "w: "); 1073 for(j = 0; j < p-> knots; j++) 1074 ( void)printf( "%2d ", w[j]); 1075 (void)fputc( '\n', stdout); 1077 (void)printf( "d: "); 1078 for(j = 0; j < p-> knots; j++) 1080 (void)fputc( '\n', stdout); 1082 (void)printf( "n: "); 1083 for(j = 0; j < p-> knots; j++) 1084 ( void)printf( "%2d ", numb[j]); 1085 (void)fputc( '\n', stdout); 1087 (void)printf( "h: "); 1088 for(j = 0; j < p-> knots; j++) 1089 ( void)printf( "%2d ", head[j]); 1090 (void)fputc( '\n', stdout); 1092 (void)printf( "p: "); 1093 for(j = 0; j < p-> knots; j++) 1094 ( void)printf( "%2d ", prev[j]); 1095 (void)fputc( '\n', stdout); 1097 (void)printf( "n: "); 1098 for(j = 0; j < p-> knots; j++) 1099 ( void)printf( "%2d ", next[j]); 1100 (void)fputc( '\n', stdout); 1102 (void)printf( "e: "); 1103 for(j = 0; j < p-> knots; j++) 1104 ( void)printf( "%2d ", e[j]); 1105 (void)fputc( '\n', stdout); static void reinitialise(const GRAPH *p, const int s, const int t, const int *capa, int *q_dist, int *q_numb, int *q_head, int *q_prev, int *q_next, int *q_temp, int *excess, int *transx, int *residi, int *w, int *dmax)
void graph_mincut_exec(GRAPH *p, int s, int t, const int *capa, int *w, int rerun)
static int insert(const int knot, int *q_dist, int *q_head, int *q_prev, int *q_next, int dmin)
SCIP_RETCODE graph_mincut_init(SCIP *scip, GRAPH *p)
includes various files containing graph methods used for Steiner problems
static void initialise(const GRAPH *p, const int s, const int t, const int *capa, int *q_dist, int *q_numb, int *q_head, int *q_prev, int *q_next, int *q_temp, int *excess, int *transx, int *residi, int *w, int *dmax)
void graph_mincut_exit(SCIP *scip, GRAPH *p)
static int bfs(const GRAPH *p, const int s, const int t, int *q_dist, int *q_numb, int *q_temp, int *w)
|