MESSAGE
DATE | 2016-11-26 |
FROM | Ruben Safir
|
SUBJECT | Re: [Hangout-NYLXS] Fitch etc
|
sorry wrong list
On 11/26/2016 06:15 PM, Ruben Safir wrote:
> I finally fixed the type problem with my fitch program. Not that I've finished
> the program, but I finally understand the problem. I got lost in the data flow
> of the program. I am trying to print out the vector of states, which have objects
> of pairs. That requires an overload of operator<<() of the states object AND a range
> operation of the vector itself.
>
> http://www.nylxs.com/docs/thesis/src/fitch/nodes.h.html
>
> 1 /*
> 2 * =====================================================================================
> 3 *
> 4 * Filename: nodes.h
> 5 *
> 6 * Description: description of phylogentic nodes as per
> 7 * Fitch and Sannkoff as describd by Felenstein
> 8 *
> 9 * Version: 1.0
> 10 * Created: Nov 4 21:15:49 EDT 2016
> 11 * Revision: none
> 12 * Compiler: gcc
> 13 *
> 14 * Author: Ruben Safir,
> 15 * Company: LIU Thesis
> 16 *
> 17 * =====================================================================================
> 18 */
> 19 #ifndef NODES_H
> 20 #define NODES_H
> 21 #include
> 22 #include
> 23 #include
> 24 namespace tree {
> 25
> 26
> 27 /* ==============================================================================
> 28 * Class NODE -
> 29 * Description - This is a node in the tree that must undergo parsimony evaluation
> 30 * ================================================================================
> 31 */
> 32 template
> 33 class NODE{
> 34 public:
> 35 ¦ //=========================LIFECYCLE=========================================
> 36 ¦ /* Constructor */
> 37 NODE( std::string xt, const unk &x , NODE *xcl= 0, NODE *xcr = 0, NODE *xp = 0 ):_trait{xt},_states{x}, _cl{xcl}, _cr{xcr}, _p{xp} {//child left, child right etc
> 38 std::cout << trait() << " node " << "has the following states => " << states() << std::endl;
> 39 };
> 40
> 41 NODE(const NODE &other); //copy constructor
> 42 ¦ ~NODE();
> 43 ¦
> 44 ¦ /* ==================== ACCESSORS ======================================= */
> 45 //no need for inline when you are defineing functions within the class definition
> 46 std::string trait()const{
> 47 return _trait;
> 48 }
> 49 unk states()const{
> 50 ¦ ¦ return _states;
> 51 ¦ };
> 52 NODE * cl()const{
> 53 ¦ ¦ return _cl;
> 54 ¦ };
> 55 NODE * cr()const{
> 56 ¦ ¦ return _cr;
> 57 ¦ };
> 58 NODE * p()const{
> 59 ¦ ¦ return _p;
> 60 ¦ };
> 61 void states(const unk &x){
> 62 ¦ ¦ _states = x;
> 63 ¦ }
> 64 void trait(std::string xt){
> 65 ¦_trait = xt; //With genetics this is a A C G T although it is just a label
> 66 ¦}
> 67 void cl(NODE *xcl){ //This is the left child node in the tree
> 68 ¦ ¦ _cl = xcl;
> 69 ¦ }
> 70 void cr(NODE *xcr){//This is the right node child node in the tree
> 71 ¦ ¦ _cr = xcr;
> 72 ¦ }
> 73 void p(NODE *xp){//This is the parent node in the tree
> 74 ¦ ¦ _p = xp;
> 75 ¦ }
> 76 ¦ /* ==================== MUTATORS ======================================= */
> 77 ¦
> 78 ¦ /* ==================== OPERATORS ======================================= */
> 79 //void display();
> 80 template
> 81 friend std::ostream& operator<<(std::ostream& os, const T&);
> 82
> 83 template
> 84 friend std::ostream& operator<<(std::ostream& os, const NODE &);
> 85
> 86 protected:
> 87 ¦ /* ==================== DATA MEMBERS ======================================= */
> 88 ¦
> 89 ¦
> 90 private:
> 91 ¦ /* ==================== DATA MEMBERS ======================================= */
> 92 ¦std::string _trait;
> 93 ¦unk _states;
> 94 ¦NODE * _cl, * _cr, * _p;
> 95
> 96
> 97 }; /* ----- end of template class NODE ----- */
> 98
> 99 template
> 100 std::ostream& operator<<(std::ostream& os, const NODE& vec){
> 101
> 102 for( auto& y : vec.state() )
> 103 os << y << std::endl;
> 104 return os;
> 105 }
> 106
> 107
> 108
> 109 template
> 110 tree::NODE::~NODE(){
> 111 }
> 112
> 113 /*
> 114 * =====================================================================================
> 115 * Class: State
> 116 * Description: This describes a possible individual state or charactoristic
> 117 * =====================================================================================
> 118 */
> 119 template
> 120 class state
> 121 {
> 122 public:
> 123 /* ==================== LIFECYCLE ======================================= */
> 124 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦/* constructor */
> 125 //r is the minimum cost of a single state when compared to the child nodes
> 126 explicit state(std::string const xa, cost xr)
> 127 :_nam{xa}, _r{xr}
> 128 {
> 129 std::cout << "Building a state pair" << std::endl;
> 130 std::cout << "nam => " << nam() << "\tcost=> " << r() << std::endl;
> 131 };
> 132
> 133
> 134 /* ==================== ACCESSORS ======================================= */
> 135 std::string nam()const {return _nam;};
> 136 cost r() const {return _r;};
> 137 void r(cost b ){_r = b;};
> 138 /* ==================== MUTATORS ======================================= */
> 139
> 140 /* ==================== OPERATORS ======================================= */
> 141 friend std::ostream & operator << ( std::ostream & os, const state & obj )
> 142 {
> 143 os << obj.nam() << ": " << obj.r() ;
> 144 return os;
> 145 } /* ----- end of function operator << ----- */
> 146
> 147 /* ==================== DATA MEMBERS ======================================= */
> 148 protected:
> 149
> 150 private:
> 151 std::string _nam;
> 152 cost _r;
> 153
> 154 }; /* ----- end of class State ----- */
> 155
> 156 /*
> 157 * =====================================================================================
> 158 * Class: Pstates
> 159 * Description: vector of all possible states
> 160 * =====================================================================================
> 161 */
> 162 template
> 163 class Pstates
> 164 {
> 165 public:
> 166
> 167 /* ==================== LIFECYCLE ======================================= */
> 168 /* constructor */
> 169 Pstates (std::vector< state > x)
> 170 : _vstate{x}
> 171 {
> 172 for( auto& y : _vstate)
> 173 std::cout << y << std::endl;
> 174 };
> 175
> 176 ~Pstates (){}; /* destructor */
> 177
> 178 /* ==================== ACCESSORS ======================================= */
> 179 const std::vector< state >& vstate() const{
> 180 return _vstate;
> 181 }
> 182 void vstate(std::vector< state > in ){
> 183 _vstate = in;
> 184 }
> 185
> 186 /* ==================== MUTATORS ======================================= */
> 187
> 188 /* ==================== OPERATORS ======================================= */
> 189
> 190 const Pstates& operator = ( const Pstates &other ); /* assignment operator */
> 191 ¦
> 192 friend std::ostream & operator << ( std::ostream & os, const Pstates & obj )
> 193 {
> 194 for(auto state_pair : obj.vstate() )
> 195 std::cout << state_pair;
> 196 return os;
> 197 } /* ----- end of function operator << ----- */
> 198
> 199 /* ==================== DATA MEMBERS ======================================= */
> 200 protected:
> 201
> 202 private:
> 203 std::vector< state > _vstate;
> 204
> 205 }; /* ----- end of class Pstates ----- */
>
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
_______________________________________________
hangout mailing list
hangout-at-nylxs.com
http://www.nylxs.com/
|
|