void C_cophenetic(int *children, int *parents, double *el, int *lp, int *m, int *nTips, int *nNode, double *res){ double *nh, maxNH; int i, lt; int *kids, *lkids, *pkids; int *tips, *ltips, *ptips; nh = (double *) calloc(*m, sizeof(double)); kids = (int *) R_alloc(*lp, sizeof(int)); lkids = (int *) R_alloc(*nNode + 1L, sizeof(int)); pkids = (int *) R_alloc(*nNode, sizeof(int)); ltips = (int *) R_alloc(*m, sizeof(int)); ptips = (int *) R_alloc(*m + 1L, sizeof(int)); //nodeH(int *edge, int *node, double *el, int *l, double *res) nodeH(children, parents, el, lp, nh); maxNH=nh[0]; for(i=1; i<*m; i++)if(maxNH<nh[i]) maxNH=nh[i]; for(i=0; i<*m; i++)nh[i] = maxNH - nh[i]; // tmp <- .C("AllKids", kids, parents, nTips, nNode, lp, integer(lp), integer(nNode+1L), // integer(nNode)) // void AllKids(int *children, int *parents, int *nTips, int *nNode, int *lp, int *kids, int *lkids, int *pkids){ AllKids(children, parents, nTips, nNode, lp, kids, lkids, pkids); //tmp2 = .C("C_bipHelp", parents, kids, nTips, m, lp, integer(m), integer(m+1L)) C_bipHelp(parents, children, nTips, m, lp, ltips, ptips); // tips <- .C("C_bip2", parents, kids, nTips, m, lp, ltips=tmp2[[6]], ptips=tmp2[[7]], integer(sum(tmp2[[6]])))[[8]] lt = 0; for(i=0; i<*m; i++)lt += ltips[i]; tips = (int *) R_alloc(lt, sizeof(int)); C_bip2(parents, children, nTips, m, lp, ltips, ptips, tips); //void coph(int *tips, int *kids, int *ptips, int *pkids, int *ltips, int *lkids, int*Nnode, double *nh, int *nTips, double *dm) C_coph(tips, kids, ptips, lkids, ltips, pkids, nNode, nh, nTips, res); }
void Graph::seedNodesAndEdges() { /* Upon construction: seed graph with nodes and edges to connect them. * For now this happens manually. Ideally this happens by algorithm */ std::shared_ptr<Node> nodeA(new Node(0, "0", 100, 50)); std::shared_ptr<Node> nodeB(new Node(1, "1", 500, 40)); std::shared_ptr<Node> nodeC(new Node(2, "2", 200, 300)); std::shared_ptr<Node> nodeD(new Node(3, "3", 700, 100)); std::shared_ptr<Node> nodeE(new Node(4, "4", 600, 400)); std::shared_ptr<Node> nodeF(new Node(5, "5", 250, 450)); std::shared_ptr<Node> nodeG(new Node(6, "6", 750, 500)); std::shared_ptr<Node> nodeH(new Node(7, "7", 400, 150)); std::shared_ptr<Node> nodeI(new Node(8, "8", 550, 250)); std::shared_ptr<Node> nodeJ(new Node(9, "9", 100, 400)); std::list<std::shared_ptr<Edge>> edgeList; // Sequenced container of Edge pointers nodeVector.push_back(nodeA); std::shared_ptr<Edge> edge1(new Edge(nodeA, nodeB, calculateCost(nodeA, nodeB))); edgeList.push_back(edge1); std::shared_ptr<Edge> edge2(new Edge(nodeA, nodeC, calculateCost(nodeA, nodeC))); edgeList.push_back(edge2); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeB); std::shared_ptr<Edge> edge3(new Edge(nodeB, nodeA, calculateCost(nodeB, nodeA))); edgeList.push_back(edge3); std::shared_ptr<Edge> edge4(new Edge(nodeB, nodeH, calculateCost(nodeB, nodeH))); edgeList.push_back(edge4); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeC); std::shared_ptr<Edge> edge5(new Edge(nodeC, nodeA, calculateCost(nodeC, nodeA))); edgeList.push_back(edge5); std::shared_ptr<Edge> edge6(new Edge(nodeC, nodeH, calculateCost(nodeC, nodeH))); edgeList.push_back(edge6); std::shared_ptr<Edge> edge7(new Edge(nodeC, nodeE, calculateCost(nodeC, nodeE))); edgeList.push_back(edge7); std::shared_ptr<Edge> edge8(new Edge(nodeC, nodeF, calculateCost(nodeC, nodeF))); edgeList.push_back(edge8); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeD); std::shared_ptr<Edge> edge9(new Edge(nodeD, nodeH, calculateCost(nodeD, nodeH))); edgeList.push_back(edge9); std::shared_ptr<Edge> edge10(new Edge(nodeD, nodeE, calculateCost(nodeD, nodeE))); edgeList.push_back(edge10); std::shared_ptr<Edge> edge11(new Edge(nodeD, nodeG, calculateCost(nodeD, nodeG))); edgeList.push_back(edge11); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeE); std::shared_ptr<Edge> edge12(new Edge(nodeE, nodeC, calculateCost(nodeE, nodeC))); edgeList.push_back(edge12); std::shared_ptr<Edge> edge13(new Edge(nodeE, nodeD, calculateCost(nodeE, nodeD))); edgeList.push_back(edge13); std::shared_ptr<Edge> edge14(new Edge(nodeE, nodeG, calculateCost(nodeE, nodeG))); edgeList.push_back(edge14); std::shared_ptr<Edge> edge15(new Edge(nodeE, nodeI, calculateCost(nodeE, nodeI))); edgeList.push_back(edge15); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeF); std::shared_ptr<Edge> edge16(new Edge(nodeF, nodeG, calculateCost(nodeF, nodeG))); edgeList.push_back(edge16); std::shared_ptr<Edge> edge17(new Edge(nodeF, nodeC, calculateCost(nodeF, nodeC))); edgeList.push_back(edge17); std::shared_ptr<Edge> edge18(new Edge(nodeF, nodeJ, calculateCost(nodeF, nodeJ))); edgeList.push_back(edge18); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeG); std::shared_ptr<Edge> edge19(new Edge(nodeG, nodeF, calculateCost(nodeG, nodeF))); edgeList.push_back(edge19); std::shared_ptr<Edge> edge20(new Edge(nodeG, nodeD, calculateCost(nodeG, nodeD))); edgeList.push_back(edge20); std::shared_ptr<Edge> edge21(new Edge(nodeG, nodeE, calculateCost(nodeG, nodeE))); edgeList.push_back(edge21); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeH); std::shared_ptr<Edge> edge22(new Edge(nodeH, nodeD, calculateCost(nodeH, nodeD))); edgeList.push_back(edge22); std::shared_ptr<Edge> edge23(new Edge(nodeH, nodeC, calculateCost(nodeH, nodeC))); edgeList.push_back(edge23); std::shared_ptr<Edge> edge24(new Edge(nodeH, nodeB, calculateCost(nodeH, nodeB))); edgeList.push_back(edge24); std::shared_ptr<Edge> edge25(new Edge(nodeH, nodeI, calculateCost(nodeH, nodeI))); edgeList.push_back(edge25); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeI); std::shared_ptr<Edge> edge26(new Edge(nodeI, nodeH, calculateCost(nodeI, nodeH))); edgeList.push_back(edge26); std::shared_ptr<Edge> edge27(new Edge(nodeI, nodeE, calculateCost(nodeI, nodeE))); edgeList.push_back(edge27); edgeListVector.push_back(edgeList); edgeList.clear(); nodeVector.push_back(nodeJ); std::shared_ptr<Edge> edge28(new Edge(nodeJ, nodeF, calculateCost(nodeJ, nodeF))); edgeList.push_back(edge28); edgeListVector.push_back(edgeList); edgeList.clear(); }