/* * Copyright 1997, Regents of the University of Minnesota * * compress.c * * This file contains code for compressing nodes with identical adjacency * structure and for prunning dense columns * * Started 9/17/97 * George */ #include "metislib.h" /*************************************************************************/ /*! This function compresses a graph by merging identical vertices The compression should lead to at least 10% reduction. The compressed graph that is generated has its adjwgts set to 1. \returns 1 if compression was performed, otherwise it returns 0. */ /**************************************************************************/ graph_t *CompressGraph(ctrl_t *ctrl, idx_t nvtxs, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *cptr, idx_t *cind) { idx_t i, ii, iii, j, jj, k, l, cnvtxs, cnedges; idx_t *cxadj, *cadjncy, *cvwgt, *mark, *map; ikv_t *keys; graph_t *graph=NULL; mark = ismalloc(nvtxs, -1, "CompressGraph: mark"); map = ismalloc(nvtxs, -1, "CompressGraph: map"); keys = ikvmalloc(nvtxs, "CompressGraph: keys"); /* Compute a key for each adjacency list */ for (i=0; idbglvl, METIS_DBG_INFO, printf(" Compression: reduction in # of vertices: %"PRIDX".\n", nvtxs-cnvtxs)); if (cnvtxs < COMPRESSION_FRACTION*nvtxs) { /* Sufficient compression is possible, so go ahead and create the compressed graph */ graph = CreateGraph(); cnedges = 0; for (i=0; ixadj = imalloc(cnvtxs+1, "CompressGraph: xadj"); cvwgt = graph->vwgt = ismalloc(cnvtxs, 0, "CompressGraph: vwgt"); cadjncy = graph->adjncy = imalloc(cnedges, "CompressGraph: adjncy"); graph->adjwgt = ismalloc(cnedges, 1, "CompressGraph: adjwgt"); /* Now go and compress the graph */ iset(nvtxs, -1, mark); l = cxadj[0] = 0; for (i=0; invtxs = cnvtxs; graph->nedges = l; graph->ncon = 1; SetupGraph_tvwgt(graph); SetupGraph_label(graph); } gk_free((void **)&keys, &map, &mark, LTERM); return graph; } /*************************************************************************/ /*! This function prunes all the vertices in a graph with degree greater than factor*average. \returns the number of vertices that were prunned. */ /*************************************************************************/ graph_t *PruneGraph(ctrl_t *ctrl, idx_t nvtxs, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *iperm, real_t factor) { idx_t i, j, k, l, nlarge, pnvtxs, pnedges; idx_t *pxadj, *padjncy, *padjwgt, *pvwgt; idx_t *perm; graph_t *graph=NULL; perm = imalloc(nvtxs, "PruneGraph: perm"); factor = factor*xadj[nvtxs]/nvtxs; pnvtxs = pnedges = nlarge = 0; for (i=0; idbglvl, METIS_DBG_INFO, printf(" Pruned %"PRIDX" of %"PRIDX" vertices.\n", nlarge, nvtxs)); if (nlarge > 0 && nlarge < nvtxs) { /* Prunning is possible, so go ahead and create the prunned graph */ graph = CreateGraph(); /* Allocate memory for the prunned graph*/ pxadj = graph->xadj = imalloc(pnvtxs+1, "PruneGraph: xadj"); pvwgt = graph->vwgt = imalloc(pnvtxs, "PruneGraph: vwgt"); padjncy = graph->adjncy = imalloc(pnedges, "PruneGraph: adjncy"); graph->adjwgt = ismalloc(pnedges, 1, "PruneGraph: adjwgt"); pxadj[0] = pnedges = l = 0; for (i=0; invtxs = pnvtxs; graph->nedges = pnedges; graph->ncon = 1; SetupGraph_tvwgt(graph); SetupGraph_label(graph); } else if (nlarge > 0 && nlarge == nvtxs) { IFSET(ctrl->dbglvl, METIS_DBG_INFO, printf(" Pruning is ignored as it removes all vertices.\n")); nlarge = 0; } gk_free((void **)&perm, LTERM); return graph; }