compare.cpp
//WARNING: Assume that colorSize is populated with the frequency for each color
//Will sort the array within the function
Assume that colorSize is populated with the frequency for each color
Will sort the array within the function
Assume that colorSize is populated with the frequency for each color Will sort the array within the function
double compute_gini_coeff(GraphElem *colorSize, int numColors) {
#ifdef DEBUG_PRINTF     
    double time1 = omp_get_wtime();
#endif
    std::sort(colorSize, colorSize+numColors);
#ifdef DEBUG_PRINTF     
    double time2 = omp_get_wtime();
    ofs << "Time for sorting (in compute_gini_coeff): " 
        << time2-time1 << std::endl;
#endif
    double numFunc=0.0, denFunc=0.0;
#pragma omp parallel for reduction(+:numFunc,denFunc)
    for (GraphElem i=0; i < numColors; i++) {
        numFunc = numFunc + ((i+1)*colorSize[i]);
        denFunc = denFunc + colorSize[i];
    }
#ifdef DEBUG_PRINTF     
    ofs << "(Gini coeff) Numerator = " << numFunc << " Denominator = " << denFunc << std::endl;
    ofs << "(Gini coeff) Negative component = " << ((double)(numColors+1)/(double)numColors) << std::endl;
#endif
    double giniCoeff = ((2*numFunc)/(numColors*denFunc)) - ((double)(numColors+1)/(double)numColors);
    return giniCoeff; 
}
double compute_gini_coeff ( GraphElem * colorSize , int numColors ) { #ifdef DEBUG_PRINTF double time1 = omp_get_wtime ( ) ; #endif std :: sort ( colorSize , colorSize + numColors ) ; #ifdef DEBUG_PRINTF double time2 = omp_get_wtime ( ) ; ofs << " " << time2 - time1 << std :: endl ; #endif double numFunc = 0.0 , denFunc = 0.0 ; #pragma  omp parallel for reduction(+:numFunc,denFunc) for ( GraphElem i = 0 ; i < numColors ; i ++ ) { numFunc = numFunc + ( ( i + 1 ) * colorSize [ i ] ) ; denFunc = denFunc + colorSize [ i ] ; } #ifdef DEBUG_PRINTF ofs << " " << numFunc << " " << denFunc << std :: endl ; ofs << " " << ( ( double ) ( numColors + 1 ) / ( double ) numColors ) << std :: endl ; #endif double giniCoeff = ( ( 2 * numFunc ) / ( numColors * denFunc ) ) - ( ( double ) ( numColors + 1 ) / ( double ) numColors ) ; return giniCoeff ; }
WARNING: Assume that colorSize is populated with the frequency for each color
Will sort the array within the function
WARNING : Assume that colorSize is populated with the frequency for each color Will sort the array within the function
//Step 1: Sort the color size vector -- use STL sort function //Step 2: Compute Gini coefficient //Return the Gini coefficient