当前位置: 首页>>代码示例>>C++>>正文


C++ timer::total方法代码示例

本文整理汇总了C++中timer::total方法的典型用法代码示例。如果您正苦于以下问题:C++ timer::total方法的具体用法?C++ timer::total怎么用?C++ timer::total使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timer的用法示例。


在下文中一共展示了timer::total方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setCover

_seq<intT> setCover(Graph GS) {
    double epsilon = 0.01;
    intT m = maxElt(GS);
    cout << "m = " << m << endl;

    bucketTime.start();
    pair<bucket*, int> B = putInBuckets(GS, epsilon);
    bucketTime.stop();
    bucket* allBuckets = B.first;
    int numBuckets = B.second;

    set* S = newA(set, GS.n);    // holds sets for current bucket
    set* ST = newA(set, GS.n);   // temporarily S (pack is not inplace)
    int l = 0;                   // size of S
    bool* flag = newA(bool, GS.n);
    intT* inCover = newA(intT, GS.n);
    intT nInCover = 0;
    intT totalWork = 0;
    intT* elts = newA(intT,m);
    intT threshold = GS.n;
    for (int i = 0; i < m; i++) elts[i] = INT_MAX;

    // loop over all buckets, largest degree first
    for (int i = numBuckets-1; i >= 0; i--) {
        bucket currentB = allBuckets[i];

        intT degreeThreshold = ceil(pow(1.0+epsilon,i));
        if (degreeThreshold == threshold && currentB.n == 0) continue;
        else threshold = degreeThreshold;
        packTime.start();

        // pack leftover sets that are below threshold down for the next round
        for (int j = 0; j < l; j++)
            flag[j] = (S[j].degree > 0 && S[j].degree < threshold);
        intT ln = sequence::pack(S, ST, flag, l);

        // pack leftover sets greater than threshold above for this round
        for (int j = 0; j < l; j++)
            flag[j] = (S[j].degree >= threshold);
        intT lb = sequence::pack(S, ST+ln, flag, l);

        // copy prebucketed bucket i to end, also for this round
        for (int j = 0; j < currentB.n; j++)
            ST[j+ln+lb] = currentB.S[j];

        lb = lb + currentB.n;   // total number in this round
        l = ln + lb;            // total number including those for next round
        swap(ST,S);             // since pack is not in place
        set* SB = S + ln;       // pointer to bottom of sets for this round
        packTime.stop();

        if (lb > 0) { // is there anything to do in this round?

            manisTime.start();
            intT work = processBucket(SB, elts, lb, threshold);
            totalWork += work;
            manisTime.stop();
            packTime.start();

            // check which sets were selected by manis to be in the set cover
            for (int j = 0; j < lb; j++)
                flag[j] = SB[j].degree < 0;

            // add these to inCover and label by their original ID
            int nNew = sequence::packIndex(inCover+nInCover, flag, lb);
            for (int j = nInCover; j < nInCover + nNew; j++)
                inCover[j] = SB[inCover[j]].id;
            nInCover = nInCover + nNew;
            packTime.stop();
            cout << "i = " << i << " bc = " << currentB.n << " l = " << l << " lb = " << lb
                 << " work = " << work << " new = " << nNew << " threshold = " << threshold << endl;
        }
    }
    cout << "Set cover size = " << nInCover << endl;
    cout << "Total work = " << totalWork << endl;
    cout << "Bucket Time = " << bucketTime.total() << endl;
    cout << "Manis Time = " << manisTime.total() << endl;
    cout << "Pack Time = " << packTime.total() << endl;

    free(elts);
    free(S);
    free(ST);
    free(flag);
    freeBuckets(allBuckets);
    return _seq<intT>(inCover, nInCover);
}
开发者ID:hustpawpaw,项目名称:MultiCoreExp,代码行数:86,代码来源:setCover.C


注:本文中的timer::total方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。