📄 rep.cc
字号:
vector = NULL; } for (i=0; i<number_of_pts; i++) { vector[i] = array[i]; } } else { (void)fprintf(logFile,"Unable to invoke operator= because Representations don't match!\n"); // used to be "stderr" } return(*this);}ConstrainedRealVector::ConstrainedRealVector(int num_els): Representation(num_els){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/ConstrainedRealVector::ConstrainedRealVector(int num_els) \n");#endif /* DEBUG */ mytype = T_CRealV; normalized = 0; vector = new double[num_els]; for (; --num_els>=0;) { vector[num_els] = double(genunf(low, high)); }// normalize();}ConstrainedRealVector::ConstrainedRealVector(int num_els, double init_low, double init_high): Representation(num_els){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/ConstrainedRealVector::ConstrainedRealVector(int num_els=%d, double init_low=%lf, double init_high=%lf) \n",num_els,init_low,init_high);#endif /* DEBUG */ mytype = T_CRealV; normalized = 0; vector = new double[num_els]; for (; --num_els>=0;) { vector[num_els] = double(genunf(init_low, init_high)); }// normalize();}ConstrainedRealVector::ConstrainedRealVector(const ConstrainedRealVector &original): Representation(original.number_of_pts){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/ConstrainedRealVector::ConstrainedRealVector(const ConstrainedRealVector &original) \n");#endif /* DEBUG */ mytype = T_CRealV; normalized = original.normalized; if (original.vector != NULL) { vector = new double[original.number_of_pts]; } else { vector = NULL; } for (register int i=0; i<original.number_of_pts; i++) { vector[i] = original.vector[i]; }}void ConstrainedRealVector::write(unsigned char value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::write(unsigned char value=%c, int gene=%d) \n",value,gene);#endif /* DEBUG */ (void)fprintf(logFile,"Writing a Bit to a Constrained Real\n"); // used to be "stderr" (void)fprintf(logFile,"value= \"%c\", gene= %d\n", value, gene); // used to be "stderr"}void ConstrainedRealVector::write(FourByteLong value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::write(FourByteLong value=%ld, int gene=%d) \n",value,gene);#endif /* DEBUG */ (void)fprintf(logFile,"Writing an Integer to a Constrained Real\n"); // used to be "stderr" (void)fprintf(logFile,"value= %ld, gene= %d\n",value,gene); // used to be "stderr"}void ConstrainedRealVector::write(double value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::write(double value=%lf, int gene=%d) \n",value,gene);#endif /* DEBUG */ if (value<low) { (void)fprintf(logFile,"Writing out-of-bounds Constrained Real\n"); // used to be "stderr" vector[gene] = low; } else if (value>high) { (void)fprintf(logFile,"Writing out-of-bounds Constrained Real\n"); // used to be "stderr" vector[gene] = high; } else { vector[gene] = value; } normalized = 0;}/*void ConstrainedRealVector::write(const void *value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::write(const void *value, int gene=%d) \n",gene);#endif // * DEBUG * / if (*((double *)value)<low) { vector[gene] = low; } else if (*((double *)value)>high) { vector[gene] = high; } else { vector[gene] = *((double *)value); } normalized = 0;}*/void ConstrainedRealVector::write(const Element value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::write(const Element value, int gene=%d) \n",gene);#endif /* DEBUG */ if (value.real<low) { vector[gene] = low; } else if (value.real>high) { vector[gene] = high; } else { vector[gene] = value.real; } normalized = 0;}void ConstrainedRealVector::normalize(void) const{ //unsigned char *kluge; commented out by gmm, 9-17-97#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void ConstrainedRealVector::normalize(void) const \n");#endif /* DEBUG */// kluge = &normalized; if (!normalized) { register int i; register double tempsum = 0.0, hypotenuse; for (i=0; i<number_of_pts; i++) { tempsum+=vector[i]*vector[i]; } if ((tempsum-sum>ACCURACY)||(sum-tempsum>ACCURACY)) { hypotenuse = sqrt(tempsum); for (i=0; i<number_of_pts; i++) { vector[i] /= hypotenuse; } } //normalized = 1; //*kluge = 1; commented out by gmm, 9-17-97 }}/*const void *ConstrainedRealVector::gene(unsigned int gene_number) const{#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const void *ConstrainedRealVector::gene(unsigned int gene_number=%d) const \n",gene_number);#endif // * DEBUG * / if (gene_number>=number_of_pts) { (void)fprintf(logFile,"Trying to access an out-of-bounds gene\n"); // used to be "stderr" return(NULL); } else {// normalize(); return((void *)(&vector[gene_number])); }}*/const Element ConstrainedRealVector::gene(unsigned int gene_number) const{ Element retval;#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const Element ConstrainedRealVector::gene(unsigned int gene_number=%d) const \n",gene_number);#endif /* DEBUG */ if (gene_number>=number_of_pts) { (void)fprintf(logFile,"Trying to access an out-of-bounds gene\n"); // used to be "stderr" retval.real = 0.0; return(retval); } else {// normalize(); retval.real = 0.0; return(retval); }}const void *ConstrainedRealVector::internals(void) const{#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const void *ConstrainedRealVector::internals(void) const \n");#endif /* DEBUG */ return((void *)(&vector[0]));}Representation &ConstrainedRealVector::operator=(const Representation &original){ register int i; double *array;#ifdef DEBUG (void)fprintf(logFile, "rep.cc/Representation &ConstrainedRealVector::operator=(const Representation &original) \n");#endif /* DEBUG */ array = (double *)original.internals(); if (original.type()==T_CRealV) { number_of_pts = original.number_of_points(); normalized = original.is_normalized(); if (vector!=NULL) { delete [] vector; } if (array!=NULL) { vector = new double[number_of_pts]; } else { vector = NULL; } for (i=0; i<number_of_pts; i++) { vector[i] = array[i]; } } else { (void)fprintf(logFile,"Unable to invoke operator= because Representations don't match!\n"); // used to be "stderr" } return(*this);}// This constructor is used to initialize the first// generation of any particular bitvector. Right// now bits are assumed to be unsigned chars.BitVector::BitVector(int num_els): Representation(num_els){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/BitVector::BitVector(int num_els=%d) \n",num_els);#endif /* DEBUG */ mytype = T_BitV; vector = new unsigned char[num_els]; for (; --num_els>=0;) { vector[num_els] = ((ranf()<one_prob)? 1 : 0); }}BitVector::BitVector(int num_els, float prob): Representation(num_els){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/BitVector::BitVector(int num_els=%d, float prob=%f) \n",num_els,prob);#endif /* DEBUG */ mytype = T_BitV; vector = new unsigned char[num_els]; for (; --num_els>=0;) { vector[num_els] = ((ranf()<prob)? 1 : 0); }}// There are probably better ways of doing this, e.g.// using memcpy()BitVector::BitVector(const BitVector &original): Representation(original.number_of_pts){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/BitVector::BitVector(const BitVector &original) \n");#endif /* DEBUG */ mytype = T_BitV; if (original.vector!=NULL) { vector = new unsigned char[number_of_pts]; } else { vector = NULL; } for (register int i=0; i<number_of_pts; i++) { vector[i] = original.vector[i]; }}void BitVector::write(unsigned char value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void BitVector::write(unsigned char value=%c, int gene=%d) \n",value,gene);#endif /* DEBUG */ vector[gene] = value;}void BitVector::write(FourByteLong value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void BitVector::write(FourByteLong value=%ld, int gene=%d) \n",value,gene);#endif /* DEBUG */ (void)fprintf(logFile,"Writing Int to Bit!\n"); // used to be "stderr" (void)fprintf(logFile,"value= %ld, gene= %d\n",value,gene); // used to be "stderr"}void BitVector::write(double value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void BitVector::write(double value=%lf, int gene=%d) \n",value,gene);#endif /* DEBUG */ (void)fprintf(logFile,"Writing Real to Bit!\n"); // used to be "stderr" (void)fprintf(logFile,"value= %lf, gene= %d\n",value,gene); // used to be "stderr"}/*void BitVector::write(const void *value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void BitVector::write(const void *value, int gene=%d) \n",gene);#endif // * DEBUG * / vector[gene] = *((unsigned char *)value);}*/void BitVector::write(const Element value, int gene){#ifdef DEBUG (void)fprintf(logFile, "rep.cc/void BitVector::write(const Element value, int gene=%d) \n",gene);#endif /* DEBUG */ vector[gene] = value.bit;}/*const void *BitVector::gene(unsigned int gene_number) const{#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const void *BitVector::gene(unsigned int gene_number=%d) const \n",gene_number);#endif // * DEBUG * / if (gene_number>=number_of_pts) { (void)fprintf(logFile,"Trying to access an out-of-bounds gene\n"); // used to be "stderr" return(NULL); } else { return((void *)(&vector[gene_number])); }}*/const Element BitVector::gene(unsigned int gene_number) const{ Element retval;#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const Element BitVector::gene(unsigned int gene_number=%d) const \n",gene_number);#endif /* DEBUG */ if (gene_number>=number_of_pts) { (void)fprintf(logFile,"Trying to access an out-of-bounds gene\n"); // used to be "stderr" retval.bit = 0; return(retval); } else { retval.bit = vector[gene_number]; return(retval); }}const void *BitVector::internals(void) const{#ifdef DEBUG (void)fprintf(logFile, "rep.cc/const void *BitVector::internals(void) const \n");#endif /* DEBUG */ return((void *)(&vector[0]));}Representation &BitVector::operator=(const Representation &original){ register int i; unsigned char *array;#ifdef DEBUG (void)fprintf(logFile, "rep.cc/Representation &BitVector::operator=(const Representation &original) \n");#endif /* DEBUG */ array = (unsigned char *)original.internals(); if (original.type()==T_BitV) { if (vector!=NULL) { delete [] vector; } number_of_pts = original.number_of_points(); if (array!=NULL) { vector = new unsigned char[number_of_pts]; } else { vector = NULL; } for (i=0; i<number_of_pts; i++) { vector[i] = array[i]; } } else { (void)fprintf(logFile,"Unable to invoke operator= because Representations don't match!\n"); // used to be "stderr" } return(*this);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -