亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ex5.c

?? 遺傳算法的源程序例子
?? C
字號:
/* ----------------------------------------------------------------------------  ex5.C  mbwall 10dec94  Copyright 1995-1996  Massachusetts Institute of Technology DESCRIPTION:   Example program for a composite genome derived from the GAGenome andcontaining a 2DBinStr genome and a Bin2Dec genome.  This program usesa steady-state GA to match a 2D pattern in the 2DBinStr part of the genomeand a sequence of numbers in the Bin2Dec part.   In this example we derive a new genome and a new crossover object to beused with it.  All of the operators (initialization, mutation, crossover, comparison, and objective) are defined as member functions but are alsooverride-able on any instance of the new genome.---------------------------------------------------------------------------- */#include <stdio.h>#include <stdlib.h>#include <iostream.h>#include <fstream.h>#include <math.h>#include <ga/GABin2DecGenome.h>#include <ga/GA2DBinStrGenome.h>#include <ga/GASStateGA.h>// This is the class definition for the new genome.  The default operators are// defined as static member functions.  They can be overridden if necessary by// anyone making an instance of this class - you don't need to derive a new// class to change the behaviour of one or two of its operators.class CompositeGenome : public GAGenome {public:  GADefineIdentity("CompositeGenome", 201);  static void CompositeInitializer(GAGenome&);  static int CompositeMutator(GAGenome&, float);  static float CompositeComparator(const GAGenome&, const GAGenome&);  static int CompositeCrossover(const GAGenome&, const GAGenome&,				GAGenome*, GAGenome*);public:  CompositeGenome(int, int, GABin2DecPhenotype&, 		  GAGenome::Evaluator f=NULL, void* u=NULL);  CompositeGenome(const CompositeGenome & orig);  CompositeGenome& operator=(const GAGenome& g);  virtual ~CompositeGenome();  virtual GAGenome* clone(GAGenome::CloneMethod) const ;  virtual void copy(const GAGenome & c);  virtual int equal(const GAGenome& g) const;  virtual int read(istream & is);  virtual int write(ostream & os) const;  GA2DBinaryStringGenome & binstr() const {return *str;}  GABin2DecGenome & bin2dec() const {return *b2d;}protected:  GA2DBinaryStringGenome *str;  GABin2DecGenome *b2d;};// Member functions for the composite genome objectCompositeGenome::CompositeGenome(int element, int bond, GABin2DecPhenotype& p, 		GAGenome::Evaluator f, void* u) :		GAGenome(  CompositeInitializer,			 CompositeMutator,			 CompositeComparator) {		  evaluator(f); userData(u); crossover(CompositeCrossover);		  str = new GA2DBinaryStringGenome(element, bond, f, u);		  b2d = new GABin2DecGenome(p, f, u);		}CompositeGenome::CompositeGenome(const CompositeGenome & orig) {  str = new GA2DBinaryStringGenome(orig.binstr());  b2d = new GABin2DecGenome(orig.bin2dec());  copy(orig);}  CompositeGenome& CompositeGenome::operator=(const GAGenome& g) { copy(g); return *this; }CompositeGenome::~CompositeGenome() { delete str; delete b2d; }GAGenome* CompositeGenome::clone(GAGenome::CloneMethod) const {  return new CompositeGenome(*this);}void CompositeGenome::copy(const GAGenome & c){  if(&c != this && sameClass(c)){    GAGenome::copy(c);    CompositeGenome & bc = (CompositeGenome &)c;    str->copy(*(bc.str));    b2d->copy(*(bc.b2d));  }}int CompositeGenome::equal(const GAGenome& g) const {  CompositeGenome& genome = (CompositeGenome&)g;  return ((*str == *genome.str) && (*b2d == *genome.b2d));}int CompositeGenome::read(istream & is) {  is >> *str >> *b2d;   return is.fail() ? 1 : 0; }int CompositeGenome::write(ostream & os) const {  int i,j;  for(j=0; j<str->height(); j++){    for(i=0; i<str->width(); i++)      os << (str->gene(i,j) == 1 ? '*' : ' ') << " ";    os << "\n";  }  os << "\n" << *b2d << "\n";  return os.fail() ? 1 : 0;}// These are the default initialization, mutation, and comparator operators for// this genome class.  They are defined as static functions of the composite// genome class and they're defaults for the class.  But they can be overridden// on any instance of the genome.// The initializer just calls the initializer for each of the genomes that are// in the composite genome.// I would have used simply 'Initializer', 'Mutator', etc rather than// 'CompositeInitializer' but old versions of g++ are brain-dead and don't// get the encapsulation properly.void CompositeGenome::CompositeInitializer(GAGenome & c) {  CompositeGenome & child = (CompositeGenome &)c;  child.binstr().initialize();  child.bin2dec().initialize();  child._evaluated = gaFalse;}// The mutator just calls the mutator for each of the component genomes.int CompositeGenome::CompositeMutator(GAGenome & c, float pmut) {  CompositeGenome & child = (CompositeGenome &)c;  int nmut = child.binstr().mutate(pmut) + child.bin2dec().mutate(pmut);  if(nmut) child._evaluated = gaFalse;  return nmut;}// The comparator just calls the comparators for each of the component genomes,// then averages the score.float CompositeGenome::CompositeComparator(const GAGenome& a, const GAGenome& b) {  CompositeGenome& sis = (CompositeGenome &)a;  CompositeGenome& bro = (CompositeGenome &)b;  return 0.5 * (sis.binstr().compare(bro) + sis.bin2dec().compare(bro));}// The crossover operator invokes the crossover for each of the genomes in the// composite genome.  We use sexual crossover only, and we do not test to see// if no crossover has been assigned.intCompositeGenome::CompositeCrossover(const GAGenome& a, const GAGenome& b,		   GAGenome* c, GAGenome* d){   CompositeGenome& mom = (CompositeGenome&)a;  CompositeGenome& dad = (CompositeGenome&)b;  int n=0;  GAGenome::SexualCrossover strcross = mom.str->sexual();  GAGenome::SexualCrossover b2dcross = mom.b2d->sexual();  if(c && d){    CompositeGenome& sis = (CompositeGenome&)*c;    CompositeGenome& bro = (CompositeGenome&)*d;    (*strcross)(mom.binstr(), dad.binstr(), &sis.binstr(), &bro.binstr());    (*b2dcross)(mom.bin2dec(),dad.bin2dec(), &sis.bin2dec(), &bro.bin2dec());    sis._evaluated = gaFalse;    bro._evaluated = gaFalse;    n = 2;  }  else if(c){    CompositeGenome& sis = (CompositeGenome&)*c;    (*strcross)(mom.binstr(), dad.binstr(), &sis.binstr(), 0);    (*b2dcross)(mom.bin2dec(), dad.bin2dec(), &sis.bin2dec(), 0);    sis._evaluated = gaFalse;    n = 1;  }  else if(d){    CompositeGenome& bro = (CompositeGenome&)*d;    (*strcross)(mom.binstr(), dad.binstr(), 0, &bro.binstr());    (*b2dcross)(mom.bin2dec(), dad.bin2dec(), 0, &bro.bin2dec());    bro._evaluated = gaFalse;    n = 1;  }  return n;}// This object is a container for the data that we are supposed to match in // our objective function.typedef struct _CompositeData {  short ** str;  float * b2d;} CompositeData;// In this objective function we try to match the pattern in the 2D part of the// genome and match the sequence of values in the binary-to-decimal part of the// genome.  The overall score is the sum of both parts.floatObjective(GAGenome & g) {  CompositeGenome & genome = (CompositeGenome &)g;  GA2DBinaryStringGenome & str = genome.binstr();  GABin2DecGenome & b2d = genome.bin2dec();  int i;  short **pattern = ((CompositeData *)g.userData())->str;  float val1=0.0;  for(i=0; i<str.width(); i++)    for(int j=0; j<str.height(); j++)      val1 += (float)(str.gene(i,j) == pattern[i][j]);  float *sequence = ((CompositeData *)g.userData())->b2d;  float val2=b2d.nPhenotypes();  for(i=0; i<b2d.nPhenotypes(); i++)    val2 += 1.0 / (1.0 + fabs(b2d.phenotype(i) - sequence[i]));  return(val1 + val2);}intmain(int argc, char *argv[]){  cout << "Example 5\n\n";  cout << "This program shows how to use a composite genome.  It reads\n";  cout << "a matrix from a data file and a set of values to be matched in\n";  cout << "a binary-to-decimal genome then uses a steady-state GA to\n";  cout << "match the pattern and value set.\n\n";// See if we've been given a seed to use (for testing purposes).  When you// specify a random seed, the evolution will be exactly the same each time// you use that seed number.  for(int ii=1; ii<argc; ii++) {    if(strcmp(argv[ii++],"seed") == 0) {      GARandomSeed((unsigned int)atoi(argv[ii]));    }  }  GAParameterList params;  GASteadyStateGA::registerDefaultParameters(params);  params.set(gaNpReplacement, 0.5);  params.set(gaNscoreFilename, "bog.dat");  params.set(gaNflushFrequency, 10);  params.set(gaNnGenerations, 800);  params.parse(argc, argv, gaFalse);  int i,j, n;  char filename1[128] = "smiley.txt";  char filename2[128] = "values.txt";  for(i=1; i<argc; i++){    if(strcmp("graph", argv[i]) == 0){      if(++i >= argc){        cerr << argv[0] << ": you must specify a filename.\n";        exit(1);      }      else{        sprintf(filename1, argv[i]);        continue;      }    }    else if(strcmp("values", argv[i]) == 0){      if(++i >= argc){        cerr << argv[0] << ": you must specify a filename.\n";        exit(1);      }      else{        sprintf(filename2, argv[i]);        continue;      }    }    else if(strcmp("seed", argv[i]) == 0){      if(++i < argc) continue;      continue;    }    else {      cerr << argv[0] << ":  unrecognized arguement: " << argv[i] << "\n\n";      cerr << "valid arguements include standard GAlib flags plus:\n";      cerr << "  graph\tname of graph filename (" << filename1 << ")\n";      cerr << "  values\tname of values filename (" << filename2 << ")\n";      cerr << "\n";      exit(1);    }  }  ifstream infile;// First we read in the pattern for the 2DBinStr genome.// File format is pretty simple://   two integers that give the height then width of the matrix,//   then the matrix of 1's and 0's (with whitespace inbetween).  infile.open(filename1, ios :: in);  if(!infile){    cerr << "Cannot open " << filename1 << " for input.\n";    exit(1);  }  int height, width;  infile >> height;  infile >> width;  short **target = new short*[width];  for(i=0; i<width; i++)    target[i] = new short[height];  for(j=0; j<height; j++)    for(i=0; i<width; i++)      infile >> target[i][j];  infile.close();// Now we read in a sequence of numbers that the Bin2Dec genome is supposed// to match for its objective.  File format is// pretty simple:  a single integer that tells how many numbers will follow,// then the sequence of numbers.  infile.open(filename2, ios :: in);  if(!infile){    cerr << "Cannot open " << filename2 << " for input.\n";    exit(1);  }  infile >> n;  float *sequence = new float[n];  for(i=0; i<n; i++)      infile >> sequence[i];  infile.close();// Print out the pattern and sequence.  cout << "input pattern:\n";  for(j=0; j<height; j++){    for(i=0; i<width; i++)      cout << (target[i][j] == 1 ? '*' : ' ') << " ";    cout << "\n";  }  cout << "\n"; cout.flush();  cout << "input sequence:\n";  for(i=0; i<n; i++)    cout << sequence[i] << " ";  cout << "\n"; cout.flush();// Create a phenotype then fill it with the phenotypes we will need to map to// the values we read from the file.  The arguments to the add() method of a// Bin2Dec phenotype are (1) number of bits, (2) min value, and (3) max value.// The phenotype maps a floating-point number onto the number of bits that// you designate.  Here we just make everything use 8 bits and pick a min and// max based upon the number we read in from the file.  You can experiment with// the number of bits and max/min values in order to make the GA work better// or worse.  GABin2DecPhenotype map;  for(i=0; i<n; i++)    map.add(12, 0.5*sequence[i], 2.0*sequence[i]);// Create an instance of our user data structure and stuff it with the values// that we read in from the files.  CompositeData mydata;  mydata.str = target;  mydata.b2d = sequence;// Now create the GA and run it.  First a genome, then the GA.  CompositeGenome genome(width, height, map, Objective, (void *)&mydata);  GASteadyStateGA ga(genome);  ga.parameters(params);  ga.parameters(argc,argv);  ga.evolve();  genome = ga.statistics().bestIndividual();  cout << "\nthe ga generated:\n" << genome << "\n";// Don't forget to free up the memory we allocated.  for(i=0; i<width; i++)    delete target[i];  delete [] target;  delete [] sequence;  return 0;}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产91综合一区在线观看| 一区二区三区鲁丝不卡| 国产麻豆精品视频| 精品国产乱码久久久久久图片| 老司机精品视频导航| 久久夜色精品国产噜噜av| 国产一区二区毛片| 国产亚洲欧洲一区高清在线观看| 成人在线视频一区| 亚洲女子a中天字幕| 精品婷婷伊人一区三区三| 麻豆91精品视频| 中文字幕av一区二区三区高| 91麻豆123| 青草av.久久免费一区| 日本一区二区不卡视频| 欧美在线一二三四区| 色妹子一区二区| 日韩精品一区二区三区老鸭窝| 久久精品国产99国产精品| 中文字幕一区二区三区在线不卡 | 《视频一区视频二区| 欧美午夜不卡在线观看免费| 美洲天堂一区二卡三卡四卡视频| 国产色产综合色产在线视频| 日本高清无吗v一区| 青青青爽久久午夜综合久久午夜| 国产亚洲一二三区| 欧美日韩在线观看一区二区 | 欧美国产乱子伦| 欧美系列在线观看| 国产一二精品视频| 亚洲综合激情网| 久久蜜臀中文字幕| 欧美精品在欧美一区二区少妇| 国产经典欧美精品| 日韩中文欧美在线| 1000部国产精品成人观看| 精品入口麻豆88视频| 色综合久久中文字幕综合网| 蜜乳av一区二区三区| 亚洲在线视频网站| 中文字幕免费观看一区| 日韩午夜av一区| 欧美性生活影院| eeuss鲁片一区二区三区在线观看| 美洲天堂一区二卡三卡四卡视频| 一区二区三区电影在线播| 精品国产乱码久久久久久闺蜜 | 激情综合网av| 亚洲成a人片综合在线| 亚洲人成网站影音先锋播放| 国产午夜精品一区二区三区四区| 日韩三级中文字幕| 欧美性极品少妇| eeuss鲁片一区二区三区| 国产黄色91视频| 韩国女主播成人在线| 免费看欧美女人艹b| 亚洲高清免费视频| 亚洲精品乱码久久久久久久久| 国产精品网曝门| 精品福利在线导航| 日韩欧美国产高清| 91精品国产福利在线观看| 在线精品观看国产| 色视频一区二区| 91激情五月电影| 91丨九色丨蝌蚪富婆spa| 波多野结衣在线aⅴ中文字幕不卡| 国产69精品一区二区亚洲孕妇| 精品一区二区三区香蕉蜜桃| 卡一卡二国产精品| 蜜臀va亚洲va欧美va天堂| 日韩精品亚洲专区| 日本亚洲一区二区| 蜜臀精品久久久久久蜜臀 | 国产精品一区二区在线播放| 激情小说欧美图片| 美女国产一区二区三区| 麻豆精品在线播放| 国产九九视频一区二区三区| 国产精品一区二区在线观看不卡| 国产sm精品调教视频网站| 成人做爰69片免费看网站| 99热这里都是精品| 色综合久久66| 7777精品伊人久久久大香线蕉经典版下载| 在线观看一区不卡| 欧美高清性hdvideosex| 欧美α欧美αv大片| 国产欧美精品一区aⅴ影院| 国产精品丝袜一区| 亚洲伊人色欲综合网| 日本女人一区二区三区| 国产精品一卡二| 99久久久国产精品| 欧美欧美午夜aⅴ在线观看| 欧美一级理论片| 国产精品人人做人人爽人人添| 悠悠色在线精品| 日本v片在线高清不卡在线观看| 韩国精品主播一区二区在线观看| 丰满少妇在线播放bd日韩电影| 色视频一区二区| 欧美videos大乳护士334| 国产精品美女视频| 亚洲成国产人片在线观看| 狠狠v欧美v日韩v亚洲ⅴ| 成人理论电影网| 911国产精品| 国产视频一区二区在线观看| 亚洲精品视频免费观看| 裸体歌舞表演一区二区| heyzo一本久久综合| 7777女厕盗摄久久久| 国产精品成人免费精品自在线观看 | 成人午夜激情影院| 精品视频一区二区不卡| 26uuu国产一区二区三区| 亚洲久本草在线中文字幕| 免费日韩伦理电影| 91麻豆福利精品推荐| 精品日韩一区二区三区免费视频| 1000部国产精品成人观看| 美国十次综合导航| 欧美这里有精品| 国产精品三级av在线播放| 日本午夜一本久久久综合| 91在线播放网址| 久久久久久久综合色一本| 午夜欧美电影在线观看| 99riav一区二区三区| 精品国产伦一区二区三区观看方式| 亚洲伊人色欲综合网| 成人午夜在线视频| 亚洲精品一区二区三区精华液| 亚洲综合久久久| 91麻豆国产福利精品| 国产无人区一区二区三区| 免费观看久久久4p| 色94色欧美sute亚洲线路一久| 国产日产欧美一区| 麻豆精品新av中文字幕| 欧美日韩久久久| 亚洲已满18点击进入久久| 99re亚洲国产精品| 久久影院电视剧免费观看| 久久精品理论片| 91精品在线一区二区| 国产成人免费视频网站高清观看视频 | 一本色道久久加勒比精品| 久久久久久99久久久精品网站| 日韩在线一区二区| 欧美在线影院一区二区| 亚洲人成在线观看一区二区| 成人黄色国产精品网站大全在线免费观看| 欧美一级一区二区| 日韩电影在线免费观看| 欧美色图激情小说| 亚洲第一久久影院| 欧美日韩亚洲国产综合| 亚洲午夜影视影院在线观看| 在线观看国产91| 亚洲综合激情小说| 色8久久人人97超碰香蕉987| 亚洲黄色片在线观看| 一本大道综合伊人精品热热| 亚洲视频一区在线观看| 色综合视频在线观看| 亚洲乱码中文字幕综合| 一本大道久久a久久精二百| 亚洲理论在线观看| 91国产免费观看| 亚欧色一区w666天堂| 日韩一区二区电影| 国内外成人在线| 国产精品丝袜久久久久久app| www.日韩精品| 亚洲自拍偷拍九九九| 欧美日韩一区三区四区| 奇米777欧美一区二区| 久久亚洲欧美国产精品乐播| 国产成人免费视频网站 | 午夜激情综合网| 91麻豆精品国产自产在线| 日本不卡一二三区黄网| 欧美精品一区二区三区一线天视频| 国产美女在线精品| 亚洲天堂中文字幕| 欧美日韩你懂得| 久久成人av少妇免费| 国产精品久久久久久亚洲伦| 色偷偷一区二区三区| 午夜精品久久久久久久久 | 中文字幕av一区二区三区免费看 | 免费成人在线观看| 国产欧美日韩精品一区| 色嗨嗨av一区二区三区| 日本三级亚洲精品|