45 cptr =
imalloc(nvtxs+1,
"OMETIS: cptr");
46 cind =
imalloc(nvtxs,
"OMETIS: cind");
55 nnvtxs =
graph->nvtxs;
76 for (
i=0;
i<nnvtxs;
i++)
78 for (
l=ii=0; ii<nnvtxs; ii++) {
80 for (
j=cptr[
i];
j<cptr[
i+1];
j++)
88 for (
i=0;
i<nvtxs;
i++)
109 idx_t *label, *bndind;
112 nvtxs =
graph->nvtxs;
133 bndind =
graph->bndind;
134 label =
graph->label;
135 for (
i=0;
i<nbnd;
i++)
136 order[label[bndind[
i]]] = --lastvtx;
152 MMDOrder(ctrl, rgraph, order, lastvtx);
184 *r_sepsize =
graph->pwgts[2];
240 idx_t i, ii,
j, k, jj, kk, nvtxs, nbnd, nswaps, nmind, nbad, qsize;
242 idx_t *mptr, *mind, *swaps, *inqueue;
245 idx_t higain, oldgain, mincut, initcut, mincutorder;
246 idx_t pass, from, to, limit;
247 idx_t badmaxpwgt, mindiff, newdiff;
253 nvtxs =
graph->nvtxs;
258 bndind =
graph->bndind;
259 bndptr =
graph->bndptr;
261 pwgts =
graph->pwgts;
262 rinfo =
graph->nrinfo;
276 pwgts[0], pwgts[1],
graph->nvtxs,
graph->nbnd, badmaxpwgt,
279 to = (pwgts[0] < pwgts[1] ? 1 : 0);
280 for (pass=0; pass<npasses; pass++) {
287 initcut = mincut =
graph->mincut;
292 for (ii=0; ii<nbnd; ii++) {
293 i = bndind[swaps[ii]];
310 mptr[0] = nmind = nbad = 0;
311 mindiff =
abs(pwgts[0]-pwgts[1]);
312 for (nswaps=0; nswaps<nvtxs; nswaps++) {
316 ASSERT(bndptr[higain] != -1);
320 if (nmind +
xadj[higain+1]-
xadj[higain] >= 2*nvtxs-1)
323 inqueue[higain] = -1;
325 if (pwgts[to]+
vwgt[higain] > badmaxpwgt) {
334 pwgts[2] -= (
vwgt[higain]-rinfo[higain].
edegrees[from]);
336 newdiff =
abs(pwgts[to]+
vwgt[higain] - (pwgts[from]-rinfo[higain].edegrees[from]));
337 if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) {
339 mincutorder = nswaps;
344 if (nbad++ > limit) {
345 pwgts[2] += (
vwgt[higain]-rinfo[higain].
edegrees[from]);
351 pwgts[to] +=
vwgt[higain];
353 swaps[nswaps] = higain;
364 else if (
where[k] == from) {
370 pwgts[from] -=
vwgt[k];
373 edegrees[0] = edegrees[1] = 0;
374 for (jj=
xadj[k]; jj<
xadj[k+1]; jj++) {
383 if (inqueue[kk] == pass)
395 mptr[nswaps+1] = nmind;
400 higain, to, (
vwgt[higain]-rinfo[higain].edegrees[from]),
401 vwgt[higain], pwgts[0], pwgts[1], pwgts[2], nswaps, limit));
409 for (nswaps--; nswaps>mincutorder; nswaps--) {
410 higain = swaps[nswaps];
420 edegrees[0] = edegrees[1] = 0;
430 for (
j=mptr[nswaps];
j<mptr[nswaps+1];
j++) {
436 for (jj=
xadj[k]; jj<
xadj[k+1]; jj++) {
444 ASSERT(mincut == pwgts[2]);
448 mincut, mincutorder, pwgts[0], pwgts[1], nbnd, qsize));
450 graph->mincut = mincut;
453 if (pass%2 == 1 && (mincutorder == -1 || mincut >= initcut))
470 idx_t i, ii,
j, k, jj, kk, nvtxs, nbnd, nswaps, nmind;
472 idx_t *mptr, *mind, *moved, *swaps;
475 idx_t higain, oldgain, mincut, initcut, mincutorder;
477 idx_t badmaxpwgt, mindiff, newdiff;
482 nvtxs =
graph->nvtxs;
487 bndind =
graph->bndind;
488 bndptr =
graph->bndptr;
490 pwgts =
graph->pwgts;
491 rinfo =
graph->nrinfo;
506 for (pass=0; pass<npasses; pass++) {
507 iset(nvtxs, -1, moved);
512 initcut = mincut =
graph->mincut;
517 for (ii=0; ii<nbnd; ii++) {
518 i = bndind[swaps[ii]];
540 mindiff =
abs(pwgts[0]-pwgts[1]);
541 to = (pwgts[0] < pwgts[1] ? 0 : 1);
542 for (nswaps=0; nswaps<nvtxs; nswaps++) {
545 if (u[0] != -1 && u[1] != -1) {
549 to = (
g[0] >
g[1] ? 0 : (
g[0] <
g[1] ? 1 : pass%2));
551 if (pwgts[to]+
vwgt[u[to]] > badmaxpwgt)
554 else if (u[0] == -1 && u[1] == -1) {
557 else if (u[0] != -1 && pwgts[0]+
vwgt[u[0]] <= badmaxpwgt) {
560 else if (u[1] != -1 && pwgts[1]+
vwgt[u[1]] <= badmaxpwgt) {
571 if (moved[higain] == -5)
574 ASSERT(bndptr[higain] != -1);
578 if (nmind +
xadj[higain+1]-
xadj[higain] >= 2*nvtxs-1)
583 newdiff =
abs(pwgts[to]+
vwgt[higain] - (pwgts[
other]-rinfo[higain].edegrees[
other]));
584 if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) {
586 mincutorder = nswaps;
590 if (nswaps - mincutorder > limit) {
597 pwgts[to] +=
vwgt[higain];
599 moved[higain] = nswaps;
600 swaps[nswaps] = higain;
611 if (moved[k] == -5 || moved[k] == -(10+
other))
623 edegrees[0] = edegrees[1] = 0;
624 for (jj=
xadj[k]; jj<
xadj[k+1]; jj++) {
631 if (moved[kk] == -5 || moved[kk] == -(10+to))
642 if (moved[k] == -1) {
656 mptr[nswaps+1] = nmind;
662 pwgts[0], pwgts[1], pwgts[2]));
670 for (nswaps--; nswaps>mincutorder; nswaps--) {
671 higain = swaps[nswaps];
682 edegrees[0] = edegrees[1] = 0;
692 for (
j=mptr[nswaps];
j<mptr[nswaps+1];
j++) {
698 for (jj=
xadj[k]; jj<
xadj[k+1]; jj++) {
706 ASSERT(mincut == pwgts[2]);
709 printf(
"\tMinimum sep: %6"PRIDX" at %5"PRIDX", PWGTS: [%6"PRIDX" %6"PRIDX"], NBND: %6"PRIDX"\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd));
711 graph->mincut = mincut;
714 if (mincutorder == -1 || mincut >= initcut)