28 idx_t i, ii, iii,
j, jj, k,
l, cnvtxs, cnedges;
29 idx_t *cxadj, *cadjncy, *cvwgt, *mark, *map;
33 mark =
ismalloc(nvtxs, -1,
"CompressGraph: mark");
34 map =
ismalloc(nvtxs, -1,
"CompressGraph: map");
35 keys =
ikvmalloc(nvtxs,
"CompressGraph: keys");
38 for (i=0; i<nvtxs; i++) {
40 for (j=xadj[i]; j<xadj[i+1]; j++)
49 for (cnvtxs=i=0; i<nvtxs; i++) {
53 for (j=xadj[ii]; j<xadj[ii+1]; j++)
59 for (j=i+1; j<nvtxs; j++) {
62 if (keys[i].
key != keys[j].
key || xadj[ii+1]-xadj[ii] != xadj[iii+1]-xadj[iii])
66 for (jj=xadj[iii]; jj<xadj[iii+1]; jj++) {
67 if (mark[adjncy[jj]] != i)
71 if (jj == xadj[iii+1]) {
83 printf(
" Compression: reduction in # of vertices: %"PRIDX".\n", nvtxs-cnvtxs));
93 for (i=0; i<cnvtxs; i++) {
95 cnedges += xadj[ii+1]-xadj[ii];
99 cxadj = graph->
xadj =
imalloc(cnvtxs+1,
"CompressGraph: xadj");
100 cvwgt = graph->
vwgt =
ismalloc(cnvtxs, 0,
"CompressGraph: vwgt");
101 cadjncy = graph->
adjncy =
imalloc(cnedges,
"CompressGraph: adjncy");
105 iset(nvtxs, -1, mark);
107 for (i=0; i<cnvtxs; i++) {
109 for (j=cptr[i]; j<cptr[i+1]; j++) {
113 cvwgt[
i] += (vwgt ==
NULL ? 1 : vwgt[ii]);
116 for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) {
127 graph->
nvtxs = cnvtxs;
153 idx_t i,
j, k,
l, nlarge, pnvtxs, pnedges;
154 idx_t *pxadj, *padjncy, *padjwgt, *pvwgt;
158 perm =
imalloc(nvtxs,
"PruneGraph: perm");
160 factor = factor*xadj[nvtxs]/nvtxs;
162 pnvtxs = pnedges = nlarge = 0;
163 for (i=0; i<nvtxs; i++) {
164 if (xadj[i+1]-xadj[i] < factor) {
167 pnedges += xadj[i+1]-xadj[
i];
170 perm[
i] = nvtxs - ++nlarge;
171 iperm[nvtxs-nlarge] =
i;
176 printf(
" Pruned %"PRIDX" of %"PRIDX" vertices.\n", nlarge, nvtxs));
179 if (nlarge > 0 && nlarge < nvtxs) {
184 pxadj = graph->
xadj =
imalloc(pnvtxs+1,
"PruneGraph: xadj");
185 pvwgt = graph->
vwgt =
imalloc(pnvtxs,
"PruneGraph: vwgt");
186 padjncy = graph->
adjncy =
imalloc(pnedges,
"PruneGraph: adjncy");
189 pxadj[0] = pnedges = l = 0;
190 for (i=0; i<nvtxs; i++) {
191 if (xadj[i+1]-xadj[i] < factor) {
192 pvwgt[
l] = (vwgt ==
NULL ? 1 : vwgt[
i]);
194 for (j=xadj[i]; j<xadj[i+1]; j++) {
197 padjncy[pnedges++] = k;
199 pxadj[++
l] = pnedges;
203 graph->
nvtxs = pnvtxs;
210 else if (nlarge > 0 && nlarge == nvtxs) {
212 printf(
" Pruning is ignored as it removes all vertices.\n"));
const gtsam::Symbol key('X', 0)
idx_t idx_t idx_t idx_t * vwgt
#define COMPRESSION_FRACTION
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 idx_t idx_t idx_t idx_t idx_t * iperm
NonlinearFactorGraph graph
static const Line3 l(Rot3(), 1, 1)
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 idx_t idx_t idx_t idx_t * perm
void gk_free(void **ptr1,...)
idx_t idx_t idx_t * adjncy
#define IFSET(a, flag, cmd)