/************************************************************************* * This function takes a graph and produces a bisection of it **************************************************************************/ int MlevelRecursiveBisection(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, floattype *tpwgts, floattype ubfactor, int fpart) { int i, j, nvtxs, cut, tvwgt, tpwgts2[2]; idxtype *label, *where; GraphType lgraph, rgraph; floattype wsum; nvtxs = graph->nvtxs; if (nvtxs == 0) { printf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); return 0; } /* Determine the weights of the partitions */ tvwgt = idxsum(nvtxs, graph->vwgt); tpwgts2[0] = tvwgt*ssum(nparts/2, tpwgts); tpwgts2[1] = tvwgt-tpwgts2[0]; MlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); cut = graph->mincut; /* printf("%5d %5d %5d [%5d %f]\n", tpwgts2[0], tpwgts2[1], cut, tvwgt, ssum(nparts/2, tpwgts));*/ label = graph->label; where = graph->where; for (i=0; i<nvtxs; i++) part[label[i]] = where[i] + fpart; if (nparts > 2) { SplitGraphPart(ctrl, graph, &lgraph, &rgraph); /* printf("%d %d\n", lgraph.nvtxs, rgraph.nvtxs); */ } /* Free the memory of the top level graph */ GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); /* Scale the fractions in the tpwgts according to the true weight */ wsum = ssum(nparts/2, tpwgts); sscale(nparts/2, 1.0/wsum, tpwgts); sscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2); /* for (i=0; i<nparts; i++) printf("%5.3f ", tpwgts[i]); printf("[%5.3f]\n", wsum); */ /* Do the recursive call */ if (nparts > 3) { cut += MlevelRecursiveBisection(ctrl, &lgraph, nparts/2, part, tpwgts, ubfactor, fpart); cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); } else if (nparts == 3) { cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); GKfree(&lgraph.gdata, &lgraph.label, LTERM); } return cut; }
/************************************************************************* * This function takes a graph and produces a bisection of it **************************************************************************/ int MCMlevelRecursiveBisection2(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, idxtype *part, float ubfactor, int fpart) { int i, nvtxs, cut; float wsum, tpwgts2[2]; idxtype *label, *where; GraphType lgraph, rgraph; nvtxs = graph->nvtxs; if (nvtxs == 0) return 0; /* Determine the weights of the partitions */ tpwgts2[0] = ssum(nparts/2, tpwgts); tpwgts2[1] = 1.0-tpwgts2[0]; MCMlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); cut = graph->mincut; label = graph->label; where = graph->where; for (i=0; i<nvtxs; i++) part[label[i]] = where[i] + fpart; if (nparts > 2) SplitGraphPart(ctrl, graph, &lgraph, &rgraph); /* Free the memory of the top level graph */ GKfree((void**)&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->label, &graph->npwgts, LTERM); /* Scale the fractions in the tpwgts according to the true weight */ wsum = ssum(nparts/2, tpwgts); sscale(nparts/2, 1.0/wsum, tpwgts); sscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2); /* Do the recursive call */ if (nparts > 3) { cut += MCMlevelRecursiveBisection2(ctrl, &lgraph, nparts/2, tpwgts, part, ubfactor, fpart); cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); } else if (nparts == 3) { cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); GKfree((void**)&lgraph.gdata, &lgraph.nvwgt, &lgraph.label, LTERM); } return cut; }
/************************************************************************* * This function takes a graph and produces a bisection of it **************************************************************************/ idxtype MlevelRecursiveBisection(CtrlType *ctrl, GraphType *graph, idxtype nparts, idxtype *part, float *tpwgts, float ubfactor, idxtype fpart) { idxtype i, j, nvtxs, cut, tvwgt, tpwgts2[2]; idxtype *label, *where; GraphType lgraph, rgraph; float wsum; nvtxs = graph->nvtxs; if (nvtxs == 0) { mprintf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); return 0; } /* Determine the weights of the partitions */ tvwgt = idxsum(nvtxs, graph->vwgt, 1); tpwgts2[0] = tvwgt*gk_fsum(nparts/2, tpwgts, 1); tpwgts2[1] = tvwgt-tpwgts2[0]; MlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); cut = graph->mincut; /* mprintf("%5D %5D %5D [%5D %f]\n", tpwgts2[0], tpwgts2[1], cut, tvwgt, gk_fsum(nparts/2, tpwgts, 1));*/ label = graph->label; where = graph->where; for (i=0; i<nvtxs; i++) part[label[i]] = where[i] + fpart; if (nparts > 2) { SplitGraphPart(ctrl, graph, &lgraph, &rgraph); /* mprintf("%D %D\n", lgraph.nvtxs, rgraph.nvtxs); */ } /* Free the memory of the top level graph */ FreeGraph(graph, 0); /* Scale the fractions in the tpwgts according to the true weight */ wsum = gk_fsum(nparts/2, tpwgts, 1); gk_fscale(nparts/2, 1.0/wsum, tpwgts, 1); gk_fscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2, 1); /* for (i=0; i<nparts; i++) mprintf("%5.3f ", tpwgts[i]); mprintf("[%5.3f]\n", wsum); */ /* Do the recursive call */ if (nparts > 3) { cut += MlevelRecursiveBisection(ctrl, &lgraph, nparts/2, part, tpwgts, ubfactor, fpart); cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); } else if (nparts == 3) { cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); FreeGraph(&lgraph, 0); } return cut; }