/************************************************************************* * This function is the entry point for KWMETIS **************************************************************************/ void METIS_WPartGraphVKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *volume, idxtype *part) { int i, j; GraphType graph; CtrlType ctrl; if (*numflag == 1) Change2CNumbering(*nvtxs, xadj, adjncy); VolSetUpGraph(&graph, OP_KVMETIS, *nvtxs, 1, xadj, adjncy, vwgt, vsize, *wgtflag); if (options[0] == 0) { /* Use the default parameters */ ctrl.CType = KVMETIS_CTYPE; ctrl.IType = KVMETIS_ITYPE; ctrl.RType = KVMETIS_RTYPE; ctrl.dbglvl = KVMETIS_DBGLVL; } else { ctrl.CType = options[OPTION_CTYPE]; ctrl.IType = options[OPTION_ITYPE]; ctrl.RType = options[OPTION_RTYPE]; ctrl.dbglvl = options[OPTION_DBGLVL]; } ctrl.optype = OP_KVMETIS; ctrl.CoarsenTo = amax((*nvtxs)/(40*log2_metis(*nparts)), 20*(*nparts)); ctrl.maxvwgt = (int) 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo); InitRandom(-1); AllocateWorkSpace(&ctrl, &graph, *nparts); IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); *volume = MlevelVolKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03); IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); FreeWorkSpace(&ctrl, &graph); if (*numflag == 1) Change2FNumbering(*nvtxs, xadj, adjncy, part); }
/************************************************************************* * multi-level weighted kernel k-means main function **************************************************************************/ Graclus normalizedCut(char* filename, int nparts) { Graclus ncData; int options[11]; idxtype *part; // cluster result stored in array part float rubvec[MAXNCON], lbvec[MAXNCON]; GraphType graph; int numflag = 0, wgtflag = 0, edgecut, chain_length = 0; int no_args = 1, levels = 0; no_args = 0; if (nparts < 2) { printf("The number of partitions should be greater than 1!\n"); exit(0); } ReadGraph(&graph, filename, &wgtflag); if (graph.nvtxs <= 0) { puts("Empty graph. Nothing to do.\n"); exit(0); } levels = amax((graph.nvtxs)/(40*log2_metis(nparts)), 20*(nparts)); // if(graph.ncon > 1) // printf(" Balancing Constraints: %d\n", graph.ncon); part = idxmalloc(graph.nvtxs, "main: part"); options[0] = 0; // printf("#Clusters: %d\n", nparts); if (graph.ncon == 1) { MLKKM_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &nparts, &chain_length, options, &edgecut, part, levels); } else { int i; for (i = 0; i < graph.ncon; i++) rubvec[i] = HORIZONTAL_IMBALANCE; } ComputePartitionBalance(&graph, nparts, part, lbvec); ComputeNCut(&graph, part, nparts); //for(int i = 0; i < graph.nvtxs; i++) printf("%d\n", part[i]); //int clusterNum = graph.nvtxs; ncData.part = part; ncData.clusterNum = graph.nvtxs; //GKfree((void **) &graph.xadj, (void **) &graph.adjncy, (void **) &graph.vwgt, (void **) &graph.adjwgt, (void **) &part, LTERM); GKfree((void **) &graph.xadj, (void **) &graph.adjncy, (void **) &graph.vwgt, (void **) &graph.adjwgt, LTERM); return ncData; }