Commit e1d78225 authored by Stephen Smith's avatar Stephen Smith
Browse files

fixed most of the memory problems for larger numbers of trees

parent fd74079b
This diff is collapsed.
......@@ -90,7 +90,7 @@ public:
#ifdef BIGTREE
VectorNodeObject<mpfr_class> conditionals(Node & node, bool marg, bool sparse);
#else
VectorNodeObject<double> conditionals(Node & node, bool marg, bool sparse);
vector<double> conditionals(Node & node, bool marg, bool sparse);
#endif
//void ancdist_conditional_lh(bpp::Node & node, bool marg);
void ancdist_conditional_lh(Node & node, bool marg);
......
......@@ -12,8 +12,6 @@
#include <vector>
using namespace std;
#include "vector_node_object.h"
BranchSegment::BranchSegment(double dur,int per):duration(dur),period(per),
model(NULL),fossilareaindices(vector<int>()),startdistint(-666),
distconds(NULL),ancdistconds(NULL){}
......
......@@ -48,12 +48,12 @@ class BranchSegment{
VectorNodeObject<mpfr_class> seg_sp_stoch_map_revB_time;
VectorNodeObject<mpfr_class> seg_sp_stoch_map_revB_number;
#else
VectorNodeObject<double> * distconds;
VectorNodeObject<double> alphas; // alpha for the entire branch -- stored in the 0th segment for anc calc
VectorNodeObject<double> seg_sp_alphas; // alpha for this specific segment, stored for the stoch map
VectorNodeObject<double> seg_sp_stoch_map_revB_time; //segment specific rev B, combining the tempA and the ENLT
VectorNodeObject<double> seg_sp_stoch_map_revB_number; //segment specific rev B, combining the tempA and the ENLT
VectorNodeObject<double> * ancdistconds;//for ancestral state reconstructions
vector<double> * distconds;
vector<double> alphas; // alpha for the entire branch -- stored in the 0th segment for anc calc
vector<double> seg_sp_alphas; // alpha for this specific segment, stored for the stoch map
vector<double> seg_sp_stoch_map_revB_time; //segment specific rev B, combining the tempA and the ENLT
vector<double> seg_sp_stoch_map_revB_number; //segment specific rev B, combining the tempA and the ENLT
vector<double> * ancdistconds;//for ancestral state reconstructions
#endif
};
......
......@@ -685,10 +685,11 @@ int main(int argc, char* argv[]){
* end stochastic mapping
*/
}
//need to delete the biogeostuff
}
for(unsigned int i=0;i<intrees.size();i++){
delete intrees[i];
delete intrees[i];
}
}
return 0;
......
......@@ -15,22 +15,25 @@
using namespace std;
#include "node.h"
#include "BranchSegment.h"
#include "node_object.h"
#include "string_node_object.h"
#include "vector_node_object.h"
Node::Node():BL(0.0),height(0.0),number(0), name(""),
parent(NULL),children(vector<Node *> ()),assoc(map<string,NodeObject *>()),
comment(""){}
assocDV(map<string,vector<double> >()),comment(""){
}
Node::Node(Node * inparent):BL(0.0),height(0.0),number(0), name(""),
parent(inparent),children(vector<Node *> ()),assoc(map<string,NodeObject *>()),
comment(""){}
assocDV(map<string,vector<double> >()),comment(""){
}
Node::Node(double bl,int innumber,string inname, Node * inparent)
:BL(bl),height(0.0),number(innumber), name(inname),
parent(inparent),children(vector<Node *> ()),assoc(map<string,NodeObject *>()),
comment(""){}
Node::Node(double bl,int innumber,string inname, Node * inparent) :BL(bl),height(0.0),
number(innumber), name(inname),parent(inparent),children(vector<Node *> ()),
assoc(map<string,NodeObject *>()),assocDV(map<string,vector<double> >()),comment(""){
}
vector<Node*> Node::getChildren(){
return children;
......@@ -243,11 +246,51 @@ int Node::getChildCount(){
void Node::assocObject(string name,NodeObject & obj){
//need to see why this doesn't work
//if(assoc.count(name) > 0) //take this out if doesn't work
// delete assoc[name];
//if(assoc.count(name) > 0){ //take this out if doesn't work
//delete assoc[name];
//}
assoc[name] = obj.clone();
}
void Node::assocDoubleVector(string name, vector<double> & obj){
if (assocDV.count(name) > 0 ){
assocDV.erase(name);
}
vector<double> tvec (obj.size());
for (unsigned int i=0;i<obj.size();i++){
tvec[i] = obj[i];
}
assocDV[name] = tvec;
}
vector<double> * Node::getDoubleVector(string name){
return &assocDV[name];
}
void Node::deleteDoubleVector(string name){
if (assocDV.count(name) > 0 ){
assocDV.erase(name);
}
}
void Node::assocSegVector(vector<BranchSegment> & obj){
segs = new vector<BranchSegment> ();
for (unsigned int i=0;i<obj.size();i++){
segs->push_back(obj[i]);
}
}
vector<BranchSegment> * Node::getSegVector(){
return segs;
}
void Node::deleteSegVector(){
if (segs->size() > 0 ){
delete segs;
}
}
/*
* use the string ones like this
* StringNodeObject sno("...a node object");
......
......@@ -15,6 +15,8 @@ using namespace std;
#include "node_object.h"
#include "vector_node_object.h"
#include "BranchSegment.h"
class Node{
private:
......@@ -25,7 +27,9 @@ private:
Node * parent;
vector<Node *> children;
map<string,NodeObject *> assoc;
map<string, vector<double> > assocDV;
string comment;
vector<BranchSegment> * segs;
public:
Node();
......@@ -58,6 +62,12 @@ public:
Node * getParent();
int getChildCount();
void assocObject(string name,NodeObject & obj);
void assocDoubleVector(string name, vector<double> & obj);
vector<double> * getDoubleVector(string name);
void deleteDoubleVector(string name);
void assocSegVector(vector<BranchSegment> & obj);
vector<BranchSegment> * getSegVector();
void deleteSegVector();
NodeObject * getObject(string name);
};
......
......@@ -18,8 +18,8 @@ public:
virtual ~NodeObject() {}
public:
virtual NodeObject * clone() const = 0;
virtual string type() {return "base";}
};
#endif /* NODE_OBJECT_H_ */
......@@ -24,11 +24,15 @@ public:
VectorNodeObject(typename vector<T>::iterator start, typename vector<T>::iterator end):
vector<T>(start, end) {}
virtual ~VectorNodeObject() {}
public:
virtual ~VectorNodeObject()
{}
virtual string type() const{
return "vector";
}
VectorNodeObject<T> * clone() const { return new VectorNodeObject<T>(*this); }
};
#endif /* NODE_OBJECT_H_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment