int flatten ( struct vtx_data **graph, /* array of vtx data for graph */ int nvtxs, /* number of vertices in graph */ int nedges, /* number of edges in graph */ struct vtx_data ***pcgraph, /* coarsened version of graph */ int *pcnvtxs, /* number of vtxs in coarsened graph */ int *pcnedges, /* number of edges in coarsened graph */ int **pv2cv, /* pointer to v2cv */ int using_ewgts, /* are edge weights being used? */ int igeom, /* dimensions of geometric data */ float **coords, /* coordinates for vertices */ float **ccoords /* coordinates for coarsened vertices */ ) { double Thresh; /* minimal acceptable size reduction */ int *v2cv; /* map from vtxs to coarse vtxs */ int cnvtxs; /* number of vertices in flattened graph */ void find_flat(), makefgraph(); Thresh = .9; v2cv = smalloc((nvtxs + 1) * sizeof(int)); find_flat(graph, nvtxs, &cnvtxs, v2cv); if (cnvtxs <= Thresh * nvtxs) { /* Sufficient shrinkage? */ makefgraph(graph, nvtxs, nedges, pcgraph, cnvtxs, pcnedges, v2cv, using_ewgts, igeom, coords, ccoords); *pcnvtxs = cnvtxs; *pv2cv = v2cv; return (TRUE); } else { /* Not worth bothering */ sfree(v2cv); return (FALSE); } }
void coarsen1 ( struct vtx_data **graph, /* array of vtx data for graph */ int nvtxs, /* number of vertices in graph */ int nedges, /* number of edges in graph */ struct vtx_data ***pcgraph, /* coarsened version of graph */ int *pcnvtxs, /* number of vtxs in coarsened graph */ int *pcnedges, /* number of edges in coarsened graph */ int **pv2cv, /* pointer to v2cv */ int igeom, /* dimension for geometric information */ float **coords, /* coordinates for vertices */ float **ccoords, /* coordinates for coarsened vertices */ int using_ewgts /* are edge weights being used? */ ) { extern double coarsen_time; extern double match_time; double time; /* time routine is entered */ int *v2cv; /* maps from vtxs to cvtxs */ int *mflag; /* flag indicating vtx matched or not */ int cnvtxs; /* number of vtxs in coarse graph */ int nmerged; /* number of edges contracted */ double seconds(); int maxmatch(); void makev2cv(), makefgraph(); time = seconds(); /* Allocate and initialize space. */ v2cv = smalloc((nvtxs + 1) * sizeof(int)); mflag = smalloc((nvtxs + 1) * sizeof(int)); /* Find a maximal matching in the graph. */ nmerged = maxmatch(graph, nvtxs, nedges, mflag, using_ewgts, igeom, coords); match_time += seconds() - time; /* Now construct coarser graph by contracting along matching edges. */ /* Pairs of values in mflag array indicate matched vertices. */ /* A zero value indicates that vertex is unmatched. */ /* makecgraph(graph, nvtxs, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, using_ewgts, igeom, coords, ccoords); makecgraph2(graph, nvtxs, nedges, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, using_ewgts, igeom, coords, ccoords); */ makev2cv(mflag, nvtxs, v2cv); sfree(mflag); cnvtxs = nvtxs - nmerged; makefgraph(graph, nvtxs, nedges, pcgraph, cnvtxs, pcnedges, v2cv, using_ewgts, igeom, coords, ccoords); *pcnvtxs = cnvtxs; *pv2cv = v2cv; coarsen_time += seconds() - time; }