26 for (cut=0, i=0; i<graph->
nvtxs; i++) {
27 for (j=graph->
xadj[i]; j<graph->
xadj[i+1]; j++)
28 if (where[i] != where[graph->
adjncy[j]])
33 for (cut=0, i=0; i<graph->
nvtxs; i++) {
34 for (j=graph->
xadj[i]; j<graph->
xadj[i+1]; j++)
35 if (where[i] != where[graph->
adjncy[j]])
59 nparts = where[
iargmax(nvtxs, where)]+1;
60 marker =
ismalloc(nparts, -1,
"ComputeVolume: marker");
64 for (i=0; i<nvtxs; i++) {
66 for (j=xadj[i]; j<xadj[i+1]; j++) {
70 totalv += (vsize ? vsize[
i] : 1);
90 cuts =
ismalloc(nparts, 0,
"ComputeMaxCut: cuts");
93 for (i=0; i<graph->
nvtxs; i++) {
94 for (j=graph->
xadj[i]; j<graph->
xadj[i+1]; j++)
95 if (where[i] != where[graph->
adjncy[j]])
100 for (i=0; i<graph->
nvtxs; i++) {
101 for (j=graph->
xadj[i]; j<graph->
xadj[i+1]; j++)
102 if (where[i] != where[graph->
adjncy[j]])
107 maxcut = cuts[
iargmax(nparts, cuts)];
109 printf(
"%zu => %"PRIDX"\n",
iargmax(nparts, cuts), maxcut);
126 nvtxs = graph->
nvtxs;
129 where = graph->
where;
133 for (nbnd=0, i=0; i<nvtxs; i++) {
134 if (xadj[i+1]-xadj[i] == 0)
137 for (j=xadj[i]; j<xadj[i+1]; j++) {
138 if (where[i] != where[adjncy[j]]) {
141 ASSERT(bndind[bndptr[i]] == i);
163 nvtxs = graph->
nvtxs;
166 where = graph->
where;
170 for (nbnd=0, i=0; i<nvtxs; i++) {
172 for (j=xadj[i]; j<xadj[i+1]; j++) {
173 if (where[i] != where[adjncy[j]])
178 if (ed -
id >= 0 && xadj[i] < xadj[i+1]) {
181 ASSERT(bndind[bndptr[i]] == i);
200 nvtxs = graph->
nvtxs;
203 where = graph->
where;
207 for (nbnd=0, i=0; i<nvtxs; i++) {
214 for (i=0; i<nvtxs; i++) {
216 ASSERTP(bndptr[i] == -1, (
"%"PRIDX
" %"PRIDX
"\n", i, bndptr[i]));
219 ASSERTP(bndptr[i] != -1, (
"%"PRIDX
" %"PRIDX
"\n", i, bndptr[i]));
239 for (i=0; i<rinfo->
nnbrs; i++) {
240 for (j=i+1; j<rinfo->
nnbrs; j++)
241 ASSERTP(nbrs[i].pid != nbrs[j].pid,
243 i, j, nbrs[i].pid, nbrs[j].pid));
259 idx_t edegrees[2], pwgts[3];
261 nvtxs = graph->
nvtxs;
266 where = graph->
where;
271 pwgts[0] = pwgts[1] = pwgts[2] = 0;
272 for (i=0; i<nvtxs; i++) {
274 pwgts[me] += vwgt[
i];
277 edegrees[0] = edegrees[1] = 0;
279 for (j=xadj[i]; j<xadj[i+1]; j++) {
280 other = where[adjncy[
j]];
282 edegrees[
other] += vwgt[adjncy[
j]];
287 i, edegrees[0], edegrees[1],
294 if (pwgts[0] != graph->
pwgts[0] ||
295 pwgts[1] != graph->
pwgts[1] ||
296 pwgts[2] != graph->
pwgts[2]) {
314 nvtxs = graph->
nvtxs;
317 where = graph->
where;
319 for (i=0; i<nvtxs; i++) {
322 other = (where[
i]+1)%2;
323 for (j=xadj[i]; j<xadj[i+1]; j++) {
324 ASSERTP(where[adjncy[j]] != other,
326 i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i],
327 xadj[adjncy[j]+1]-xadj[adjncy[j]]));
341 idx_t i, ii,
j, k, kk,
l, nvtxs, nbnd, mincut, minvol, me,
other, pid;
343 vkrinfo_t *rinfo, *myrinfo, *orinfo, tmprinfo;
344 vnbr_t *mynbrs, *onbrs, *tmpnbrs;
348 nvtxs = graph->
nvtxs;
350 vsize = graph->
vsize;
352 where = graph->
where;
360 for (i=0; i<nvtxs; i++) {
366 for (k=0; k<myrinfo->
nnbrs; k++)
367 tmpnbrs[k] = mynbrs[k];
370 tmprinfo.
nid = myrinfo->
nid;
371 tmprinfo.
ned = myrinfo->
ned;
376 for (k=0; k<myrinfo->
nnbrs; k++)
379 for (j=xadj[i]; j<xadj[i+1]; j++) {
387 for (k=0; k<myrinfo->
nnbrs; k++) {
389 for (kk=0; kk<orinfo->
nnbrs; kk++) {
390 if (onbrs[kk].pid == pid)
393 if (kk == orinfo->
nnbrs)
394 mynbrs[k].
gv -= vsize[ii];
399 for (k=0; k<orinfo->
nnbrs; k++) {
400 if (onbrs[k].pid == me)
404 if (onbrs[k].ned == 1) {
405 for (k=0; k<myrinfo->
nnbrs; k++) {
406 if (mynbrs[k].pid == other) {
407 mynbrs[k].
gv += vsize[ii];
413 for (k=0; k<myrinfo->
nnbrs; k++) {
414 if ((pid = mynbrs[k].pid) ==
other)
416 for (kk=0; kk<orinfo->
nnbrs; kk++) {
417 if (onbrs[kk].pid == pid) {
418 mynbrs[k].
gv += vsize[ii];
427 for (k=0; k<myrinfo->
nnbrs; k++) {
428 if ((pid = mynbrs[k].pid) ==
other)
430 for (kk=0; kk<orinfo->
nnbrs; kk++) {
431 if (onbrs[kk].pid == pid)
434 if (kk == orinfo->
nnbrs)
435 mynbrs[k].
gv -= vsize[ii];
444 for (k=0; k<myrinfo->
nnbrs; k++) {
446 for (kk=0; kk<tmprinfo.
nnbrs; kk++) {
447 if (tmpnbrs[kk].pid == pid) {
448 if (tmpnbrs[kk].gv != mynbrs[k].gv)
450 i, where[i], pid, mynbrs[k].gv, tmpnbrs[kk].gv);
idx_t CheckNodeBnd(graph_t *graph, idx_t onbnd)
idx_t idx_t idx_t idx_t * vwgt
idx_t IsSeparable(graph_t *graph)
#define ASSERTP(expr, msg)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t * nparts
NonlinearFactorGraph graph
static const Similarity3 id
idx_t idx_t idx_t idx_t idx_t * vsize
#define ASSERT(expression)
idx_t CheckNodePartitionParams(graph_t *graph)
static const Line3 l(Rot3(), 1, 1)
idx_t ComputeCut(graph_t *graph, idx_t *where)
idx_t CheckBnd2(graph_t *graph)
idx_t idx_t idx_t idx_t idx_t idx_t * adjwgt
void gk_free(void **ptr1,...)
idx_t idx_t idx_t idx_t * where
idx_t CheckBnd(graph_t *graph)
idx_t idx_t idx_t * adjncy
idx_t ComputeVolume(graph_t *graph, idx_t *where)
idx_t ComputeMaxCut(graph_t *graph, idx_t nparts, idx_t *where)
void CheckKWayVolPartitionParams(ctrl_t *ctrl, graph_t *graph)
idx_t CheckRInfo(ctrl_t *ctrl, ckrinfo_t *rinfo)