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


C++ TopologyNode::getChildren方法代码示例

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


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

示例1: recursivelyCleanPatchClade

void StitchTreeFunction::recursivelyCleanPatchClade(TopologyNode* node, TopologyNode*& newRoot, std::set<Taxon>& remainingTaxa, size_t& index, size_t patchIndex)
{
    
    // remove self if found in remainingTaxa
    if (node->isTip())
    {
        std::set<Taxon>::iterator it = remainingTaxa.find( node->getTaxon() );
        if (it != remainingTaxa.end())
        {
            remainingTaxa.erase( node->getTaxon() );
            TopologyNode* parent = &node->getParent();
            std::vector<TopologyNode*> children = parent->getChildren();
            for (size_t i = 0; i < children.size(); i++)
            {
                children[i]->setParent(NULL);
                parent->removeChild(children[i]);
                
                if (children[i] != node)
                    newRoot = children[i];
                else
                    delete children[i];
            }
            
            // free old root node
            delete parent;
        }
        return;
    }
    
    // recurse towards tips
    std::vector<TopologyNode*> children = node->getChildren();
    for (size_t i = 0; i < children.size(); i++)
    {
        recursivelyCleanPatchClade(children[i], newRoot, remainingTaxa, index, patchIndex);
    }
    
    return;
}
开发者ID:,项目名称:,代码行数:38,代码来源:

示例2: recursivelyRetainTaxa

int PruneTreeFunction::recursivelyRetainTaxa(RevBayesCore::TopologyNode *node)
{
    // tip node
    if (node->isTip())
    {
        const std::vector<Taxon>& taxa = tau->getValue().getTaxa();
        const Taxon& tipTaxon = taxa[node->getIndex()];

        std::set<Taxon>::iterator it = retainedTaxa.find( tipTaxon );
        
        // found it
        if (it != retainedTaxa.end()) {
//            std::cout << "retain\t" << node->getIndex() << "\t" << node << "\t" << tipTaxon.getName() << "\n";
            return 1;
        }
        else {
//            std::cout << "prune\t" << node->getIndex() << "\t" << node << "\t" << tipTaxon.getName() << "\n";
            return 0;
        }
    }
    int total_count = 0;
    int number_children_retained = 0;
    
    // determine if subclade has any retained taxa
    std::vector<TopologyNode*> children = node->getChildren();
    std::vector<int> count( children.size(), 0 );
    for (size_t i = 0; i < children.size(); i++)
    {
//        std::cout << "recurse\t" << node->getIndex() << "\t" << node << "\tfor child\t" << children[i]->getIndex() << "\t" << children[i] << "\n";
//        count[i] = recursivelyRetainTaxa(children[i]);
        pruneCount[ children[i] ] = recursivelyRetainTaxa(children[i]);
        total_count += pruneCount[ children[i] ];
        if (pruneCount[ children[i] ] > 0)
            number_children_retained++;
    }
    
    if (node->isRoot())
    {
        TopologyNode* root = node;
        if (number_children_retained == 0)
        {

        }
        // if one daughter, patch over node
        else if (number_children_retained == 1)
        {

            std::vector<TopologyNode*> fresh_children = node->getChildren();
            for (size_t i = 0; i < fresh_children.size(); i++)
            {
                // remove all of the node's children
                // NB: node->removeAllChildren() also calls delete
                node->removeChild(fresh_children[i]);
//                std::cout << "del-child\t" << fresh_children[i]->getIndex() << "\t" << fresh_children[i] << "\t" << fresh_children[i]->getTaxon().getName() << "\n";
            }
            for (size_t i = 0; i < fresh_children.size(); i++)
            {
                if (pruneCount[ fresh_children[i] ] == 0)
                    continue;
                
                root = fresh_children[i];
                fresh_children[i]->setParent(NULL);
//                std::cout << "add-child\t" << fresh_children[i]->getIndex() << "\t" << fresh_children[i] << "\t" << fresh_children[i]->getTaxon().getName() << "\n";
            }

            node->setParent(NULL);
            
            // free memory
            // delete node;
            // setRoot will free this memory
        }
        
        // check ntaxa > 2
        bool good = true;
        if (!good) {
            throw RbException("");
        }

        value->setRoot( root, true );
        std::vector<TopologyNode*> nodes = value->getNodes();
        
        // update tip nodes with stored taxon-index
        for (size_t i = 0; i < value->getNumberOfTips(); i++)
        {
            nodes[i]->setIndex( retainedIndices[ nodes[i]->getTaxon() ] );
        }
        
//        value->setRoot( root, false );
        value->setRoot(root, true);
    }
    else if (node->isInternal())
    {
//        std::cout << "patch\t" << node->getIndex() << "\t" << node << "\n";
        // if zero daughters, drop all daughters
        if (number_children_retained == 0)
        {
            node->removeAllChildren();
        }
        // if one daughter, patch over node
        else if (number_children_retained == 1)
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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