本文整理汇总了C++中idxwspacemalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ idxwspacemalloc函数的具体用法?C++ idxwspacemalloc怎么用?C++ idxwspacemalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了idxwspacemalloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Match_HEM
/*************************************************************************
* This function finds a matching using the HEM heuristic
**************************************************************************/
void Match_HEM(CtrlType *ctrl, GraphType *graph)
{
int i, ii, j, k, nvtxs, cnvtxs, maxidx, maxwgt;
idxtype *xadj, *vwgt, *adjncy, *adjwgt;
idxtype *match, *cmap, *perm;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr));
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
cmap = graph->cmap;
match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs));
perm = idxwspacemalloc(ctrl, nvtxs);
RandomPermute(nvtxs, perm, 1);
cnvtxs = 0;
for (ii=0; ii<nvtxs; ii++) {
i = perm[ii];
if (match[i] == UNMATCHED) { /* Unmatched */
maxidx = i;
maxwgt = 0;
/* Find a heavy-edge matching, subject to maxvwgt constraints */
for (j=xadj[i]; j<xadj[i+1]; j++) {
k = adjncy[j];
if (match[k] == UNMATCHED && maxwgt < adjwgt[j] && vwgt[i]+vwgt[k] <= ctrl->maxvwgt) {
maxwgt = adjwgt[j];
maxidx = adjncy[j];
}
}
cmap[i] = cmap[maxidx] = cnvtxs++;
match[i] = maxidx;
match[maxidx] = i;
}
}
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr));
CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm);
idxwspacefree(ctrl, nvtxs);
idxwspacefree(ctrl, nvtxs);
}
开发者ID:Ascronia,项目名称:fieldtrip,代码行数:53,代码来源:match.c
示例2: ConstructSeparator
/*************************************************************************
* This function takes a bisection and constructs a minimum weight vertex
* separator out of it. It uses the node-based separator refinement for it.
**************************************************************************/
void ConstructSeparator(CtrlType *ctrl, GraphType *graph, float ubfactor)
{
int i, j, k, nvtxs, nbnd;
idxtype *xadj, *where, *bndind;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
nbnd = graph->nbnd;
bndind = graph->bndind;
where = idxcopy(nvtxs, graph->where, idxwspacemalloc(ctrl, nvtxs));
/* Put the nodes in the boundary into the separator */
for (i=0; i<nbnd; i++) {
j = bndind[i];
if (xadj[j+1]-xadj[j] > 0) /* Ignore islands */
where[j] = 2;
}
GKfree(&graph->rdata, LTERM);
Allocate2WayNodePartitionMemory(ctrl, graph);
idxcopy(nvtxs, where, graph->where);
idxwspacefree(ctrl, nvtxs);
ASSERT(IsSeparable(graph));
Compute2WayNodePartitionParams(ctrl, graph);
ASSERT(CheckNodePartitionParams(graph));
FM_2WayNodeRefine(ctrl, graph, ubfactor, 8);
ASSERT(IsSeparable(graph));
}
开发者ID:Nasrollah,项目名称:phasta,代码行数:38,代码来源:separator.c
示例3: Match_RM_NVW
/*************************************************************************
* This function finds a matching using the HEM heuristic
**************************************************************************/
void Match_RM_NVW(CtrlType *ctrl, GraphType *graph)
{
int i, ii, j, nvtxs, cnvtxs, maxidx;
idxtype *xadj, *adjncy;
idxtype *match, *cmap, *perm;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr));
nvtxs = graph->nvtxs;
xadj = graph->xadj;
adjncy = graph->adjncy;
cmap = graph->cmap;
match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs));
perm = idxwspacemalloc(ctrl, nvtxs);
RandomPermute(nvtxs, perm, 1);
cnvtxs = 0;
for (ii=0; ii<nvtxs; ii++) {
i = perm[ii];
if (match[i] == UNMATCHED) { /* Unmatched */
maxidx = i;
/* Find a random matching, subject to maxvwgt constraints */
for (j=xadj[i]; j<xadj[i+1]; j++) {
if (match[adjncy[j]] == UNMATCHED) {
maxidx = adjncy[j];
break;
}
}
cmap[i] = cmap[maxidx] = cnvtxs++;
match[i] = maxidx;
match[maxidx] = i;
}
}
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr));
CreateCoarseGraph_NVW(ctrl, graph, cnvtxs, match, perm);
idxwspacefree(ctrl, nvtxs);
idxwspacefree(ctrl, nvtxs);
}
开发者ID:HerculesCE,项目名称:ParaView,代码行数:49,代码来源:match.c
示例4: FM_2WayNodeRefine_OneSided
/*************************************************************************
* This function performs a node-based FM refinement. This is the
* one-way version
**************************************************************************/
void FM_2WayNodeRefine_OneSided(CtrlType *ctrl, GraphType *graph, float ubfactor, idxtype npasses)
{
idxtype i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind;
idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr;
idxtype *mptr, *mind, *swaps, *perm;
PQueueType parts;
NRInfoType *rinfo;
idxtype higain, oldgain, mincut, initcut, mincutorder;
idxtype pass, to, other, limit;
idxtype badmaxpwgt, mindiff, newdiff;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
adjncy = graph->adjncy;
vwgt = graph->vwgt;
bndind = graph->bndind;
bndptr = graph->bndptr;
where = graph->where;
pwgts = graph->pwgts;
rinfo = graph->nrinfo;
PQueueInit(ctrl, &parts, nvtxs, ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt));
perm = idxwspacemalloc(ctrl, nvtxs);
swaps = idxwspacemalloc(ctrl, nvtxs);
mptr = idxwspacemalloc(ctrl, nvtxs+1);
mind = idxwspacemalloc(ctrl, nvtxs);
IFSET(ctrl->dbglvl, DBG_REFINE,
mprintf("Partitions-N1: [%6D %6D] Nv-Nb[%6D %6D]. ISep: %6D\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
badmaxpwgt = (int)(ubfactor*(pwgts[0]+pwgts[1]+pwgts[2])/2);
to = (pwgts[0] < pwgts[1] ? 1 : 0);
for (pass=0; pass<npasses; pass++) {
other = to;
to = (to+1)%2;
PQueueReset(&parts);
mincutorder = -1;
initcut = mincut = graph->mincut;
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = bndind[perm[ii]];
ASSERT(where[i] == 2);
PQueueInsert(&parts, i, vwgt[i]-rinfo[i].edegrees[other]);
}
ASSERT(CheckNodeBnd(graph, nbnd));
ASSERT(CheckNodePartitionParams(graph));
limit = (ctrl->oflags&OFLAG_COMPRESS ? amin(5*nbnd, 400) : amin(2*nbnd, 300));
/******************************************************
* Get into the FM loop
*******************************************************/
mptr[0] = nmind = 0;
mindiff = idxtype_abs(pwgts[0]-pwgts[1]);
for (nswaps=0; nswaps<nvtxs; nswaps++) {
if ((higain = PQueueGetMax(&parts)) == -1)
break;
ASSERT(bndptr[higain] != -1);
if (pwgts[to]+vwgt[higain] > badmaxpwgt)
break; /* No point going any further. Balance will be bad */
pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]);
newdiff = idxtype_abs(pwgts[to]+vwgt[higain] - (pwgts[other]-rinfo[higain].edegrees[other]));
if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) {
mincut = pwgts[2];
mincutorder = nswaps;
mindiff = newdiff;
}
else {
if (nswaps - mincutorder > limit) {
pwgts[2] += (vwgt[higain]-rinfo[higain].edegrees[other]);
break; /* No further improvement, break out */
}
}
BNDDelete(nbnd, bndind, bndptr, higain);
pwgts[to] += vwgt[higain];
where[higain] = to;
swaps[nswaps] = higain;
/**********************************************************
* Update the degrees of the affected nodes
***********************************************************/
//.........这里部分代码省略.........
开发者ID:educharlie,项目名称:HNA-Algorithm,代码行数:101,代码来源:sfm.c
示例5: FM_2WayNodeBalance
/*************************************************************************
* This function performs a node-based FM refinement
**************************************************************************/
void FM_2WayNodeBalance(CtrlType *ctrl, GraphType *graph, float ubfactor)
{
idxtype i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps;
idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr;
idxtype *perm, *moved;
PQueueType parts;
NRInfoType *rinfo;
idxtype higain, oldgain;
idxtype pass, to, other;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
adjncy = graph->adjncy;
vwgt = graph->vwgt;
bndind = graph->bndind;
bndptr = graph->bndptr;
where = graph->where;
pwgts = graph->pwgts;
rinfo = graph->nrinfo;
if (idxtype_abs(pwgts[0]-pwgts[1]) < (int)((ubfactor-1.0)*(pwgts[0]+pwgts[1])))
return;
if (idxtype_abs(pwgts[0]-pwgts[1]) < 3*idxsum(nvtxs, vwgt, 1)/nvtxs)
return;
to = (pwgts[0] < pwgts[1] ? 0 : 1);
other = (to+1)%2;
PQueueInit(ctrl, &parts, nvtxs, ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt));
perm = idxwspacemalloc(ctrl, nvtxs);
moved = idxset(nvtxs, -1, idxwspacemalloc(ctrl, nvtxs));
IFSET(ctrl->dbglvl, DBG_REFINE,
mprintf("Partitions: [%6D %6D] Nv-Nb[%6D %6D]. ISep: %6D [B]\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = bndind[perm[ii]];
ASSERT(where[i] == 2);
PQueueInsert(&parts, i, vwgt[i]-rinfo[i].edegrees[other]);
}
ASSERT(CheckNodeBnd(graph, nbnd));
ASSERT(CheckNodePartitionParams(graph));
/******************************************************
* Get into the FM loop
*******************************************************/
for (nswaps=0; nswaps<nvtxs; nswaps++) {
if ((higain = PQueueGetMax(&parts)) == -1)
break;
moved[higain] = 1;
if (pwgts[other] - rinfo[higain].edegrees[other] < (pwgts[0]+pwgts[1])/2)
continue;
#ifdef XXX
if (pwgts[other] - rinfo[higain].edegrees[other] < pwgts[to]+vwgt[higain])
break;
#endif
ASSERT(bndptr[higain] != -1);
pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]);
BNDDelete(nbnd, bndind, bndptr, higain);
pwgts[to] += vwgt[higain];
where[higain] = to;
IFSET(ctrl->dbglvl, DBG_MOVEINFO,
mprintf("Moved %6D to %3D, Gain: %3D, \t[%5D %5D %5D]\n", higain, to, vwgt[higain]-rinfo[higain].edegrees[other], pwgts[0], pwgts[1], pwgts[2]));
/**********************************************************
* Update the degrees of the affected nodes
***********************************************************/
for (j=xadj[higain]; j<xadj[higain+1]; j++) {
k = adjncy[j];
if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */
rinfo[k].edegrees[to] += vwgt[higain];
}
else if (where[k] == other) { /* This vertex is pulled into the separator */
ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k]));
BNDInsert(nbnd, bndind, bndptr, k);
where[k] = 2;
pwgts[other] -= vwgt[k];
edegrees = rinfo[k].edegrees;
edegrees[0] = edegrees[1] = 0;
for (jj=xadj[k]; jj<xadj[k+1]; jj++) {
kk = adjncy[jj];
if (where[kk] != 2)
edegrees[where[kk]] += vwgt[kk];
//.........这里部分代码省略.........
开发者ID:educharlie,项目名称:HNA-Algorithm,代码行数:101,代码来源:sfm.c
示例6: Greedy_KWayEdgeBalanceMConn
/*************************************************************************
* This function performs k-way refinement
**************************************************************************/
void Greedy_KWayEdgeBalanceMConn(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses)
{
int i, ii, iii, j, jj, k, l, pass, nvtxs, nbnd, tvwgt, myndegrees, oldgain, gain, nmoves;
int from, me, to, oldcut, vwgt, maxndoms, nadd;
idxtype *xadj, *adjncy, *adjwgt;
idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *moved, *itpwgts;
idxtype *phtable, *pmat, *pmatptr, *ndoms;
EDegreeType *myedegrees;
RInfoType *myrinfo;
PQueueType queue;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
bndind = graph->bndind;
bndptr = graph->bndptr;
where = graph->where;
pwgts = graph->pwgts;
pmat = ctrl->wspace.pmat;
phtable = idxwspacemalloc(ctrl, nparts);
ndoms = idxwspacemalloc(ctrl, nparts);
ComputeSubDomainGraph(graph, nparts, pmat, ndoms);
/* Setup the weight intervals of the various subdomains */
minwgt = idxwspacemalloc(ctrl, nparts);
maxwgt = idxwspacemalloc(ctrl, nparts);
itpwgts = idxwspacemalloc(ctrl, nparts);
tvwgt = idxsum(nparts, pwgts);
ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt));
for (i=0; i<nparts; i++) {
itpwgts[i] = tpwgts[i]*tvwgt;
maxwgt[i] = tpwgts[i]*tvwgt*ubfactor;
minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor);
}
perm = idxwspacemalloc(ctrl, nvtxs);
moved = idxwspacemalloc(ctrl, nvtxs);
PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]);
IFSET(ctrl->dbglvl, DBG_REFINE,
printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d [B]\n",
pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0],
1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd,
graph->mincut));
for (pass=0; pass<npasses; pass++) {
ASSERT(ComputeCut(graph, where) == graph->mincut);
/* Check to see if things are out of balance, given the tolerance */
for (i=0; i<nparts; i++) {
if (pwgts[i] > maxwgt[i])
break;
}
if (i == nparts) /* Things are balanced. Return right away */
break;
PQueueReset(&queue);
idxset(nvtxs, -1, moved);
oldcut = graph->mincut;
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = bndind[perm[ii]];
PQueueInsert(&queue, i, graph->rinfo[i].ed - graph->rinfo[i].id);
moved[i] = 2;
}
maxndoms = ndoms[idxamax(nparts, ndoms)];
for (nmoves=0;;) {
if ((i = PQueueGetMax(&queue)) == -1)
break;
moved[i] = 1;
myrinfo = graph->rinfo+i;
from = where[i];
vwgt = graph->vwgt[i];
if (pwgts[from]-vwgt < minwgt[from])
continue; /* This cannot be moved! */
myedegrees = myrinfo->edegrees;
myndegrees = myrinfo->ndegrees;
/* Determine the valid domains */
for (j=0; j<myndegrees; j++) {
to = myedegrees[j].pid;
//.........这里部分代码省略.........
开发者ID:kelseym,项目名称:microstates,代码行数:101,代码来源:subdomains.c
示例7: SplitGraphPart
/*************************************************************************
* This function takes a graph and a bisection and splits it into two graphs.
**************************************************************************/
void SplitGraphPart(CtrlType *ctrl, GraphType *graph, GraphType *lgraph, GraphType *rgraph)
{
int i, j, k, kk, l, istart, iend, mypart, nvtxs, ncon, snvtxs[2], snedges[2], sum;
idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr;
idxtype *sxadj[2], *svwgt[2], *sadjncy[2], *sadjwgt[2], *sadjwgtsum[2], *slabel[2];
idxtype *rename;
idxtype *auxadjncy, *auxadjwgt;
floattype *nvwgt, *snvwgt[2], *npwgts;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr));
nvtxs = graph->nvtxs;
ncon = graph->ncon;
xadj = graph->xadj;
vwgt = graph->vwgt;
nvwgt = graph->nvwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
adjwgtsum = graph->adjwgtsum;
label = graph->label;
where = graph->where;
bndptr = graph->bndptr;
npwgts = graph->npwgts;
ASSERT(bndptr != NULL);
rename = idxwspacemalloc(ctrl, nvtxs);
snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0;
for (i=0; i<nvtxs; i++) {
k = where[i];
rename[i] = snvtxs[k]++;
snedges[k] += xadj[i+1]-xadj[i];
}
SetUpSplitGraph(graph, lgraph, snvtxs[0], snedges[0]);
sxadj[0] = lgraph->xadj;
svwgt[0] = lgraph->vwgt;
snvwgt[0] = lgraph->nvwgt;
sadjwgtsum[0] = lgraph->adjwgtsum;
sadjncy[0] = lgraph->adjncy;
sadjwgt[0] = lgraph->adjwgt;
slabel[0] = lgraph->label;
SetUpSplitGraph(graph, rgraph, snvtxs[1], snedges[1]);
sxadj[1] = rgraph->xadj;
svwgt[1] = rgraph->vwgt;
snvwgt[1] = rgraph->nvwgt;
sadjwgtsum[1] = rgraph->adjwgtsum;
sadjncy[1] = rgraph->adjncy;
sadjwgt[1] = rgraph->adjwgt;
slabel[1] = rgraph->label;
snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0;
sxadj[0][0] = sxadj[1][0] = 0;
for (i=0; i<nvtxs; i++) {
mypart = where[i];
sum = adjwgtsum[i];
istart = xadj[i];
iend = xadj[i+1];
if (bndptr[i] == -1) { /* This is an interior vertex */
auxadjncy = sadjncy[mypart] + snedges[mypart] - istart;
auxadjwgt = sadjwgt[mypart] + snedges[mypart] - istart;
for(j=istart; j<iend; j++) {
auxadjncy[j] = adjncy[j];
auxadjwgt[j] = adjwgt[j];
}
snedges[mypart] += iend-istart;
}
else {
auxadjncy = sadjncy[mypart];
auxadjwgt = sadjwgt[mypart];
l = snedges[mypart];
for (j=istart; j<iend; j++) {
k = adjncy[j];
if (where[k] == mypart) {
auxadjncy[l] = k;
auxadjwgt[l++] = adjwgt[j];
}
else {
sum -= adjwgt[j];
}
}
snedges[mypart] = l;
}
if (ncon == 1)
svwgt[mypart][snvtxs[mypart]] = vwgt[i];
else {
for (kk=0; kk<ncon; kk++)
snvwgt[mypart][snvtxs[mypart]*ncon+kk] = nvwgt[i*ncon+kk]/npwgts[mypart*ncon+kk];
}
sadjwgtsum[mypart][snvtxs[mypart]] = sum;
slabel[mypart][snvtxs[mypart]] = label[i];
//.........这里部分代码省略.........
开发者ID:davidheryanto,项目名称:sc14,代码行数:101,代码来源:pmetis.c
示例8: Match_SHEM
/*************************************************************************
* This function finds a matching using the HEM heuristic
**************************************************************************/
void Match_SHEM(CtrlType *ctrl, GraphType *graph)
{
int i, ii, j, k, nvtxs, cnvtxs, maxidx, maxwgt, avgdegree;
idxtype *xadj, *vwgt, *adjncy, *adjwgt;
idxtype *match, *cmap, *degrees, *perm, *tperm;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr));
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
cmap = graph->cmap;
match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs));
perm = idxwspacemalloc(ctrl, nvtxs);
tperm = idxwspacemalloc(ctrl, nvtxs);
degrees = idxwspacemalloc(ctrl, nvtxs);
RandomPermute(nvtxs, tperm, 1);
avgdegree = 0.7*(xadj[nvtxs]/nvtxs);
for (i=0; i<nvtxs; i++)
degrees[i] = (xadj[i+1]-xadj[i] > avgdegree ? avgdegree : xadj[i+1]-xadj[i]);
BucketSortKeysInc(nvtxs, avgdegree, degrees, tperm, perm);
cnvtxs = 0;
/* Take care any islands. Islands are matched with non-islands due to coarsening */
for (ii=0; ii<nvtxs; ii++) {
i = perm[ii];
if (match[i] == UNMATCHED) { /* Unmatched */
if (xadj[i] < xadj[i+1])
break;
maxidx = i;
for (j=nvtxs-1; j>ii; j--) {
k = perm[j];
if (match[k] == UNMATCHED && xadj[k] < xadj[k+1]) {
maxidx = k;
break;
}
}
cmap[i] = cmap[maxidx] = cnvtxs++;
match[i] = maxidx;
match[maxidx] = i;
}
}
/* Continue with normal matching */
for (; ii<nvtxs; ii++) {
i = perm[ii];
if (match[i] == UNMATCHED) { /* Unmatched */
maxidx = i;
maxwgt = 0;
/* Find a heavy-edge matching, subject to maxvwgt constraints */
for (j=xadj[i]; j<xadj[i+1]; j++) {
if (match[adjncy[j]] == UNMATCHED && maxwgt < adjwgt[j] && vwgt[i]+vwgt[adjncy[j]] <= ctrl->maxvwgt) {
maxwgt = adjwgt[j];
maxidx = adjncy[j];
}
}
cmap[i] = cmap[maxidx] = cnvtxs++;
match[i] = maxidx;
match[maxidx] = i;
}
}
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr));
idxwspacefree(ctrl, nvtxs); /* degrees */
idxwspacefree(ctrl, nvtxs); /* tperm */
CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm);
idxwspacefree(ctrl, nvtxs);
idxwspacefree(ctrl, nvtxs);
}
开发者ID:HerculesCE,项目名称:ParaView,代码行数:87,代码来源:match.c
示例9: Bnd2WayBalance
/*************************************************************************
* This function balances two partitions by moving boundary nodes
* from the domain that is overweight to the one that is underweight.
**************************************************************************/
void Bnd2WayBalance(CtrlType *ctrl, GraphType *graph, int *tpwgts)
{
int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, tmp;
idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts;
idxtype *moved, *perm;
PQueueType parts;
int higain, oldgain, mincut, mindiff;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
where = graph->where;
id = graph->id;
ed = graph->ed;
pwgts = graph->pwgts;
bndptr = graph->bndptr;
bndind = graph->bndind;
moved = idxwspacemalloc(ctrl, nvtxs);
perm = idxwspacemalloc(ctrl, nvtxs);
/* Determine from which domain you will be moving data */
mindiff = abs(tpwgts[0]-pwgts[0]);
from = (pwgts[0] < tpwgts[0] ? 1 : 0);
to = (from+1)%2;
IFSET(ctrl->dbglvl, DBG_REFINE,
printf("Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d [B]\n",
pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
tmp = graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)];
PQueueInit(ctrl, &parts, nvtxs, tmp);
idxset(nvtxs, -1, moved);
ASSERT(ComputeCut(graph, where) == graph->mincut);
ASSERT(CheckBnd(graph));
/* Insert the boundary nodes of the proper partition whose size is OK in the priority queue */
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = perm[ii];
ASSERT(ed[bndind[i]] > 0 || id[bndind[i]] == 0);
ASSERT(bndptr[bndind[i]] != -1);
if (where[bndind[i]] == from && vwgt[bndind[i]] <= mindiff)
PQueueInsert(&parts, bndind[i], ed[bndind[i]]-id[bndind[i]]);
}
mincut = graph->mincut;
for (nswaps=0; nswaps<nvtxs; nswaps++) {
if ((higain = PQueueGetMax(&parts)) == -1)
break;
ASSERT(bndptr[higain] != -1);
if (pwgts[to]+vwgt[higain] > tpwgts[to])
break;
mincut -= (ed[higain]-id[higain]);
INC_DEC(pwgts[to], pwgts[from], vwgt[higain]);
where[higain] = to;
moved[higain] = nswaps;
IFSET(ctrl->dbglvl, DBG_MOVEINFO,
printf("Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1]));
/**************************************************************
* Update the id[i]/ed[i] values of the affected nodes
***************************************************************/
SWAP(id[higain], ed[higain], tmp);
if (ed[higain] == 0 && xadj[higain] < xadj[higain+1])
BNDDelete(nbnd, bndind, bndptr, higain);
for (j=xadj[higain]; j<xadj[higain+1]; j++) {
k = adjncy[j];
oldgain = ed[k]-id[k];
kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]);
INC_DEC(id[k], ed[k], kwgt);
/* Update its boundary information and queue position */
if (bndptr[k] != -1) { /* If k was a boundary vertex */
if (ed[k] == 0) { /* Not a boundary vertex any more */
BNDDelete(nbnd, bndind, bndptr, k);
if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff) /* Remove it if in the queues */
PQueueDelete(&parts, k, oldgain);
}
else { /* If it has not been moved, update its position in the queue */
if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff)
PQueueUpdate(&parts, k, oldgain, ed[k]-id[k]);
}
}
else {
//.........这里部分代码省略.........
开发者ID:arjunroy,项目名称:modelnet-core,代码行数:101,代码来源:balance.c
示例10: FM_2WayEdgeRefine
/*************************************************************************
* This function performs an edge-based FM refinement
**************************************************************************/
void FM_2WayEdgeRefine(CtrlType *ctrl, GraphType *graph, int *tpwgts, int npasses)
{
int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, limit, tmp;
idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts;
idxtype *moved, *swaps, *perm;
PQueueType parts[2];
int higain, oldgain, mincut, mindiff, origdiff, initcut, newcut, mincutorder, avgvwgt;
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
where = graph->where;
id = graph->id;
ed = graph->ed;
pwgts = graph->pwgts;
bndptr = graph->bndptr;
bndind = graph->bndind;
moved = idxwspacemalloc(ctrl, nvtxs);
swaps = idxwspacemalloc(ctrl, nvtxs);
perm = idxwspacemalloc(ctrl, nvtxs);
limit = (int) amin(amax(0.01*nvtxs, 15), 100);
avgvwgt = amin((pwgts[0]+pwgts[1])/20, 2*(pwgts[0]+pwgts[1])/nvtxs);
tmp = graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)];
PQueueInit(ctrl, &parts[0], nvtxs, tmp);
PQueueInit(ctrl, &parts[1], nvtxs, tmp);
IFSET(ctrl->dbglvl, DBG_REFINE,
printf("Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d\n",
pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
origdiff = abs(tpwgts[0]-pwgts[0]);
idxset(nvtxs, -1, moved);
for (pass=0; pass<npasses; pass++) { /* Do a number of passes */
PQueueReset(&parts[0]);
PQueueReset(&parts[1]);
mincutorder = -1;
newcut = mincut = initcut = graph->mincut;
mindiff = abs(tpwgts[0]-pwgts[0]);
ASSERT(ComputeCut(graph, where) == graph->mincut);
ASSERT(CheckBnd(graph));
/* Insert boundary nodes in the priority queues */
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = perm[ii];
ASSERT(ed[bndind[i]] > 0 || id[bndind[i]] == 0);
ASSERT(bndptr[bndind[i]] != -1);
PQueueInsert(&parts[where[bndind[i]]], bndind[i], ed[bndind[i]]-id[bndind[i]]);
}
for (nswaps=0; nswaps<nvtxs; nswaps++) {
from = (tpwgts[0]-pwgts[0] < tpwgts[1]-pwgts[1] ? 0 : 1);
to = (from+1)%2;
if ((higain = PQueueGetMax(&parts[from])) == -1)
break;
ASSERT(bndptr[higain] != -1);
newcut -= (ed[higain]-id[higain]);
INC_DEC(pwgts[to], pwgts[from], vwgt[higain]);
if ((newcut < mincut && abs(tpwgts[0]-pwgts[0]) <= origdiff+avgvwgt) ||
(newcut == mincut && abs(tpwgts[0]-pwgts[0]) < mindiff)) {
mincut = newcut;
mindiff = abs(tpwgts[0]-pwgts[0]);
mincutorder = nswaps;
}
else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */
newcut += (ed[higain]-id[higain]);
INC_DEC(pwgts[from], pwgts[to], vwgt[higain]);
break;
}
where[higain] = to;
moved[higain] = nswaps;
swaps[nswaps] = higain;
IFSET(ctrl->dbglvl, DBG_MOVEINFO,
printf("Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-id[higain], vwgt[higain], newcut, pwgts[0], pwgts[1]));
/**************************************************************
* Update the id[i]/ed[i] values of the affected nodes
***************************************************************/
SWAP(id[higain], ed[higain], tmp);
if (ed[higain] == 0 && xadj[higain] < xadj[higain+1])
BNDDelete(nbnd, bndind, bndptr, higain);
for (j=xadj[higain]; j<xadj[higain+1]; j++) {
k = adjncy[j];
//.........这里部分代码省略.........
开发者ID:AIBluefisher,项目名称:GraphCluster,代码行数:101,代码来源:fm.c
示例11: MCRandom_KWayEdgeRefineHorizontal
/*************************************************************************
* This function performs k-way refinement
**************************************************************************/
void MCRandom_KWayEdgeRefineHorizontal(CtrlType *ctrl, GraphType *graph, int nparts,
float *orgubvec, int npasses)
{
int i, ii, iii, j, /*jj,*/ k, /*l,*/ pass, nvtxs, ncon, nmoves, nbnd, myndegrees, same;
int from, me, to, oldcut, gain;
idxtype *xadj, *adjncy, *adjwgt;
idxtype *where, *perm, *bndptr, *bndind;
EDegreeType *myedegrees;
RInfoType *myrinfo;
float *npwgts, *nvwgt, *minwgt, *maxwgt, maxlb, minlb, ubvec[MAXNCON], tvec[MAXNCON];
nvtxs = graph->nvtxs;
ncon = graph->ncon;
xadj = graph->xadj;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
bndptr = graph->bndptr;
bndind = graph->bndind;
where = graph->where;
npwgts = graph->npwgts;
/* Setup the weight intervals of the various subdomains */
minwgt = fwspacemalloc(ctrl, nparts*ncon);
maxwgt = fwspacemalloc(ctrl, nparts*ncon);
/* See if the orgubvec consists of identical constraints */
maxlb = minlb = orgubvec[0];
for (i=1; i<ncon; i++) {
minlb = (orgubvec[i] < minlb ? orgubvec[i] : minlb);
maxlb = (orgubvec[i] > maxlb ? orgubvec[i] : maxlb);
}
same = (fabs(maxlb-minlb) < .01 ? 1 : 0);
/* Let's not get very optimistic. Let Balancing do the work */
ComputeHKWayLoadImbalance(ncon, nparts, npwgts, ubvec);
for (i=0; i<ncon; i++)
ubvec[i] = amax(ubvec[i], orgubvec[i]);
if (!same) {
for (i=0; i<nparts; i++) {
for (j=0; j<ncon; j++) {
maxwgt[i*ncon+j] = ubvec[j]/nparts;
minwgt[i*ncon+j] = 1.0/(ubvec[j]*nparts);
}
}
}
else {
maxlb = ubvec[0];
for (i=1; i<ncon; i++)
maxlb = (ubvec[i] > maxlb ? ubvec[i] : maxlb);
for (i=0; i<nparts; i++) {
for (j=0; j<ncon; j++) {
maxwgt[i*ncon+j] = maxlb/nparts;
minwgt[i*ncon+j] = 1.0/(maxlb*nparts);
}
}
}
perm = idxwspacemalloc(ctrl, nvtxs);
if (ctrl->dbglvl&DBG_REFINE) {
printf("Partitions: [%5.4f %5.4f], Nv-Nb[%6d %6d]. Cut: %6d, LB: ",
npwgts[samin(ncon*nparts, npwgts)], npwgts[samax(ncon*nparts, npwgts)],
graph->nvtxs, graph->nbnd, graph->mincut);
ComputeHKWayLoadImbalance(ncon, nparts, npwgts, tvec);
for (i=0; i<ncon; i++)
printf("%.3f ", tvec[i]);
printf("\n");
}
for (pass=0; pass<npasses; pass++) {
ASSERT(ComputeCut(graph, where) == graph->mincut);
oldcut = graph->mincut;
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (nmoves=iii=0; iii<graph->nbnd; iii++) {
ii = perm[iii];
if (ii >= nbnd)
continue;
i = bndind[ii];
myrinfo = graph->rinfo+i;
if (myrinfo->ed >= myrinfo->id) { /* Total ED is too high */
from = where[i];
nvwgt = graph->nvwgt+i*ncon;
if (myrinfo->id > 0 && AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, -1.0, nvwgt, minwgt+from*ncon))
continue; /* This cannot be moved! */
//.........这里部分代码省略.........
开发者ID:Vignesh2208,项目名称:Awlsim_Ins,代码行数:101,代码来源:mkwayfmh.c
示例12: SplitGraphOrderCC
/*************************************************************************
* This function takes a graph and a bisection and splits it into two graphs.
* It relies on the fact that adjwgt is all set to 1.
**************************************************************************/
int SplitGraphOrderCC(CtrlType *ctrl, GraphType *graph, GraphType *sgraphs, int ncmps, idxtype *cptr, idxtype *cind)
{
int i, ii, iii, j, k, l, istart, iend, mypart, nvtxs, snvtxs, snedges;
idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr, *bndind;
idxtype *sxadj, *svwgt, *sadjncy, *sadjwgt, *sadjwgtsum, *slabel;
idxtype *rename;
idxtype *auxadjncy, *auxadjwgt;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr));
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
adjwgtsum = graph->adjwgtsum;
label = graph->label;
where = graph->where;
bndptr = graph->bndptr;
bndind = graph->bndind;
ASSERT(bndptr != NULL);
/* Go and use bndptr to also mark the boundary nodes in the two partitions */
for (ii=0; ii<graph->nbnd; ii++) {
i = bndind[ii];
for (j=xadj[i]; j<xadj[i+1]; j++)
bndptr[adjncy[j]] = 1;
}
rename = idxwspacemalloc(ctrl, nvtxs);
/* Go and split the graph a component at a time */
for (iii=0; iii<ncmps; iii++) {
RandomPermute(cptr[iii+1]-cptr[iii], cind+cptr[iii], 0);
snvtxs = snedges = 0;
for (j=cptr[iii]; j<cptr[iii+1]; j++) {
i = cind[j];
rename[i] = snvtxs++;
snedges += xadj[i+1]-xadj[i];
}
SetUpSplitGraph(graph, sgraphs+iii, snvtxs, snedges);
sxadj = sgraphs[iii].xadj;
svwgt = sgraphs[iii].vwgt;
sadjwgtsum = sgraphs[iii].adjwgtsum;
sadjncy = sgraphs[iii].adjncy;
sadjwgt = sgraphs[iii].adjwgt;
slabel = sgraphs[iii].label;
snvtxs = snedges = sxadj[0] = 0;
for (ii=cptr[iii]; ii<cptr[iii+1]; ii++) {
i = cind[ii];
istart = xadj[i];
iend = xadj[i+1];
if (bndptr[i] == -1) { /* This is an interior vertex */
auxadjncy = sadjncy + snedges - istart;
auxadjwgt = sadjwgt + snedges - istart;
for(j=istart; j<iend; j++)
auxadjncy[j] = adjncy[j];
snedges += iend-istart;
}
else {
l = snedges;
for (j=istart; j<iend; j++) {
k = adjncy[j];
if (where[k] != 2)
sadjncy[l++] = k;
}
snedges = l;
}
svwgt[snvtxs] = vwgt[i];
sadjwgtsum[snvtxs] = snedges-sxadj[snvtxs];
slabel[snvtxs] = label[i];
sxadj[++snvtxs] = snedges;
}
idxset(snedges, 1, sadjwgt);
for (i=0; i<snedges; i++)
sadjncy[i] = rename[sadjncy[i]];
sgraphs[iii].nvtxs = snvtxs;
sgraphs[iii].nedges = snedges;
sgraphs[iii].ncon = 1;
if (snvtxs < MMDSWITCH)
sgraphs[iii].adjwgt = NULL; /* A marker to call MMD on the driver */
}
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SplitTmr));
idxwspacefree(ctrl, nvtxs);
return ncmps;
//.........这里部分代码省略.........
开发者ID:iyer-arvind,项目名称:gmsh,代码行数:101,代码来源:ometis.c
示例13: MocFM_2WayEdgeRefine
/*************************************************************************
* This function performs an edge-based FM refinement
**************************************************************************/
void MocFM_2WayEdgeRefine(CtrlType *ctrl, GraphType *graph, float *tpwgts, int npasses)
{
int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum;
idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind;
idxtype *moved, *swaps, *perm, *qnum;
float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal;
PQueueType parts[MAXNCON][2];
int higain, oldgain, mincut, initcut, newcut, mincutorder;
float rtpwgts[2];
nvtxs = graph->nvtxs;
ncon = graph->ncon;
xadj = graph->xadj;
nvwgt = graph->nvwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
where = graph->where;
id = graph->id;
ed = graph->ed;
npwgts = graph->npwgts;
bndptr = graph->bndptr;
bndind = graph->bndind;
moved = idxwspacemalloc(ctrl, nvtxs);
swaps = idxwspacemalloc(ctrl, nvtxs);
perm = idxwspacemalloc(ctrl, nvtxs);
qnum = idxwspacemalloc(ctrl, nvtxs);
limit = amin(amax(0.01*nvtxs, 25), 150);
/* Initialize the queues */
for (i=0; i<ncon; i++) {
PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1);
PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1);
}
for (i=0; i<nvtxs; i++)
qnum[i] = samax(ncon, nvwgt+i*ncon);
origbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts);
rtpwgts[0] = origbal*tpwgts[0];
rtpwgts[1] = origbal*tpwgts[1];
/*
if (ctrl->dbglvl&DBG_REFINE) {
printf("Parts: [");
for (l=0; l<ncon; l++)
printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]);
printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f\n", tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut, origbal);
}
*/
idxset(nvtxs, -1, moved);
for (pass=0; pass<npasses; pass++) { /* Do a number of passes */
for (i=0; i<ncon; i++) {
PQueueReset(&parts[i][0]);
PQueueReset(&parts[i][1]);
}
mincutorder = -1;
newcut = mincut = initcut = graph->mincut;
for (i=0; i<ncon; i++)
mindiff[i] = fabs(tpwgts[0]-npwgts[i]);
minbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts);
ASSERT(ComputeCut(graph, where) == graph->mincut);
ASSERT(CheckBnd(graph));
/* Insert boundary nodes in the priority queues */
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = bndind[perm[ii]];
ASSERT(ed[i] > 0 || id[i] == 0);
ASSERT(bndptr[i] != -1);
PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]);
}
for (nswaps=0; nswaps<nvtxs; nswaps++) {
SelectQueue(ncon, npwgts, rtpwgts, &from, &cnum, parts);
to = (from+1)%2;
if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1)
break;
ASSERT(bndptr[higain] != -1);
saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1);
saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1);
newcut -= (ed[higain]-id[higain]);
newbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts);
if ((newcut < mincut && newbal-origbal <= .00001) ||
(newcut == mincut && (newbal < minbal ||
(newbal == minbal && BetterBalance(ncon, npwgts, tpwgts, mindiff))))) {
mincut = newcut;
minbal = newbal;
//.........这里部分代码省略.........
开发者ID:cran,项目名称:BigQuic,代码行数:101,代码来源:mfm.c
示例14: SplitGraphOrder
/*************************************************************************
* This function takes a graph and a bisection and splits it into two graphs.
* This function relies on the fact that adjwgt is all equal to 1.
**************************************************************************/
void SplitGraphOrder(CtrlType *ctrl, GraphType *graph, GraphType *lgraph, GraphType *rgraph)
{
int i, ii, j, k, l, istart, iend, mypart, nvtxs, snvtxs[3], snedges[3];
idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr, *bndind;
idxtype *sxadj[2], *svwgt[2], *sadjncy[2], *sadjwgt[2], *sadjwgtsum[2], *slabel[2];
idxtype *rename;
idxtype *auxadjncy, *auxadjwgt;
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr));
nvtxs = graph->nvtxs;
xadj = graph->xadj;
vwgt = graph->vwgt;
adjncy = graph->adjncy;
adjwgt = graph->adjwgt;
adjwgtsum = graph->adjwgtsum;
label = graph->label;
where = graph->where;
bndptr = graph->bndptr;
bndind = graph->bndind;
ASSERT(bndptr != NULL);
rename = idxwspacemalloc(ctrl, nvtxs);
snvtxs[0] = snvtxs[1] = snvtxs[2] = snedges[0] = snedges[1] = snedges[2] = 0;
for (i=0; i<nvtxs; i++) {
k = where[i];
rename[i] = snvtxs[k]++;
snedges[k] += xadj[i+1]-xadj[i];
}
SetUpSplitGraph(graph, lgraph, snvtxs[0], snedges[0]);
sxadj[0] = lgraph->xadj;
svwgt[0] = lgraph->vwgt;
sadjwgtsum[0] = lgraph->adjwgtsum;
sadjncy[0] = lgraph->adjncy;
sadjwgt[0] = lgraph->adjwgt;
slabel[0] = lgraph->label;
SetUpSplitGraph(graph, rgraph, snvtxs[1], snedges[1]);
sxadj[1] = rgraph->xadj;
svwgt[1] = rgraph->vwgt;
sadjwgtsum[1] = rgraph->adjwgtsum;
sadjncy[1] = rgraph->adjncy;
sadjwgt[1] = rgraph->adjwgt;
slabel[1] = rgraph->label;
/* Go and use bndptr to also mark the boundary nodes in the two partitions */
for (ii=0; ii<graph->nbnd; ii++) {
i = bndind[ii];
for (j=xadj[i]; j<xadj[i+1]; j++)
bndptr[adjncy[j]] = 1;
}
snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0;
sxadj[0][0] = sxadj[1][0] = 0;
for (i=0; i<nvtxs; i++) {
if ((mypart = where[i]) == 2)
continue;
istart = xadj[i];
iend = xadj[i+1];
if (bndptr[i] == -1) { /* This is an interior vertex */
auxadjncy = sadjncy[mypart] + snedges[mypart] - istart;
for(j=istart; j<iend; j++)
auxadjncy[j] = adjncy[j];
snedges[mypart] += iend-istart;
}
else {
auxadjncy = sadjncy[mypart];
l = snedges[mypart];
for (j=istart; j<iend; j++) {
k = adjncy[j];
if (where[k] == mypart)
auxadjncy[l++] = k;
}
snedges[mypart] = l;
}
svwgt[mypart][snvtxs[mypart]] = vwgt[i];
sadjwgtsum[mypart][snvtxs[mypart]] = snedges[mypart]-sxadj[mypart][snvtxs[mypart]];
slabel[mypart][snvtxs[mypart]] = label[i];
sxadj[mypart][++snvtxs[mypart]] = snedges[mypart];
}
for (mypart=0; mypart<2; mypart++) {
iend = snedges[mypart];
idxset(iend, 1, sadjwgt[mypart]);
auxadjncy = sadjncy[mypart];
for (i=0; i<iend; i++)
auxadjncy[i] = rename[auxadjncy[i]];
}
lgraph->nvtxs = snvtxs[0];
lgraph->nedges = snedges[0];
//.........这里部分代码省略.........
开发者ID:iyer-arvind,项目名称:gmsh,代码行数:101,代码来源:ometis.c
示例15: FM_2WayNodeRefine_TwoSidedP
void FM_2WayNodeRefine_TwoSidedP(CtrlType *ctrl, GraphType *graph,
idxtype *hmarker, float ubfactor, int npasses)
{
int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind;
idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr;
idxtype *mptr, *mind, *moved, *swaps, *perm;
PQueueType parts[2];
NRInfoType *rinfo;
int higain, oldgain, mincut, initcut, mincutorder;
int pass, to, other, limit;
int badmaxpwgt, mindiff, newdiff;
int u[2], g[2];
nvtxs = graph->nvtxs;
xadj = graph->xadj;
adjncy = graph->adjncy;
vwgt = graph->vwgt;
bndind = graph->bndind;
bndptr = graph->bndptr;
where = graph->where;
pwgts = graph->pwgts;
rinfo = graph->nrinfo;
i = ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt);
PQueueInit(ctrl, &parts[0], nvtxs, i);
PQueueInit(ctrl, &parts[1], nvtxs, i);
moved = idxwspacemalloc(ctrl, nvtxs);
swaps = idxwspacemalloc(ctrl, nvtxs);
mptr = idxwspacemalloc(ctrl, nvtxs+1);
mind = idxwspacemalloc(ctrl, nvtxs);
perm = idxwspacemalloc(ctrl, nvtxs);
IFSET(ctrl->dbglvl, DBG_REFINE,
printf("Partitions: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
badmaxpwgt = (int)(ubfactor*amax(pwgts[0], pwgts[1]));
for (pass=0; pass<npasses; pass++) {
idxset(nvtxs, -1, moved);
PQueueReset(&parts[0]);
PQueueReset(&parts[1]);
mincutorder = -1;
initcut = mincut = graph->mincut;
nbnd = graph->nbnd;
RandomPermute(nbnd, perm, 1);
for (ii=0; ii<nbnd; ii++) {
i = bndind[perm[ii]];
ASSERT(where[i] == 2);
if (hmarker[i] == -1) {
PQueueInsert(&parts[0], i, vwgt[i]-rinfo[i].edegrees[1]);
PQueueInsert(&parts[1], i, vwgt[i]-rinfo[i].edegrees[0]);
moved[i] = -5;
}
else if (hmarker[i] != 2) {
PQueueInsert(&parts[hmarker[i]], i, vwgt[i]-rinfo[i].edegrees[(hmarker[i]+1)%2]);
moved[i] = -(10+hmarker[i]);
}
}
ASSERT(CheckNodeBnd(graph, nbnd));
ASSERT(CheckNodePartitionParams(graph));
limit = nbnd;
/*******************
|
请发表评论