本文整理汇总了C++中TopologyNode::removeChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TopologyNode::removeChild方法的具体用法?C++ TopologyNode::removeChild怎么用?C++ TopologyNode::removeChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TopologyNode
的用法示例。
在下文中一共展示了TopologyNode::removeChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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)
//.........这里部分代码省略.........