/* * Copyright 1997, Regents of the University of Minnesota * * stat.c * * This file computes various statistics * * Started 7/25/97 * George * * $Id: stat.c 9942 2011-05-17 22:09:52Z karypis $ * */ #include "metislib.h" /************************************************************************* * This function computes cuts and balance information **************************************************************************/ void ComputePartitionInfoBipartite(graph_t *graph, idx_t nparts, idx_t *where) { idx_t i, j, k, nvtxs, ncon, mustfree=0; idx_t *xadj, *adjncy, *vwgt, *vsize, *adjwgt, *kpwgts, *tmpptr; idx_t *padjncy, *padjwgt, *padjcut; nvtxs = graph->nvtxs; ncon = graph->ncon; xadj = graph->xadj; adjncy = graph->adjncy; vwgt = graph->vwgt; vsize = graph->vsize; adjwgt = graph->adjwgt; if (vwgt == NULL) { vwgt = graph->vwgt = ismalloc(nvtxs, 1, "vwgt"); mustfree = 1; } if (adjwgt == NULL) { adjwgt = graph->adjwgt = ismalloc(xadj[nvtxs], 1, "adjwgt"); mustfree += 2; } printf("%"PRIDX"-way Cut: %5"PRIDX", Vol: %5"PRIDX", ", nparts, ComputeCut(graph, where), ComputeVolume(graph, where)); /* Compute balance information */ kpwgts = ismalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts"); for (i=0; ivwgt = NULL; } if (mustfree == 2 || mustfree == 3) { gk_free((void **)&adjwgt, LTERM); graph->adjwgt = NULL; } gk_free((void **)&kpwgts, &padjncy, &padjwgt, &padjcut, LTERM); } /************************************************************************* * This function computes the balance of the partitioning **************************************************************************/ void ComputePartitionBalance(graph_t *graph, idx_t nparts, idx_t *where, real_t *ubvec) { idx_t i, j, nvtxs, ncon; idx_t *kpwgts, *vwgt; real_t balance; nvtxs = graph->nvtxs; ncon = graph->ncon; vwgt = graph->vwgt; kpwgts = ismalloc(nparts, 0, "ComputePartitionInfo: kpwgts"); if (vwgt == NULL) { for (i=0; invtxs; i++) kpwgts[where[i]] += vwgt[i*ncon+j]; ubvec[j] = 1.0*nparts*kpwgts[iargmax(nparts, kpwgts)]/(1.0*isum(nparts, kpwgts, 1)); } } gk_free((void **)&kpwgts, LTERM); } /************************************************************************* * This function computes the balance of the element partitioning **************************************************************************/ real_t ComputeElementBalance(idx_t ne, idx_t nparts, idx_t *where) { idx_t i; idx_t *kpwgts; real_t balance; kpwgts = ismalloc(nparts, 0, "ComputeElementBalance: kpwgts"); for (i=0; i