本文整理汇总了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;
}