diff --git a/Makefile b/Makefile index d625b1d..a6d72e1 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,11 @@ # Makefile for program "cover" by Kari J. Nurmela. # -CC = gcc +CXX = g++ LIBS= -lm -FLAGS= -ggdb -W # unoptimized, debuggable -#FLAGS= -W -O2 # optimized, not debuggable +#FLAGS= -ggdb -W # unoptimized, debuggable +FLAGS= -ffast-math -W -Ofast -D_GLIBCXX_PARALLEL# optimized, not debuggable #if windows #REMOVE= del cover.exe @@ -20,12 +20,12 @@ OBJECTS= cover.o bincoef.o tables.o setoper.o solcheck.o exp.o arg.o pdo.o CS= cover.c bincoef.c tables.c setoper.c solcheck.c exp.c arg.c pdo.c AUTOBACKUPS= *~ -.cc.o : - $(CC) $(FLAGS) -c $< +.c.o : $(CS) + $(CXX) $(FLAGS) -c $< cover: $(OBJECTS) $(REMOVE) - $(CC) -o cover $(OBJECTS) \ + $(CXX) $(FLAGS) -lgomp -o cover $(OBJECTS) \ $(LIBS) distrib: @@ -35,7 +35,7 @@ distrib: echo "NOTE: distribution contains files cover.tar.Z, cover.zip, and README." clean: - $(DELETE) $(OBJECTS) + $(DELETE) $(OBJECTS) $(BCS) cover $(DELETE) $(AUTOBACKUPS) $(DELETE) core $(DELETE) cover.tar diff --git a/arg.c b/arg.c index b947283..f968e9b 100644 --- a/arg.c +++ b/arg.c @@ -6,8 +6,9 @@ */ -#include -#include +#include +#include +#include #include "cover.h" #include "arg.h" #include "tables.h" @@ -103,10 +104,10 @@ void parseArguments(int argc, char **argv) if((tmp = strchr(argv[i], '=')) == NULL) errmsg(argv[i]); eq = tmp - argv[i] + 1; - strncpy(name, argv[i], min(eq - 1, TMP_BUF_SIZE - 1)); - name[min(eq - 1, TMP_BUF_SIZE - 1)] = '\0'; - strncpy(value, argv[i] + eq, min(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)); - value[min(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)] = '\0'; + strncpy(name, argv[i], fmin(eq - 1, TMP_BUF_SIZE - 1)); + name[(int)fmin(eq - 1, TMP_BUF_SIZE - 1)] = '\0'; + strncpy(value, argv[i] + eq, (int)fmin(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)); + value[(int)fmin(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)] = '\0'; found = 0; for(j = 0; j < OPT_COUNT; j++) if(!strcmp(vars[j].varname, name)) { diff --git a/cover.c b/cover.c index 29157d9..d3a6339 100644 --- a/cover.c +++ b/cover.c @@ -25,7 +25,10 @@ #include #include "cover.h" #include "bincoef.h" -#include "tables.h" +#include "tables.h" +#include "setoper.h" +#include "solcheck.h" +#include "arg.h" #include "exp.h" #include "pdo.h" @@ -149,9 +152,68 @@ int compareVarieties(varietyType *a, varietyType *b) { return 0; } } - + char *logName, *resultName; -FILE *logFp, *resFp; +FILE *logFp, *resFp; + +void printProblemParams(){ + if(pack){ + printf("Searching for a (%d,%d,%d,%d,%d) packing in %d blocks. (v,k,m,t,lambda)\n\n", + v,k,m,t,coverNumber,b); + }else{ + printf("Searching for a (%d,%d,%d,%d,%d) covering in %d blocks. (v,k,m,t,lambda)\n\n", + v,k,m,t,coverNumber,b); + } + if(pack){ + asprintf(&logName, "./solutions/P(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b); + }else{ + asprintf(&logName, "./solutions/C(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b); + } + logFp = fopen(logName, "w"); + if(!logFp) { + fprintf(stderr, "Can't open log file %s.\n", logName); + coverError(SEE_ABOVE_ERROR); + } + if(verbose && !pdoFlag){ + printParams(stdout); + } + printParams(logFp); +} + +void printProblemOutput(){ + if(verbose){ + printf("Result:\n" "-------\n" + "EndLimit = %d\n\n", endLimit); + } + if(verbose){ + if(finalCost <= endLimit) { + printf("Solution:\n" "---------\n"); + } else { + printf("EndLimit was not reached.\n\n"); + if(verbose >= 2) { + printf("Inadequate solution:\n" "--------------------\n"); + printSolution(stdout); + } + } + } + if(finalCost <= endLimit) { + if(verbose) { + printSolution(stdout); + } + if(pack){ + asprintf(&resultName, "./solutions/P(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b); + }else{ + asprintf(&resultName, "./solutions/C(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b); + } + resFp = fopen(resultName, "w"); + if(!resFp) { + fprintf(stderr, "Can't open file %s.\n", resultName); + coverError(SEE_ABOVE_ERROR); + } + printSolution(resFp); + fclose(resFp); + } +} int main(int argc, char **argv) { costType retVal; @@ -227,61 +289,3 @@ int main(int argc, char **argv) { return !solFound; /* returns 0 if a solution was found */ } -void printProblemParams(){ - if(pack){ - printf("Searching for a (%d,%d,%d,%d,%d) packing in %d blocks. (v,k,m,t,lambda)\n\n", - v,k,m,t,coverNumber,b); - }else{ - printf("Searching for a (%d,%d,%d,%d,%d) covering in %d blocks. (v,k,m,t,lambda)\n\n", - v,k,m,t,coverNumber,b); - } - if(pack){ - asprintf(&logName, "./solutions/P(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b); - }else{ - asprintf(&logName, "./solutions/C(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b); - } - logFp = fopen(logName, "w"); - if(!logFp) { - fprintf(stderr, "Can't open log file %s.\n", logName); - coverError(SEE_ABOVE_ERROR); - } - if(verbose && !pdoFlag){ - printParams(stdout); - } - printParams(logFp); -} - -void printProblemOutput(){ - if(verbose){ - printf("Result:\n" "-------\n" - "EndLimit = %d\n\n", endLimit); - } - if(verbose){ - if(finalCost <= endLimit) { - printf("Solution:\n" "---------\n"); - } else { - printf("EndLimit was not reached.\n\n"); - if(verbose >= 2) { - printf("Inadequate solution:\n" "--------------------\n"); - printSolution(stdout); - } - } - } - if(finalCost <= endLimit) { - if(verbose) { - printSolution(stdout); - } - if(pack){ - asprintf(&resultName, "./solutions/P(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b); - }else{ - asprintf(&resultName, "./solutions/C(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b); - } - resFp = fopen(resultName, "w"); - if(!resFp) { - fprintf(stderr, "Can't open file %s.\n", resultName); - coverError(SEE_ABOVE_ERROR); - } - printSolution(resFp); - fclose(resFp); - } -} diff --git a/cover.h b/cover.h index 4dd60db..a9cfa8d 100644 --- a/cover.h +++ b/cover.h @@ -11,14 +11,14 @@ #include #include - +#include //#define maxv 40 #define maxv 70 /* binomial coefficients are tried to calculate up to binCoef[maxv][?] * (overflow is checked and the program is not halted */ -#define min(X,Y) ((X) < (Y) ? (X) : (Y)) +//#define min(X,Y) ((X) < (Y) ? (X) : (Y)) /* initialize random number generator */ diff --git a/pdo.c b/pdo.c index 2750e95..e17283d 100644 --- a/pdo.c +++ b/pdo.c @@ -1,11 +1,12 @@ #include -#include +#include +#include #include "cover.h" #include "bincoef.h" #include "tables.h" #include "exp.h" #include "pdo.h" - +#include "setoper.h" //always accept sideways moves //moves at the same level are counted together towards the number of moves needed to find better solution //initialize jdf to 10*neighbourhood-size @@ -27,169 +28,6 @@ int printCount = 0; rankType *oldKSet; FILE *fp; -static void updateJDF(void){ - /* - double ans = jdc[currCost] * jdf[currCost] + counter; - ans /= (double)(jdc[currCost] + 1); - */ - - //Jan de Heer, more efficient way to compute - //and avoids overflows from initial multiplication - double ans = counter - jdf_precise[currCost]; - ans /= (double)(jdc[currCost] + 1); - ans += (double)(jdf_precise[currCost]); - - jdf_precise[currCost] = ans; - jdf[currCost] = (int)ceil(ans); - - //only try up to a million times? - if(pdoMaxJDF && jdf[currCost] > pdoMaxJDF){ - jdf[currCost] = pdoMaxJDF; - } -} - -static costType initSolution(void) { - int i, j, count, maxCount, l; - costType initCost; - coveredType *ptr; - rankType *coveringsPtr; - - fp = fopen("startFile.txt", "r"); - for(i = 0; i < b; i++) { - if(startFromFileFlag && !bSearch){ - kset[i] = getNextBlockFromFile(); - }else if(greedyStartFlag && !bSearch){ - kset[i] = getNextGreedyBlock(); - } else if( bSearch == 2 && //if taking from last results - startB != b && //and this isn't the first one (no one to take frome) - !(pack && i == b-1)){//and this isn't the last block (new packing has one new extra block) - kset[i] = oldKSet[i]; //copy it over from previous solution - } else { - kset[i] = rnd(binCoef[v][k]); //generate randomly - } - - if(onTheFly) { - calculateOneCovering(kset[i], coverings); - coveringsPtr = coverings; - } else { - coveringsPtr = coverings + (int) kset[i] * coverLen; - } - for(j = 0; j < coverLen - 1; j++) { - covered[coveringsPtr[j]]++; - } - } - if(bSearch == 2 && (startB != b) && oldKSet){ - //TODO free is crashing program for some reason - //crashes occasionally with v=17 k=6 m=4 t=4 b=105 bFinal=114 bSearch=2 pack=1 - if(!pack){ - free((void *) oldKSet); - } - } - fclose(fp); - for(i = 0, initCost = (costType) 0, ptr = covered; i < coveredLen; i++, ptr++) - initCost += costs[*ptr]; - - return initCost; -} - - -costType pdo() { - int i; - - if(b > maxkSetCount){ - coverError(B_TOO_LARGE); - } - //blank covering data - for(i = 0; i < binCoef[v][m]; i++){ - covered[i] = 0; - } - - //need to allocate kset, costs, costds - if(bSearch == 2 && startB != b){ //allocate new storage if we are copying over - oldKSet = kset; - // printf("%d %d\n", oldKSet[0], kset[0]); - if(!(kset = (rankType *) malloc(b * sizeof(rankType)))){ - coverError(MEM_ALLOC_ERROR); - } - // printf("%d %d\n", oldKSet[0], kset[0]); - }else{ //reallocate if we are overwriting - free((void *) kset); - free((void *) costs); - free((void *) costds); - if(!(kset = (rankType *) malloc(b * sizeof(rankType))) || - !(costs = (costType *) malloc((b + 1) * sizeof(costType))) || - !(costds = (costDType *) malloc((b + 1) * sizeof(costDType)))) - // if(!(kset = (rankType *) realloc((char *) kset, b * sizeof(rankType))) || - // !(costs = (costType *) realloc((char *) costs, (b + 1) * sizeof(costType))) || - // !(costds = (costDType *) realloc((char *) costds, (b + 1) * sizeof(costDType)))) - coverError(MEM_ALLOC_ERROR); - } - //costs[lambda] holds costs for covering a single m-set lambda times - maxCost = 0; - calculateCosts(); - for(i = 0; i < b; i++){ - if(costs[i] > maxCost){ - maxCost = costs[i]; - } - } - //if the most we can be pushished for one m-set is max-cost, then the highest - //possible cost is number of m-sets * max pushishment per m-set - maxCost *= binCoef[v][m]; - - //Jump Down Function: cost -> moves needed to find good neighbour - jdf = calloc(maxCost, sizeof(int)); - jdf_precise = calloc(maxCost, sizeof(double)); - for(i = 0; i < maxCost; i++){ - jdf_precise[i] = pdoK * b * neighborLen; - jdf[i] = (int)jdf_precise[i]; - } - //Jump Down Count: jdc[i] = number of times we have jumped down from a solution at level i - jdc = calloc(maxCost, sizeof(int)); - for(i = 0; i < maxCost; i++){ - jdc[i] = 1; - } - - counter = 0; - currCost = initSolution(); - - //get random neighbour and its cost - int costDifference = computeNeighbor(); - - printProgress(); - - while( currCost > endLimit){ - counter++; - if( costDifference > 0) { //if( neighborCost > currCost){ - if( counter > pdoJ * jdf[currCost] ){ - //failed to find jump down from this level, accept bad neighbour anyway - acceptNeighbor(); - counter = 0; - currCost += costDifference; - } - }else if(costDifference == 0) { //if( neighborCost == currCost ){ - acceptNeighbor(); - //counter keeps counting - }else { //found better solution - updateJDF(); - jdc[currCost]++;//increment number of times we have jumped down - acceptNeighbor(); - if(pdoPrint && !printCount--){ - printProgress(); - printCount = pdoPrintFreq; - } - counter = 0; - currCost += costDifference; - } - //try random neighbour - costDifference = computeNeighbor(); - } - if(pdoPrint){ - printf("\n\n\n\n"); - } - - return currCost;//found solution -} - /* ** `setNumber' is the index to the table `kset'. `setNumber' indicates ** the index of the k-set in the proposed change. The current solution @@ -198,7 +36,7 @@ costType pdo() { **`nextSto' are for on-the-fly annealing. `costs[x]' holds the difference ** of costs associated with a m-set covered x times and x+1 times. */ -static setNumber; +static int setNumber; static rankType nextS; static rankType stored[2]; static int currSto, nextSto; @@ -244,10 +82,19 @@ rankType randomNeighbor(rankType curr) unrankSubset(curr, subset, k); makeComplement(subset, csubset, v); subset[rnd(k)] = csubset[rnd(v-k)]; - qsort((char *) subset, k, sizeof(varietyType), compareVarieties); + std::sort(subset, subset+k); return rankSubset(subset, k); } - + +typedef struct { + rankType first; + char second; +} pairdata_t; + +bool comparePair(const pairdata_t& a, const pairdata_t& b) +{ + return (a.first < b.first); +} /* ** computeNeighbor() calculates the cost difference between the current @@ -257,14 +104,15 @@ rankType randomNeighbor(rankType curr) ** */ -costType computeNeighbor(void) +static costType computeNeighbor(void) { costType costDelta = 0; int i; rankType currS; rankType *currPtr, *nextPtr; - + const long limit = (coverLen-1)*2-1; + setNumber = rnd(b); currS = kset[setNumber]; @@ -314,7 +162,7 @@ costType computeNeighbor(void) costDelta += costds[covered[*currPtr++] - 1]; } else - costDelta -= costds[covered[*nextPtr++]]; + costDelta -= costds[covered[*nextPtr++]]; return costDelta; } @@ -325,32 +173,35 @@ costType computeNeighbor(void) ** computed. */ -void acceptNeighbor(void) +static void acceptNeighbor(void) { int i; rankType currS; - rankType *coveringsPtr; + rankType *coveringsPtrA; + rankType *coveringsPtrB; currS = kset[setNumber]; if(onTheFly) - coveringsPtr = coverings + currSto * coverLen; + coveringsPtrA = coverings + currSto * coverLen; else - coveringsPtr = coverings + currS * coverLen; - for(i = 0; i < coverLen - 1; i++) - covered[coveringsPtr[i]]--; + coveringsPtrA = coverings + currS * coverLen; + if(onTheFly) - coveringsPtr = coverings + nextSto * coverLen; + coveringsPtrB = coverings + nextSto * coverLen; else - coveringsPtr = coverings + nextS * coverLen; - for(i = 0; i < coverLen - 1; i++) - covered[coveringsPtr[i]]++; + coveringsPtrB = coverings + nextS * coverLen; + #pragma clang loop unroll_count(100) vectorize_width(100) interleave_count(100) + for(i = 0; i < coverLen - 1; i++) { + covered[coveringsPtrA[i]]--; + covered[coveringsPtrB[i]]++; + } kset[setNumber] = nextS; } rankType getNextBlockFromFile(){ int j; //TODO add some sort of verification here and print error if file sucks - varietyType *block = calloc(k+1, sizeof(int)); + varietyType *block = (varietyType *)calloc(k+1, sizeof(int)); for(j = 0; j < k; j++){ int point; fscanf(fp, "%d", &point); @@ -369,7 +220,7 @@ rankType getNextGreedyBlock(){ //if block has leftover spaces, attempt to cover next m-set int idx = 0; - varietyType *block = calloc(k + 1, sizeof(int)); + varietyType *block = (varietyType *)calloc(k + 1, sizeof(int)); for(j = 0; j < binCoef[v][m]; j++){ if(k < idx+t){ @@ -379,7 +230,7 @@ rankType getNextGreedyBlock(){ if(!covered[j]){ //this m-set not covered //take first t elements of m-set, and add to block - varietyType *mset = calloc(m + 1, sizeof(int)); + varietyType *mset = (varietyType *)calloc(m + 1, sizeof(int)); unrankSubset(covered[j], mset, m); for(i2 = 0; i2 < t; i2++){ block[i2] = mset[i2 + idx]; @@ -388,13 +239,13 @@ rankType getNextGreedyBlock(){ } } //fill in block with other stuff - varietyType *com = calloc(v - idx, sizeof(int)); + varietyType *com = (varietyType *)calloc(v - idx, sizeof(int)); makeComplement(block, com, v); for(; idx < k; idx++){ block[idx] = com[rnd(v-idx)];//TODO hope it doesn't hit same number twice } - qsort((char *) block, k, sizeof(varietyType), compareVarieties); + std::sort(block, block+k); //block done return rankSubset(block, k); } @@ -415,7 +266,7 @@ void printProgress(void){ } } if(curr != 10){ - qsort((int *)indices, 10, sizeof(int), compareVarieties); + std::sort(indices, indices+10); } }else if(pdoPrint == 3){ //show 10 levels above current int i = 0; @@ -444,3 +295,170 @@ void printProgress(void){ // printf("\033[1A"); // printf("\033[1A"); } + +static void updateJDF(void){ + /* + double ans = jdc[currCost] * jdf[currCost] + counter; + ans /= (double)(jdc[currCost] + 1); + */ + + //Jan de Heer, more efficient way to compute + //and avoids overflows from initial multiplication + double ans = counter - jdf_precise[currCost]; + ans /= (double)(jdc[currCost] + 1); + ans += (double)(jdf_precise[currCost]); + + jdf_precise[currCost] = ans; + jdf[currCost] = (int)ceil(ans); + + //only try up to a million times? + if(pdoMaxJDF && jdf[currCost] > pdoMaxJDF){ + jdf[currCost] = pdoMaxJDF; + } +} + +static costType initSolution(void) { + int i, j, count, maxCount, l; + costType initCost; + coveredType *ptr; + rankType *coveringsPtr; + + fp = fopen("startFile.txt", "r"); + for(i = 0; i < b; i++) { + if(startFromFileFlag && !bSearch){ + kset[i] = getNextBlockFromFile(); + }else if(greedyStartFlag && !bSearch){ + kset[i] = getNextGreedyBlock(); + } else if( bSearch == 2 && //if taking from last results + startB != b && //and this isn't the first one (no one to take frome) + !(pack && i == b-1)){//and this isn't the last block (new packing has one new extra block) + kset[i] = oldKSet[i]; //copy it over from previous solution + } else { + kset[i] = rnd(binCoef[v][k]); //generate randomly + } + + if(onTheFly) { + calculateOneCovering(kset[i], coverings); + coveringsPtr = coverings; + } else { + coveringsPtr = coverings + (int) kset[i] * coverLen; + } + for(j = 0; j < coverLen - 1; j++) { + covered[coveringsPtr[j]]++; + } + } + if(bSearch == 2 && (startB != b) && oldKSet){ + //TODO free is crashing program for some reason + //crashes occasionally with v=17 k=6 m=4 t=4 b=105 bFinal=114 bSearch=2 pack=1 + if(!pack){ + free((void *) oldKSet); + } + } + fclose(fp); + for(i = 0, initCost = (costType) 0, ptr = covered; i < coveredLen; i++, ptr++) + initCost += costs[*ptr]; + + return initCost; +} + + +costType pdo() { + int i; + + if(b > maxkSetCount){ + coverError(B_TOO_LARGE); + } + //blank covering data + for(i = 0; i < binCoef[v][m]; i++){ + covered[i] = 0; + } + + //need to allocate kset, costs, costds + if(bSearch == 2 && startB != b){ //allocate new storage if we are copying over + oldKSet = kset; + // printf("%d %d\n", oldKSet[0], kset[0]); + if(!(kset = (rankType *) malloc(b * sizeof(rankType)))){ + coverError(MEM_ALLOC_ERROR); + } + // printf("%d %d\n", oldKSet[0], kset[0]); + }else{ //reallocate if we are overwriting + free((void *) kset); + free((void *) costs); + free((void *) costds); + if(!(kset = (rankType *) malloc(b * sizeof(rankType))) || + !(costs = (costType *) malloc((b + 1) * sizeof(costType))) || + !(costds = (costDType *) malloc((b + 1) * sizeof(costDType)))) + // if(!(kset = (rankType *) realloc((char *) kset, b * sizeof(rankType))) || + // !(costs = (costType *) realloc((char *) costs, (b + 1) * sizeof(costType))) || + // !(costds = (costDType *) realloc((char *) costds, (b + 1) * sizeof(costDType)))) + coverError(MEM_ALLOC_ERROR); + } + //costs[lambda] holds costs for covering a single m-set lambda times + maxCost = 0; + calculateCosts(); + for(i = 0; i < b; i++){ + if(costs[i] > maxCost){ + maxCost = costs[i]; + } + } + //if the most we can be pushished for one m-set is max-cost, then the highest + //possible cost is number of m-sets * max pushishment per m-set + maxCost *= binCoef[v][m]; + + //Jump Down Function: cost -> moves needed to find good neighbour + jdf = (int *)calloc(maxCost, sizeof(int)); + jdf_precise = (double *)calloc(maxCost, sizeof(double)); + for(i = 0; i < maxCost; i++){ + jdf_precise[i] = pdoK * b * neighborLen; + jdf[i] = (int)jdf_precise[i]; + } + //Jump Down Count: jdc[i] = number of times we have jumped down from a solution at level i + jdc = (int *)calloc(maxCost, sizeof(int)); + for(i = 0; i < maxCost; i++){ + jdc[i] = 1; + } + + counter = 0; + currCost = initSolution(); + + //get random neighbour and its cost + int costDifference = computeNeighbor(); + + printProgress(); + + while( currCost > endLimit){ + counter++; + if( costDifference > 0) { //if( neighborCost > currCost){ + if( counter > pdoJ * jdf[currCost] ){ + //failed to find jump down from this level, accept bad neighbour anyway + acceptNeighbor(); + counter = 0; + currCost += costDifference; + } + }else if(costDifference == 0) { //if( neighborCost == currCost ){ + acceptNeighbor(); + //counter keeps counting + }else { //found better solution + updateJDF(); + jdc[currCost]++;//increment number of times we have jumped down + acceptNeighbor(); + if(pdoPrint && !printCount--){ + printProgress(); + printCount = pdoPrintFreq; + } + counter = 0; + currCost += costDifference; + printf("currCost: %15ld\n\n", currCost); + printf("\033[F"); + printf("\033[F"); + } + //try random neighbour + costDifference = computeNeighbor(); + + } + if(pdoPrint){ + printf("\n\n\n\n"); + } + + return currCost;//found solution +} diff --git a/tables.c b/tables.c index 1cbe239..58355e7 100644 --- a/tables.c +++ b/tables.c @@ -5,13 +5,14 @@ ** */ - -#include +#include +#include +#include #include "cover.h" #include "bincoef.h" #include "setoper.h" #include "tables.h" - +#include rankType *kset = NULL; //this is the solution int neighborLen, coverLen, coveredLen; @@ -50,7 +51,7 @@ void allocateMemory(void) coverError(INVALID_PARAMETERS); tmp = coverLen = 0; - for(i = 0; i <= min(k - t, m - t); i++) { + for(i = 0; i <= fmin(k - t, m - t); i++) { if(overflowBinCoef(k, t + i) || overflowBinCoef(v - k, m - t - i)) coverError(BINCOEF_OVERFLOW); coverLen += binCoef[k][t + i] * binCoef[v - k][m - t - i]; @@ -205,7 +206,7 @@ void calculateOneCovering(rankType kRank, rankType *buf) unrankSubset(kRank, subset, k); //subset is curr block subset[k] = maxv + 1; /* sentinel */ makeComplement(subset, csubset, v); //csubset is points not in curr block - for(ti = t; ti <= min(k, m); ti++) { + for(ti = t; ti <= fmin(k, m); ti++) { getFirstSubset(subsubset, ti); //t-set that this block covers do { getFirstSubset(subcsubset, m - ti); //other points not in block we can add to t-set to make m-set @@ -229,8 +230,8 @@ void calculateOneCovering(rankType kRank, rankType *buf) } while(getNextSubset(subcsubset, m - ti, v - k)); } while(getNextSubset(subsubset, ti, k)); } - *coverptr = binCoef[v][m]; /* sentinel */ - qsort((char *) buf, coverLen - 1, sizeof(rankType), compareRanks); + *coverptr = binCoef[v][m]; /* sentinel */ + std::sort(buf, kset+coverLen - 1); } @@ -316,5 +317,5 @@ void bIs(int bl) void sortSolution(void) { - qsort(kset, b, sizeof(rankType), compareRanks); + std::sort(kset, kset+b); }