00001 //**************************************************** 00002 // April, 1993, University of Illinois 00003 // Copyright (C) 1993, 1994 Tianlin Wang 00004 /* Copyright (C) 1994-2003 Matvec Development Team. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with this library; if not, write to the Free 00018 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 MA 02111-1307, USA 00020 */ 00021 00022 #include "genome.h" 00023 00024 namespace matvec { 00025 00026 Genome* new_Genome_vec(const unsigned m, GeneticDist *D) 00027 { 00028 Genome *T = 0; 00029 if (m) { 00030 T = new Genome[m]; 00031 check_ptr(T); 00032 } 00033 if (D) { 00034 for (unsigned i=0; i<m; i++) T[i].remodel(D); 00035 } 00036 return T; 00037 } 00038 00039 Genome::Genome(GeneticDist *D) 00040 { 00041 numchrom = 0; 00042 chromosome = 0; 00043 remodel(D); 00044 } 00045 00046 Genome::Genome(const Genome& A) 00047 { 00048 numchrom = 0; 00049 chromosome = 0; 00050 copyfrom(A); 00051 } 00052 00053 void Genome::copyfrom(const Genome& A) 00054 { 00055 if (this == &A) return; 00056 numchrom = A.numchrom; 00057 if (chromosome) { 00058 delete [] chromosome; 00059 chromosome=0; 00060 } 00061 if(numchrom>0){ 00062 chromosome = new Chromosome [numchrom]; // each chrom should resize 00063 } 00064 else{ 00065 chromosome = 0; 00066 } 00067 for (unsigned i=0; i<numchrom; i++) chromosome[i] = A.chromosome[i]; 00068 } 00069 00070 const Genome& Genome::operator=(const Genome& A) 00071 { 00072 copyfrom(A); 00073 return *this; 00074 } 00075 00076 void Genome::remodel(GeneticDist *D) 00077 { 00078 numchrom = D->nchrom(); 00079 ChromStruct *Chrom = D->chrom(); 00080 if (chromosome) { 00081 delete [] chromosome; 00082 chromosome=0; 00083 } 00084 if (numchrom >0) { 00085 chromosome = new Chromosome [numchrom]; // each chrom should resize 00086 } 00087 else { 00088 chromosome = 0; 00089 } 00090 for (unsigned i=0; i<numchrom; i++) chromosome[i].resize(Chrom[i].nloci()); 00091 } 00092 00093 void Genome::resize(const unsigned nc, const unsigned nl) 00094 { 00095 numchrom = nc; 00096 if (chromosome) { 00097 delete [] chromosome; 00098 chromosome=0; 00099 } 00100 if(numchrom>0){ 00101 chromosome = new Chromosome [numchrom]; // each chrom should resize 00102 } 00103 else{ 00104 chromosome = 0; 00105 } 00106 for (unsigned i=0; i<numchrom; i++) chromosome[i].resize(nl); 00107 } 00108 00109 void Genome::release(void) 00110 { 00111 if (chromosome) { delete [] chromosome; chromosome = 0; } 00112 } 00113 00114 int Genome::chrom_id(const Chromosome& chrm) const 00115 { 00116 int retval = -1; 00117 Chromosome *C; 00118 unsigned i,j,nl; 00119 for (i=0; i<numchrom; i++) { 00120 C = &(chromosome[i]); 00121 nl = C->nloci(); 00122 for (j=0; j<nl; j++) { 00123 if (chrm.locus[j].allele != C->locus[j].allele) break; 00124 } 00125 if (j==nl) { 00126 retval = C->id(); 00127 break; 00128 } 00129 } 00130 return retval; 00131 } 00132 00133 } /////////// end of namespace matvec
1.2.16