void Func_simTree::simulateCaterpillarTree( size_t n, RevBayesCore::TopologyNode* node ) { // add a left child RevBayesCore::TopologyNode* leftChild = new RevBayesCore::TopologyNode(0); node->addChild(leftChild); leftChild->setParent(node); // add a right child RevBayesCore::TopologyNode* rightChild = new RevBayesCore::TopologyNode(0); node->addChild(rightChild); rightChild->setParent(node); std::string name = "Taxon_" + StringUtilities::to_string(n); rightChild->setName(name); if ( n > 2 ) { simulateCaterpillarTree(n-1, leftChild); } else { std::string name = "Taxon_" + StringUtilities::to_string(n-1); leftChild->setName(name); } }
void Func_simTree::simulateBalancedTree( size_t n, std::vector<RevBayesCore::TopologyNode*> &nodes ) { // check if the number of taxa is divideable by two size_t half = n / 2; if ( (half+half) != n ) { throw RbException("Bad number of taxa."); } std::vector<RevBayesCore::TopologyNode*> children; for (size_t i = 0; i < nodes.size(); ++i) { RevBayesCore::TopologyNode *parent = nodes[i]; // add a left child RevBayesCore::TopologyNode* leftChild = new RevBayesCore::TopologyNode(0); parent->addChild(leftChild); leftChild->setParent(parent); children.push_back(leftChild); // add a right child RevBayesCore::TopologyNode* rightChild = new RevBayesCore::TopologyNode(0); parent->addChild(rightChild); rightChild->setParent(parent); children.push_back(rightChild); } if ( half == 1 ) { // we are done with the recursion for (size_t i = 0; i < children.size(); ++i) { RevBayesCore::TopologyNode *node = children[i]; std::string name = "Taxon_" + StringUtilities::to_string(i+1); node->setName(name); } } else { simulateBalancedTree(half, children); } }