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


C++ Permutation::isEmpty方法代码示例

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


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

示例1: debugLog

shared_ptr<PartialGtGenerator> GtGenerator::reducePermutation(shared_ptr<PartialGtGenerator> partialGenerator,
    uint n, Scheme* scheme, Scheme::iterator* targetIter)
{
    debugLog("GtGenerator::reducePermutation()-dump-transposition-count", [&](ostream& out)->void
    {
        const Permutation& perm = partialGenerator->getPermutation();
        uint transpCount = 0;
        static uint stepCount = 0;

        for (auto cycle : perm)
        {
            uint elementCount = cycle->length();
            transpCount += elementCount - 1;
        }

        out << "Step " << ++stepCount << ", transposition count = " << transpCount << '\n';
    });

    shared_ptr<PartialGtGenerator> restGenerator = 0;

    bool isLeftAndRightMultiplicationDiffers = partialGenerator->isLeftAndRightMultiplicationDiffers();
    if(isLeftAndRightMultiplicationDiffers)
    {
        // get left choice
        Permutation leftMultipliedPermutation  = partialGenerator->getResidualPermutation(true);
        shared_ptr<PartialGtGenerator> leftGenerator(new PartialGtGenerator());

        leftGenerator->setPermutation(leftMultipliedPermutation, n);
        leftGenerator->prepareForGeneration();

        // get right choice
        Permutation rightMultipliedPermutation = partialGenerator->getResidualPermutation(false);
        shared_ptr<PartialGtGenerator> rightGenerator(new PartialGtGenerator());

        rightGenerator->setPermutation(rightMultipliedPermutation, n);
        rightGenerator->prepareForGeneration();

        debugLog("GtGenerator::reducePermutation()-dump-left-right", [&](ostream& out)->void
        {
            out << "============================\n";
            out << "Left:\n" << leftMultipliedPermutation << '\n';
            out << "\nRight:\n" << rightMultipliedPermutation << '\n' << endl;
        });

        // compare left and right choices and choose the best
        PartialResultParams leftPartialResultParams  =  leftGenerator->getPartialResultParams();
        PartialResultParams rightPartialResultParams = rightGenerator->getPartialResultParams();

        bool isLeftBetter = leftPartialResultParams.isBetterThan(rightPartialResultParams);

        debugBehavior("GtGenerator::reducePermutation()-right-always-better", [&]()->void
        {
            isLeftBetter = false;
        });
        
        if(isLeftBetter)
        {
            debugLog("GtGenerator::reducePermutation()-dump-left", [&](ostream& out)->void
            {
                out << "Left:\n" << leftMultipliedPermutation << endl;
            });

            implementPartialResult(*partialGenerator, true, scheme, targetIter);
            restGenerator = leftGenerator;
        }
        else
        {
            debugLog("GtGenerator::reducePermutation()-dump-right", [&](ostream& out)->void
            {
                out << "Right:\n" << rightMultipliedPermutation << endl;
            });

            implementPartialResult(*partialGenerator, false, scheme, targetIter);
            restGenerator = rightGenerator;
        }
    }
    else
    {
        implementPartialResult(*partialGenerator, true, scheme, targetIter);

        // get residual permutation and iterate on it
        Permutation residualPermutation = partialGenerator->getResidualPermutation(true);
        if(!residualPermutation.isEmpty())
        {
            debugLog("GtGenerator::reducePermutation()-dump-residual", [&](ostream& out)->void
            {
                out << "Residual:\n" << residualPermutation << endl;
            });

            restGenerator = shared_ptr<PartialGtGenerator>(new PartialGtGenerator());
            restGenerator->setPermutation(residualPermutation, n);
            restGenerator->prepareForGeneration();
        }
    }

    return restGenerator;
}
开发者ID:dmitry-zakablukov,项目名称:ReversibleLogicGenerator,代码行数:97,代码来源:GtGenerator.cpp


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