/************************************************************************* * This function selects the partition number and the queue from which * we will move vertices out **************************************************************************/ void SelectQueue2(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, PQueueType queues[MAXNCON][2], float *maxwgt) { int i, j, maxgain=0; float diff, max, maxdiff=0.0; *from = -1; *cnum = -1; /* First determine the side and the queue, irrespective of the presence of nodes */ for (j=0; j<2; j++) { for (i=0; i<ncon; i++) { diff = npwgts[j*ncon+i]-maxwgt[j*ncon+i]; if (diff >= maxdiff) { maxdiff = diff; *from = j; *cnum = i; } } } if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { /* The desired queue is empty, select a node from that side anyway */ for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][*from]) > 0) { max = (npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]); *cnum = i; break; } } for (i++; i<ncon; i++) { diff = npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]; if (diff > max && PQueueGetSize(&queues[i][*from]) > 0) { max = diff; *cnum = i; } } } /* Check to see if you can focus on the cut */ if (maxdiff <= 0.0 || *from == -1) { maxgain = -100000; for (j=0; j<2; j++) { for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][j]) > 0 && PQueueGetKey(&queues[i][j]) > maxgain) { maxgain = PQueueGetKey(&queues[i][j]); *from = j; *cnum = i; } } } /* printf("(%2d %2d) %3d\n", *from, *cnum, maxgain); */ } }
/************************************************************************* * This function selects the partition number and the queue from which * we will move vertices out **************************************************************************/ void SelectQueue(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, PQueueType queues[MAXNCON][2]) { int i, part, maxgain=0; float max, maxdiff=0.0; *from = -1; *cnum = -1; /* First determine the side and the queue, irrespective of the presence of nodes */ for (part=0; part<2; part++) { for (i=0; i<ncon; i++) { if (npwgts[part*ncon+i]-tpwgts[part] >= maxdiff) { maxdiff = npwgts[part*ncon+i]-tpwgts[part]; *from = part; *cnum = i; } } } /* printf("Selected1 %d(%d) -> %d [%5f]\n", *from, *cnum, PQueueGetSize(&queues[*cnum][*from]), maxdiff); */ if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { /* The desired queue is empty, select a node from that side anyway */ for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][*from]) > 0) { max = npwgts[(*from)*ncon + i]; *cnum = i; break; } } for (i++; i<ncon; i++) { if (npwgts[(*from)*ncon + i] > max && PQueueGetSize(&queues[i][*from]) > 0) { max = npwgts[(*from)*ncon + i]; *cnum = i; } } } /* Check to see if you can focus on the cut */ if (maxdiff <= 0.0 || *from == -1) { maxgain = -100000; for (part=0; part<2; part++) { for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][part]) > 0 && PQueueGetKey(&queues[i][part]) > maxgain) { maxgain = PQueueGetKey(&queues[i][part]); *from = part; *cnum = i; } } } } /* printf("Selected2 %d(%d) -> %d\n", *from, *cnum, PQueueGetSize(&queues[*cnum][*from])); */ }
/************************************************************************* * This function selects the partition number and the queue from which * we will move vertices out **************************************************************************/ int SelectQueueOneWay(int ncon, float *npwgts, float *tpwgts, int from, PQueueType queues[MAXNCON][2]) { int i, cnum=-1; float max=0.0; for (i=0; i<ncon; i++) { if (npwgts[from*ncon+i]-tpwgts[from] >= max && PQueueGetSize(&queues[i][0]) + PQueueGetSize(&queues[i][1]) > 0) { max = npwgts[from*ncon+i]-tpwgts[0]; cnum = i; } } return cnum; }
/************************************************************************* * This function selects the partition number and the queue from which * we will move vertices out **************************************************************************/ int SelectQueueOneWay2(int ncon, float *pto, PQueueType queues[MAXNCON][2], float *ubvec) { int i, cnum=-1, imax, maxgain; float max=0.0; float twgt[MAXNCON]; for (i=0; i<ncon; i++) { if (max < pto[i]) { imax = i; max = pto[i]; } } for (i=0; i<ncon; i++) twgt[i] = (max/(ubvec[imax]*ubvec[i]))/pto[i]; twgt[imax] = 0.0; max = 0.0; for (i=0; i<ncon; i++) { if (max < twgt[i] && (PQueueGetSize(&queues[i][0]) > 0 || PQueueGetSize(&queues[i][1]) > 0)) { max = twgt[i]; cnum = i; } } if (max > 1) return cnum; /* optimize of cut */ maxgain = -10000000; for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][0]) > 0 && PQueueGetKey(&queues[i][0]) > maxgain) { maxgain = PQueueGetKey(&queues[i][0]); cnum = i; } } return cnum; }
/************************************************************************* * This function selects the partition number and the queue from which * we will move vertices out **************************************************************************/ void SelectQueue3(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, PQueueType queues[MAXNCON][2], float *maxwgt) { int i, j, maxgain=0; float maxdiff=0.0, diff; *from = -1; *cnum = -1; /* First determine the side and the queue, irrespective of the presence of nodes */ for (j=0; j<2; j++) { for (i=0; i<ncon; i++) { diff = npwgts[j*ncon+i]-maxwgt[j*ncon+i]; if (diff >= maxdiff) { maxdiff = diff; *from = j; *cnum = i; } } } /* DELETE j = *from; for (i=0; i<ncon; i++) printf("[%5d %5d %.4f %.4f] ", i, PQueueGetSize(&queues[i][j]), npwgts[j*ncon+i], maxwgt[j*ncon+i]); printf("***[%5d %5d]\n", *cnum, *from); */ /* If the desired queue is empty, select a node from that side anyway */ if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][*from]) > 0) { maxdiff = (npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]); *cnum = i; break; } } for (i++; i<ncon; i++) { diff = npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]; if (diff > maxdiff && PQueueGetSize(&queues[i][*from]) > 0) { maxdiff = diff; *cnum = i; } } } /* If the constraints ar OK, select a high gain vertex */ if (*from == -1) { maxgain = -100000; for (j=0; j<2; j++) { for (i=0; i<ncon; i++) { if (PQueueGetSize(&queues[i][j]) > 0 && PQueueGetKey(&queues[i][j]) > maxgain) { maxgain = PQueueGetKey(&queues[i][0]); *from = j; *cnum = i; } } } /* printf("(%2d %2d) %3d\n", *from, *cnum, maxgain); */ } }