TEST_F(QueueTest, UpdateParentDescendant) { buildSimpleTree(); updatePriority(1, {5, false, 8}); dump(); EXPECT_EQ(nodes_, IDList({{5, 100}, {9, 50}, {1, 50}, {3, 33}, {7, 66}})); }
TEST_F(QueueTest, UpdateParentAncestorExcl) { buildSimpleTree(); updatePriority(9, {0, true, 16}); dump(); EXPECT_EQ(nodes_, IDList({{9, 100}, {1, 100}, {3, 25}, {5, 25}, {7, 50}})); }
TEST_F(QueueTest, UpdateParentDescendantExcl) { buildSimpleTree(); updatePriority(1, {5, true, 8}); dump(); EXPECT_EQ(nodes_, IDList({{5, 100}, {1, 100}, {3, 20}, {7, 40}, {9, 40}})); }
TEST_F(QueueTest, RemoveLeaf) { buildSimpleTree(); removeTransaction(3); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {5, 33}, {9, 100}, {7, 66}})); }
TEST_F(QueueTest, RemoveParent) { buildSimpleTree(); removeTransaction(5); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 20}, {7, 40}, {9, 40}})); }
TEST_F(QueueTest, UpdateWeightExcl) { buildSimpleTree(); updatePriority(5, {1, true, 8}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {5, 100}, {9, 40}, {3, 20}, {7, 40}})); }
TEST_F(QueueTest, UpdateParentSiblingExcl) { buildSimpleTree(); updatePriority(7, {5, true, 4}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 50}, {5, 50}, {7, 100}, {9, 100}})); }
TEST_F(QueueTest, UpdateParentSibling) { buildSimpleTree(); updatePriority(5, {3, false, 4}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 33}, {5, 100}, {9, 100}, {7, 66}})); }
TEST_F(QueueTest, iterateBFS) { buildSimpleTree(); auto stopFn = [this] { return nodes_.size() > 2; }; dumpBFS(stopFn); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 25}, {5, 25}, {7, 50}})); }
TEST_F(QueueTest, UpdateParentAncestor) { buildSimpleTree(); updatePriority(9, {0, false, 15}); dump(); EXPECT_EQ(nodes_, IDList({{1, 50}, {3, 25}, {5, 25}, {7, 50}, {9, 50}})); nextEgress(); EXPECT_EQ(nodes_, IDList({{1, 50}, {9, 50}})); }
TEST_F(QueueTest, UpdateWeightExclDequeued) { buildSimpleTree(); signalEgress(5, false); updatePriority(5, {1, true, 7}); signalEgress(1, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{9, 40}, {7, 40}, {3, 20}})); }
TEST_F(QueueTest, ExclusiveAdd) { buildSimpleTree(); addTransaction(11, {1, true, 100}); dump(); EXPECT_EQ(nodes_, IDList({ {1, 100}, {11, 100}, {3, 25}, {5, 25}, {9, 100}, {7, 50} })); }
TEST_F(QueueTest, AddUnknown) { buildSimpleTree(); addTransaction(11, {75, false, 16}); dump(); EXPECT_EQ(nodes_, IDList({ {1, 50}, {3, 25}, {5, 25}, {9, 100}, {7, 50}, {11, 50} })); }
TEST_F(QueueTest, Misc) { buildSimpleTree(); EXPECT_FALSE(q_.empty()); EXPECT_EQ(q_.numPendingEgress(), 5); signalEgress(1, false); EXPECT_EQ(q_.numPendingEgress(), 4); EXPECT_FALSE(q_.empty()); removeTransaction(9); removeTransaction(1); dump(); EXPECT_EQ(nodes_, IDList({{3, 25}, {5, 25}, {7, 50}})); }
TEST_F(QueueTest, UpdateParentSiblingExcl) { buildSimpleTree(); updatePriority(7, {5, true, 3}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 50}, {5, 50}, {7, 100}, {9, 100}})); signalEgress(1, false); signalEgress(3, false); signalEgress(5, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 100}})); }
TEST_F(QueueTest, UpdateParentDescendantExcl) { buildSimpleTree(); updatePriority(1, {5, true, 7}); dump(); EXPECT_EQ(nodes_, IDList({{5, 100}, {1, 100}, {3, 20}, {7, 40}, {9, 40}})); nextEgress(); EXPECT_EQ(nodes_, IDList({{5, 100}})); signalEgress(5, false); signalEgress(1, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 40}, {9, 40}, {3, 20}})); }
TEST_F(QueueTest, nextEgressExclusiveAddWithEgress) { buildSimpleTree(); // clear all egress, except 3 signalEgress(1, false); signalEgress(5, false); signalEgress(7, false); signalEgress(9, false); // Add a transaction with exclusive dependency, clear its egress addTransaction(11, {1, true, 100}); signalEgress(11, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{3, 100}})); }
TEST_F(QueueTest, nextEgressExclusiveAdd) { buildSimpleTree(); // clear all egress signalEgress(1, false); signalEgress(3, false); signalEgress(5, false); signalEgress(7, false); signalEgress(9, false); // Add a transaction with exclusive dependency, clear its egress addTransaction(11, {1, true, 100}); signalEgress(11, false); // signal egress for a child that got moved via exclusive dep signalEgress(3, true); nextEgress(); EXPECT_EQ(nodes_, IDList({{3, 100}})); }
TEST_F(QueueTest, nextEgressRemoveParent) { buildSimpleTree(); // Clear egress for all except txn=9 signalEgress(1, false); signalEgress(3, false); signalEgress(5, false); signalEgress(7, false); // Remove parent of 9 (5) removeTransaction(5); nextEgress(); EXPECT_EQ(nodes_, IDList({{9, 100}})); // signal egress for 9's new siblings to verify weights signalEgress(3, true); signalEgress(7, true); nextEgress(); EXPECT_EQ(nodes_, IDList({{9, 40}, {7, 40}, {3, 20}})); }
TEST_F(QueueTest, nextEgress) { buildSimpleTree(); nextEgress(); EXPECT_EQ(nodes_, IDList({{1, 100}})); addTransaction(11, {7, false, 15}); signalEgress(1, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {5, 25}})); signalEgress(5, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {9, 25}})); signalEgress(5, true); signalEgress(3, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 66}, {5, 33}})); signalEgress(5, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 66}, {9, 33}})); signalEgress(7, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{11, 66}, {9, 33}})); signalEgress(9, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{11, 100}})); signalEgress(3, true); signalEgress(7, true); signalEgress(9, true); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {9, 25}})); }
TEST_F(QueueTest, UpdateParentSibling) { buildSimpleTree(); updatePriority(5, {3, false, 3}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 33}, {5, 100}, {9, 100}, {7, 66}})); signalEgress(1, false); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 66}, {3, 33}})); // Clear 5's egress (so it is only in the tree because 9 has egress) and move // it back. Hit's a slightly different code path in reparent signalEgress(5, false); updatePriority(5, {1, false, 3}); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 25}, {7, 50}, {5, 25}, {9, 100}})); nextEgress(); EXPECT_EQ(nodes_, IDList({{7, 50}, {3, 25}, {9, 25}})); }
void pllMakeParsimonyTreeFast(tree *tr) { nodeptr p, f; int i, nextsp, *perm = (int *)malloc((size_t)(tr->mxtips + 1) * sizeof(int)); unsigned int randomMP, startMP; assert(!tr->constrained); makePermutationFast(perm, tr->mxtips, tr); tr->ntips = 0; tr->nextnode = tr->mxtips + 1; buildSimpleTree(tr, perm[1], perm[2], perm[3]); f = tr->start; while(tr->ntips < tr->mxtips) { nodeptr q; tr->bestParsimony = INT_MAX; nextsp = ++(tr->ntips); p = tr->nodep[perm[nextsp]]; q = tr->nodep[(tr->nextnode)++]; p->back = q; q->back = p; if(tr->grouped) { int number = p->back->number; tr->constraintVector[number] = -9; } stepwiseAddition(tr, q, f->back); { nodeptr r = tr->insertNode->back; int counter = 4; hookupDefault(q->next, tr->insertNode, tr->numBranches); hookupDefault(q->next->next, r, tr->numBranches); computeTraversalInfoParsimony(q, tr->ti, &counter, tr->mxtips, FALSE); tr->ti[0] = counter; newviewParsimonyIterativeFast(tr); } } printf("ADD: %d\n", tr->bestParsimony); nodeRectifierPars(tr); randomMP = tr->bestParsimony; do { startMP = randomMP; nodeRectifierPars(tr); for(i = 1; i <= tr->mxtips + tr->mxtips - 2; i++) { rearrangeParsimony(tr, tr->nodep[i], 1, 20, FALSE); if(tr->bestParsimony < randomMP) { restoreTreeRearrangeParsimony(tr); randomMP = tr->bestParsimony; } } } while(randomMP < startMP); printf("OPT: %d\n", tr->bestParsimony); }
TEST_F(QueueTest, Basic) { buildSimpleTree(); dump(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 25}, {5, 25}, {9, 100}, {7, 50}})); }
TEST_F(QueueTest, BreadthFirst) { buildSimpleTree(); dumpBFS(); EXPECT_EQ(nodes_, IDList({{1, 100}, {3, 25}, {5, 25}, {7, 50}, {9, 100}})); }
void TreeRandomizer::createStepwiseAdditionParsimonyTree(TreeAln &traln, ParallelSetup& pl ) { auto *tr = &(traln.getTrHandle()); auto *pr = &(traln.getPartitionsHandle()); assert(tr->fastParsimony == PLL_FALSE); nodeptr p, f; int nextsp; auto perm = std::vector<int>(tr->mxtips+1, 0); assert(!tr->constrained); makePermutationFast(perm.data(), tr->mxtips, tr); tr->ntips = 0; tr->nextnode = tr->mxtips + 1; buildSimpleTree(tr, pr, perm[1], perm[2], perm[3]); f = tr->start; while(tr->ntips < tr->mxtips) { nodeptr q; tr->bestParsimony = std::numeric_limits<nat>::max(); nextsp = ++(tr->ntips); p = tr->nodep[perm[nextsp]]; q = tr->nodep[(tr->nextnode)++]; p->back = q; q->back = p; if(tr->grouped) { int number = p->back->number; tr->constraintVector[number] = -9; } stepwiseAddition(tr, pr, q, f->back, pl); // std::cout << SyncOut() << "bestPars: "<< tr->bestParsimony << std::endl; { nodeptr r = tr->insertNode->back; int counter = 4; hookupDefault(q->next, tr->insertNode); hookupDefault(q->next->next, r); computeTraversalInfoParsimony(q, tr->ti, &counter, tr->mxtips, PLL_FALSE); tr->ti[0] = counter; newviewParsimonyIterativeFast(tr, pr); } } }