⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allelestr.h

📁 moealib
💻 H
字号:
/******************************************************************************** *                                                                              * * -------------------   Class for Allele String -------------------------------* *                                                                              * * the allele set is consisted of the following symbols(characters):            * * 1. if alleles <= 10: 0, 1,..., 9                                             * * 2. if alleles <= 26: a, b,..., z                                             * *                                                                              * *                                                   xianming Chen, Aug, 2000   * *                                                   modified on Jan 14, 2001   * ********************************************************************************/#ifndef _AlleleStr_H_#define _AlleleStr_H_#include <iostream.h>#include <assert.h>#include "Random.h"class AlleleString  {  typedef unsigned char Allele; public:  AlleleString() : len(0), _alleles(0), data(NULL) { }  AlleleString(int ln, int als = 2) : len(ln), _alleles(als) { data = new Allele [len]; }  AlleleString(const AlleleString& other) { data = 0; len = -1; copy(other); }  virtual ~AlleleString() { delete [] data; }  void copy(const AlleleString& other);  AlleleString& operator= (const AlleleString& other) { copy(other); return *this; }  const Allele& operator[] (int index) const { assert(index<len); return data[index]; }  Allele& operator[] (int index)             { assert(index<len); return data[index]; }  void randomize() {     for(int i=0; i<len; i++) data[i] = Randint(0,_alleles-1) + (_alleles>10 ? 'a':'0');}  int length()  const { return len; }  int alleles() const { return _alleles; }  int hammingDistance(const AlleleString& s2) const {     int rt=0; for(int i=0; i<len; i++) if(data[i] != s2.data[i]) rt++; return rt; }  friend ostream& operator<< (ostream & os,const AlleleString& str);  friend bool operator== (const AlleleString&, const AlleleString&);  friend bool operator!= (const AlleleString& a, const AlleleString& b) { return !(a==b); } protected:  Allele* data;  int len;  int _alleles;};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -