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

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

?? ex22.c

?? 遺傳算法的源程序例子
?? C
字號(hào):
/* ----------------------------------------------------------------------------  ex22.C  mbwall 5jan96  Copyright (c) 1995-1996  Massachusetts Institute of Technology DESCRIPTION:   This example shows how to derive your own genetic algorithm class.  This onedoes a modified form of speciation that is useful for fitness-scaled speciationwith overlapping populations (Goldberg's speciation is designed for use with non-overlapping populations.     The steady-state genetic algorithm built-in to GAlib is actually capable ofdoing this already, but this example illustrates how you can modify a geneticalgorithm to do your own thing.  For example, instead of using the "singlechild crossover" you could use your own crossover algorithm instead.---------------------------------------------------------------------------- */#include <stdio.h>#include <iostream.h>#include <math.h>#include <ga/ga.h>// If your compiler does not do automatic instantiation (e.g. g++ 2.6.8),// then define the NO_AUTO_INST directive.#ifdef NO_AUTO_INST#include <ga/GA1DArrayGenome.C>#if defined(__GNUG__)template class GA1DArrayGenome<float>;#elseGA1DArrayGenome<float>;#endif#endif#ifndef M_PI#define M_PI            3.14159265358979323846#endif#define OBJECTIVE Objective1#define MIN_VALUE -100#define MAX_VALUE 100//#define OBJECTIVE Objective2//#define MIN_VALUE -50//#define MAX_VALUE 50float Objective1(GAGenome&);float Objective2(GAGenome&);int   Mutator(GAGenome&, float);void  Initializer(GAGenome&);float Comparator(const GAGenome&, const GAGenome&);int   Crossover(const GAGenome&, const GAGenome&, GAGenome*);// Here we define our own genetic algorithm class.  This class is almost the// same as the steady-state genetic algorithm, but we modify the step method// (the one that does all the work) so that we do a slightly modified // replacement.  We're only going to do a two-parents-make-one-child mating,// so we define our own crossover and use it rather than the standard one in// GAlib.typedef int (*SingleChildCrossover)(const GAGenome&,const GAGenome&,GAGenome*);class SharedOverlapGA : public GASteadyStateGA {public:  GADefineIdentity("SharedOverlapGA", 200);  SharedOverlapGA(const GAGenome& g) : GASteadyStateGA(g) {}  virtual ~SharedOverlapGA() {}  virtual void step();  SharedOverlapGA & operator++() { step(); return *this; }  void crossover(SingleChildCrossover func) {crossFunction = func;}protected:  SingleChildCrossover crossFunction;};// This step method is similar to that of the regular steady-state genetic// algorithm, but here we generate only one child in a crossover, and we// do a slightly different type of replacement.  Here we generate the new// individuals, insert them into the population, force a scaling to occur, // then remove the worst individuals.  This is all done based on the scaled// (fitness) scores, not the raw (objective) scores.voidSharedOverlapGA::step(){   int i;  GAGenome *mom, *dad;  for(i=0; i<tmpPop->size(); i++){	// takes care of odd population    mom = &(pop->select());      dad = &(pop->select());    stats.numsel += 2;		// keep track of number of selections    if(GAFlipCoin(pCrossover()))      stats.numcro += crossFunction(*mom, *dad, &tmpPop->individual(i));    else if(GARandomBit())       tmpPop->individual(i).copy(*mom);    else      tmpPop->individual(i).copy(*dad);    stats.nummut += tmpPop->individual(i).mutate(pMutation());  }  for(i=0; i<tmpPop->size(); i++)    pop->add(tmpPop->individual(i));  pop->evaluate();		// get info about current pop for next time  pop->scale();			// remind the population to do its scaling  for(i=0; i<tmpPop->size(); i++)    pop->destroy(GAPopulation::WORST, GAPopulation::SCALED);  stats.update(*pop);		// update the statistics by one generation}intmain(int argc, char** argv){  cout << "Example 22\n\n";  cout << "This example shows how to derive your own genetic algorithm\n";  cout << "class.  Here we use a custom, single-child crossover and a\n";  cout << "modified replacement strategy with overlapping populations.\n\n";  cout.flush();// 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.  unsigned int seed = 0;  for(int ii=1; ii<argc; ii++) {    if(strcmp(argv[ii++],"seed") == 0) {      seed = atoi(argv[ii]);    }  }  ofstream outfile;  char file[] = "sinusoid.dat";  char ifile[] = "pop.initial.dat";  char ffile[] = "pop.final.dat";  int i;  GA1DArrayGenome<float> genome(1, OBJECTIVE);  genome.initializer(::Initializer);  genome.mutator(::Mutator);  genome.comparator(::Comparator);  GASharing share(Comparator);  SharedOverlapGA ga(genome);  ga.crossover(Crossover);  ga.scaling(share);  ga.populationSize(100);  ga.pReplacement(0.25);  ga.nGenerations(500);  ga.pMutation(0.01);  ga.pCrossover(1.0);  ga.scoreFilename("bog.dat");	// name of file for scores  ga.scoreFrequency(10);	// keep the scores of every 10th generation  ga.flushFrequency(100);	// specify how often to write the score to disk  ga.selectScores(GAStatistics::AllScores);  ga.parameters(argc, argv, gaTrue); // parse commands, complain if bogus args  cout << "initializing...\n"; cout.flush();  ga.initialize(seed);// dump the initial population to file  outfile.open(ifile, (ios::out | ios::trunc));  for(i=0; i<ga.population().size(); i++){    genome = ga.population().individual(i);    outfile << genome.gene(0) << "\t" << genome.score() << "\n";  }  outfile.close();// Evolve until the termination function says we're finished.  Print out a// little status indicator periodically to let us know what's going on.  After// the evolution we flush any remaining scores to file.  cout << "evolving"; cout.flush();  while(!ga.done()){    ga.step();    if(ga.generation() % 50 == 0){      cout << ".";      cout.flush();    }  }  cout << "\n\n";  ga.flushScores();// dump the final population to file  outfile.open(ffile, (ios::out | ios::trunc));  for(i=0; i<ga.population().size(); i++){    genome = ga.population().individual(i);    outfile << genome.gene(0) << "\t" << genome.score() << "\n";  }  outfile.close();// dump the function to file  cout << "dumping the function to file..." << endl;  outfile.open(file, (ios::out | ios::trunc));  if(outfile.fail()){    cerr << "Cannot open " << file << " for output.\n";    exit(1);  }  for(float x=MIN_VALUE; x<=MAX_VALUE; x+=1.0)    outfile << genome.gene(0,x) << "\t" << genome.score() << "\n";  outfile << "\n";  outfile.close();  cout << "initial population is in '" << ifile << "'\n";  cout << "final population is in '" << ffile << "'\n";  cout << "the function is in '" << file << "'\n";  cout << "parameters were:\n\n" << ga.parameters() << "\n";  return 0;} // Here are two different objective functions.  Function 1 has multiple peaks// with significant difference between peak heights - it is a modulated// sinusoid.  Function 2 has less difference between peaks - it is an // approximation of a square plateau using a sum of sinusoids.floatObjective1(GAGenome& g){  GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;  float v = genome.gene(0);  float y = 100.0 * exp(-fabs(v) / 50.0) * (1.0 - cos(v * M_PI * 2.0 / 25.0));  if(v < MIN_VALUE || v > MAX_VALUE) y = 0;  if(y < 0) y = 0;  return y+0.00001;}floatObjective2(GAGenome& g){  GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;  float v = genome.gene(0) / 100.0;  float y = 0.5 + 0.6 * sin(M_PI*v) + 0.2 * sin(3*M_PI*v) + 0.1 * sin(5*M_PI*v)    + 0.02 * sin(7*M_PI*v) + 0.01 * sin(7*M_PI*v);  if(v < -0.23 || v > 1.23) y = 0;  if(y < 0) y = 0;  return y+0.00001;}voidInitializer(GAGenome& g){  GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;  genome.gene(0, GARandomFloat(-100.0, 100.0));}intMutator(GAGenome& g, float pmut){  GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;  int nmut = 0;  if(GAFlipCoin(pmut)){    genome.gene(0, genome.gene(0) + 		GARandomFloat() * (GARandomFloat() - GARandomFloat()));    nmut = 1;  }  return nmut;}intCrossover(const GAGenome& g1, const GAGenome& g2, GAGenome* c1){  GA1DArrayGenome<float>& mom = (GA1DArrayGenome<float>&)g1;  GA1DArrayGenome<float>& dad = (GA1DArrayGenome<float>&)g2;  GA1DArrayGenome<float>& child = (GA1DArrayGenome<float>&)*c1;  float distance = 0.0, midpoint = 0.0;  midpoint = (mom.gene(0) + dad.gene(0)) / 2;  distance = fabs(mom.gene(0) - dad.gene(0));  child.gene(0, midpoint + distance * (GARandomFloat() - GARandomFloat()));  return 1;}// You can change the factor to control how tightly the distance function // considers the spacing of two genomes.  Higher numbers will give you a // tighter clustering at function peaks.#define FACTOR 800floatComparator(const GAGenome& g1, const GAGenome& g2) {  GA1DArrayGenome<float>& a = (GA1DArrayGenome<float>&)g1;  GA1DArrayGenome<float>& b = (GA1DArrayGenome<float>&)g2;  float val= exp( - (a.gene(0)-b.gene(0)) * (a.gene(0)-b.gene(0)) / FACTOR);  if(1-val < 0 || 1-val > 1) cerr << "val: " << val << "\n";  return 1-val;}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品一区二区免费不卡| 麻豆国产精品一区二区三区| 7777精品久久久大香线蕉| 国产麻豆精品theporn| 一区二区三区中文字幕电影| 久久综合九色欧美综合狠狠| 色网综合在线观看| 福利电影一区二区三区| 日本怡春院一区二区| 亚洲私人黄色宅男| 精品国产乱码久久久久久老虎| 在线视频你懂得一区二区三区| 国产一区二区不卡老阿姨| 五月天一区二区| 亚洲精品视频自拍| 国产精品久久影院| 久久网站热最新地址| 91精品久久久久久久99蜜桃| 91福利在线看| av一区二区三区黑人| 国产精品77777竹菊影视小说| 日本成人在线视频网站| 亚洲成a人v欧美综合天堂下载| 国产精品麻豆99久久久久久| 久久这里只有精品首页| 日韩欧美综合在线| 69久久夜色精品国产69蝌蚪网| a亚洲天堂av| 成人永久aaa| 中文字幕的久久| 国产日韩成人精品| 国产日产精品1区| 久久久久久毛片| 精品国产第一区二区三区观看体验| 91精品国产综合久久婷婷香蕉 | 国产成人免费视| 精品一区二区免费看| 免费视频一区二区| 激情六月婷婷久久| 秋霞国产午夜精品免费视频| 奇米综合一区二区三区精品视频| 日韩av在线发布| 久久精品国产澳门| 黄页网站大全一区二区| 国产美女一区二区三区| 国产大片一区二区| 成人黄色av电影| 色综合一个色综合亚洲| 91成人免费网站| 欧美日韩一区不卡| 日韩午夜激情免费电影| 精品久久人人做人人爱| 中文字幕av一区二区三区免费看| 国产精品九色蝌蚪自拍| 一区二区三区在线观看欧美 | 久久av资源网| 国产一区二区日韩精品| eeuss鲁片一区二区三区| 欧洲人成人精品| 日韩一区二区三区视频在线观看| 欧美xxxx老人做受| 国产精品丝袜91| 亚洲激情图片qvod| 麻豆国产欧美一区二区三区| 国产激情一区二区三区四区| 99re视频这里只有精品| 欧美日韩另类一区| 精品久久人人做人人爽| 椎名由奈av一区二区三区| 午夜精品福利久久久| 国产一区视频导航| 色乱码一区二区三区88| 日韩一级高清毛片| 国产精品久久久久aaaa樱花| 一级做a爱片久久| 美女免费视频一区二区| 成人精品国产福利| 欧美人与z0zoxxxx视频| 国产亚洲一二三区| 亚洲主播在线观看| 国产精品小仙女| 欧美日韩一区中文字幕| 久久久精品综合| 一区二区在线观看视频| 国内成人自拍视频| 在线中文字幕不卡| 久久久天堂av| 日韩精品亚洲一区| 成人av免费观看| 欧美成人一区二区三区在线观看| 欧美国产一区视频在线观看| 天天综合色天天| 成人高清免费观看| 日韩免费高清视频| 亚洲国产精品一区二区尤物区| 国产一区在线观看麻豆| 欧美精品视频www在线观看 | 欧美激情在线一区二区| 五月婷婷综合网| 不卡av在线网| 久久一区二区三区四区| 天涯成人国产亚洲精品一区av| 国产精品69毛片高清亚洲| 日韩一区和二区| 夜夜嗨av一区二区三区中文字幕| 国产成人精品三级| 精品国免费一区二区三区| 亚洲国产精品视频| 99久久精品国产一区二区三区 | 2023国产一二三区日本精品2022| 亚洲激情av在线| av在线免费不卡| 中文在线免费一区三区高中清不卡| 视频一区欧美日韩| 欧美性做爰猛烈叫床潮| 亚洲视频在线一区| 成人动漫视频在线| 国产午夜精品美女毛片视频| 久久国产精品无码网站| 欧美一区二区三区男人的天堂| 亚洲精品乱码久久久久久久久 | 成人午夜又粗又硬又大| 久久综合成人精品亚洲另类欧美| 日韩黄色一级片| 欧美日韩精品免费观看视频| 有坂深雪av一区二区精品| a级高清视频欧美日韩| 国产精品网友自拍| 成人自拍视频在线| 中文字幕乱码一区二区免费| 国产91高潮流白浆在线麻豆| 2023国产一二三区日本精品2022| 久久精品国产在热久久| 日韩欧美美女一区二区三区| 日本美女一区二区三区| 91精品国产手机| 免费观看一级特黄欧美大片| 欧美一区二区三区在线观看视频 | 99久久精品免费看国产| 成人欧美一区二区三区黑人麻豆 | 欧美日韩精品久久久| 午夜免费久久看| 欧美精品电影在线播放| 热久久国产精品| 精品久久免费看| 国产精品一区二区视频| 国产三级一区二区三区| 国产91精品精华液一区二区三区| 国产精品素人视频| 91福利视频在线| 亚洲国产一区二区三区| 欧美日韩国产影片| 久久精品国产免费| 国产日产精品1区| 色婷婷激情久久| 日日摸夜夜添夜夜添亚洲女人| 欧美一区二区视频观看视频| 国产精品一区二区果冻传媒| 国产精品久久久久久一区二区三区| 97se亚洲国产综合自在线观| 亚洲国产日韩综合久久精品| 日韩免费一区二区| 成人黄色网址在线观看| 亚洲国产精品久久不卡毛片| 日韩免费一区二区| av在线这里只有精品| 午夜精品久久久久久久久久久| 日韩美一区二区三区| 99精品视频在线免费观看| 午夜影院久久久| 国产亚洲一区二区三区在线观看| 99热国产精品| 美国毛片一区二区| 国产精品欧美一区二区三区| 欧美天天综合网| 国产精品羞羞答答xxdd| 亚洲高清不卡在线| 国产午夜精品福利| 欧美日本一道本在线视频| 国产成人免费视频网站| 亚洲成人av电影| 国产欧美精品在线观看| 欧美日韩国产小视频在线观看| 国产一区二区三区精品欧美日韩一区二区三区 | 中文字幕一区二区三区色视频| 欧美三级日本三级少妇99| 韩国三级在线一区| 亚洲精品综合在线| 2021中文字幕一区亚洲| 欧美色电影在线| 成人免费毛片嘿嘿连载视频| 日韩在线一二三区| 国产精品狼人久久影院观看方式| 7777女厕盗摄久久久| 99re成人精品视频| 国产揄拍国内精品对白| 亚洲福利视频一区二区| 亚洲日韩欧美一区二区在线| 久久这里只有精品首页| 欧美一区二区三区四区五区|