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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ex26.cpp

?? 這是一個面向對象的GA遺傳算法庫GAlib: A C++ Library of Genetic Algorithm Components)
?? CPP
字號:
/* ----------------------------------------------------------------------------  ex26.C  mbwall 24mar96  Copyright (c) 1995-1996  Massachusetts Institute of Technology  The code for this example is adapted from an original implementation   by Thomas Grueninger (from Uni Stuttgart, visiting scholar at MIT) DESCRIPTION:   GAs are lousy at solving the travelling salesperson problem.  But here is anexample of how to do it anyway.  In this case we use a steady-state geneticalgorithm and give you the compile-time choice of partial match or edge recombination crossover.   This one looks really good when you draw an entire population of individualsand watch them all evolve in real time.  It becomes very obvious what thegenetic algorithm is doing and how well the speciation is working (or not).   This implementation is by no means efficient, so please do not complain about all of the silly little inefficient aspects of the implementation.  But it does get the job done.---------------------------------------------------------------------------- */#include <math.h>#include <ga/GASStateGA.h>#include <ga/GAListGenome.h>#include <ga/garandom.h>#include <ga/std_stream.h>#define cout STD_COUT#define cerr STD_CERR#define endl STD_ENDL#define ostream STD_OSTREAM#define ifstream STD_IFSTREAM// Set this up for your favorite TSP.  The sample one is a contrived problem// with the towns laid out in a grid (so it is easy to figure out what the // shortest distance is, and there are many different paths with the same// shortest path).  File format is that used by the TSPLIB problems.  You can // grab more problems from // // // Apologies for using fixed-length arrays.  But this is an example, not // production code ;)#define MAX_TOWNS 50#define TSP_FILE "tsp_rect_20.txt"float DISTANCE[MAX_TOWNS][MAX_TOWNS];double x[MAX_TOWNS],y[MAX_TOWNS];int ntowns = 0;// You can use either edge recombination crossover or partial match crossover.// Which one you select makes a HUGE difference in the performance of the// genetic algorithm.  Only one of the two following lines should be commented.//#define XOVER PMXover       // (Partial Match Crossover)#define XOVER ERXover         // (Edge Recombination Crossover)float Objective(GAGenome&);int   Mutator(GAGenome&, float);void  Initializer(GAGenome&);float Comparator(const GAGenome&, const GAGenome&); int   ERXover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*);int   PMXover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*);void  ERXOneChild(const GAGenome&, const GAGenome&, GAGenome*);intmain(int argc, char** argv) {  cout << "Example 26\n\n";  cout << "The Travelling Salesman Problem (TSP) demo program.\n" << endl;// 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]);    }  }  double dump;  ifstream in(TSP_FILE);   if(!in) {    cerr << "could not read data file " << TSP_FILE << "\n";    exit(1);  }  ntowns=0;  do {    in >> dump;    in >> x[ntowns];    in >> y[ntowns];    ntowns++;  } while(!in.eof() && ntowns < MAX_TOWNS);  in.close();  if(ntowns >= MAX_TOWNS) {    cerr << "data file contains more towns than allowed for in the fixed\n";    cerr << "arrays.  Recompile the program with larger arrays or try a\n";    cerr << "smaller problem.\n";    exit(1);  }  double dx,dy;  for(int i=0;i<ntowns;i++) {    for(int j=i; j<ntowns;j++) {      dx=x[i]-x[j]; dy=y[i]-y[j];      DISTANCE[j][i]=DISTANCE[i][j]=sqrt(dx*dx+dy*dy);    }  }  GAListGenome<int> genome(Objective);  genome.initializer(::Initializer);  genome.mutator(::Mutator);  genome.comparator(::Comparator);  genome.crossover(XOVER);  GASteadyStateGA ga(genome);  ga.minimize();  ga.pReplacement(1.0);  ga.populationSize(100);  ga.nGenerations(1000);  ga.pMutation(0.1);  ga.pCrossover(1.0);  ga.selectScores(GAStatistics::AllScores);  ga.parameters(argc, argv);  cout << "initializing..."; cout.flush();  ga.initialize(seed);  cout << "evolving..."; cout.flush();  while(!ga.done()) {    ga.step();    if(ga.generation() % 10 == 0) {      cout << ga.generation() << " "; cout.flush();    }  }  genome = ga.statistics().bestIndividual();  cout << "the shortest path found is " << genome.score() << "\n";  cout << "this is the distance from the sequence\n";  cout << genome << "\n\n";  cout << ga.statistics() << "\n";  return 0;}// Here are the genome operators that we want to use for this problem.// Thanks to Jan Kees IJspeert for isolating an order-of-evaluation problem// in the previous implementation of this function.floatObjective(GAGenome& g) {  GAListGenome<int> & genome = (GAListGenome<int> &)g;  float dist = 0;  if(genome.head()) {    for(int i=0; i<ntowns; i++) {      int xx = *genome.current();      int yy = *genome.next();      dist += DISTANCE[xx][yy];    }  }  return dist;}voidInitializer(GAGenome& g) {  GAListGenome<int> &child=(GAListGenome<int> &)g;  while(child.head()) child.destroy(); // destroy any pre-existing list  int i,town;  static int visit[MAX_TOWNS];  memset(visit, 0, MAX_TOWNS*sizeof(int));  town=GARandomInt(0,ntowns-1);  visit[town]=1;  child.insert(town,GAListBASE::HEAD); // the head node   for( i=1; i<ntowns; i++) {    do {      town=GARandomInt(0,ntowns-1);    } while (visit[town]);    visit[town]=1;    child.insert(town);  }		// each subsequent node }intMutator(GAGenome& g, float pmut) {  GAListGenome<int> &child=(GAListGenome<int> &)g;  register int n, i;  if ((GARandomFloat() >= pmut) || (pmut <= 0)) return 0;  n = child.size();    if (GARandomFloat()<0.5) {    child.swap(GARandomInt(0,n-1),GARandomInt(0,n-1)); // swap only one time  }  else {    int nNodes = GARandomInt(1,((int)(n/2-1)));       // displace nNodes     child.warp(GARandomInt(0,n-1));                   // with or without    GAList<int> TmpList;                              // inversion    for(i=0;i<nNodes;i++) {      int *iptr = child.remove();      TmpList.insert(*iptr,GAListBASE::AFTER);      delete iptr;      child.next();    }    int invert;    child.warp(GARandomInt(0,n-nNodes));    invert = (GARandomFloat()<0.5) ? 0 : 1;    if (invert) TmpList.head(); else TmpList.tail();    for(i=0;i<nNodes;i++) {      int *iptr = TmpList.remove();      child.insert(*iptr,GAListBASE::AFTER);      delete iptr;      if (invert) TmpList.prev(); else TmpList.next();    }  }  child.head();		// set iterator to root node  return (1);}intERXover(const GAGenome& g1, const GAGenome& g2, GAGenome* c1, GAGenome* c2) {  int nc=0;  if(c1) { ERXOneChild(g1,g2,c1); nc+=1; }  if(c2) { ERXOneChild(g1,g2,c2); nc+=1; }  return nc;}voidERXOneChild(const GAGenome& g1, const GAGenome& g2, GAGenome* c1) {  GAListGenome<int> &mate1=(GAListGenome<int> &)g1;  GAListGenome<int> &mate2=(GAListGenome<int> &)g2;  GAListGenome<int> &sis=(GAListGenome<int> &)*c1;    int i,j,k,t1,t2,town;  static char CM[MAX_TOWNS][MAX_TOWNS],visit[MAX_TOWNS];  memset(CM, 0, MAX_TOWNS*MAX_TOWNS*sizeof(char));  memset(visit, 0, MAX_TOWNS*sizeof(char));  while (sis.head()) sis.destroy();  // create connection matrix  mate1.head();  for(j=0; j<ntowns; j++) {    t1 = *mate1.current(); t2 = *mate1.next();    CM[t1][t2]=1; CM[t2][t1]=1;  }  mate2.head();  for(j=0; j<ntowns; j++) {    t1 = *mate2.current(); t2 = *mate2.next();    CM[t1][t2]=1; CM[t2][t1]=1;  }    // select 1st town randomly  town=GARandomInt(0,ntowns-1);  visit[town]=1; memset(CM[town], 0, MAX_TOWNS*sizeof(char));  sis.insert(town); // the head node     GAList<int> PossFollowList;  GAList<int> FollowersList[5];  while (PossFollowList.head()) PossFollowList.destroy();  for(k=0; k<5; k++) {    while (FollowersList[k].head()) FollowersList[k].destroy();   }    // select the following town with the minimal no of next folling towns  int nPoss,nFollow;  for(i=1; i<ntowns; i++) {               nPoss = 0;    for(j=0; j<ntowns; j++) {          // no of poss. following towns      if (CM[j][town]) {	nPoss += 1;	PossFollowList.insert(j);}    }    // nPoss = 0;    if (nPoss == 0) {      do {town=GARandomInt(0,ntowns-1);} while (visit[town]); // no follower      visit[town]=1; memset(CM[town], 0, MAX_TOWNS*sizeof(char));      sis.insert(town);     }    else {      PossFollowList.head();      for(j=0; j<nPoss; j++) {	nFollow = 0; 	town = (*PossFollowList.current());	for(k=0; k<ntowns; k++) {	  if (CM[k][town]) nFollow++; 	}	FollowersList[nFollow].insert(town);	PossFollowList.next();      }      k=0;      while (FollowersList[k].size() == 0) k++;      FollowersList[k].warp(GARandomInt(0,FollowersList[k].size()));      town = (*FollowersList[k].current());      visit[town]=1; memset(CM[town], 0, MAX_TOWNS*sizeof(char));      sis.insert(town);     }    while (PossFollowList.head()) PossFollowList.destroy();    for(k=0; k<5; k++) {      while (FollowersList[k].head()) FollowersList[k].destroy();     }  }  sis.head();         // set iterator to head of list}intPMXover(const GAGenome& g1, const GAGenome& g2, GAGenome* c1, GAGenome* c2) {  GAListGenome<int> &mom=(GAListGenome<int> &)g1;  GAListGenome<int> &dad=(GAListGenome<int> &)g2;  int a = GARandomInt(0, mom.size());  int b = GARandomInt(0, dad.size());  int h;  if (b<a) { h=a; a=b; b=h; }  int* index;  int i,j,nc=0;  if(c1) {    GAListGenome<int> &sis=(GAListGenome<int> &)*c1;    sis.GAList<int>::copy(mom);    GAListIter<int> diter(dad);    index = diter.warp(a);    for(i=a; i<b; i++, index=diter.next()){      if(*sis.head() == *index){	sis.swap(i,0);      }      else{	for(j=1; (j<sis.size()) && (*sis.next() != *index); j++);	sis.swap(i,j);  // no op if j>size      }    }    sis.head();         // set iterator to head of list    nc += 1;  }  if(c2) {    GAListGenome<int> &sis=(GAListGenome<int> &)*c2;    sis.GAList<int>::copy(mom);    GAListIter<int> diter(dad);    index = diter.warp(a);    for(i=a; i<b; i++, index=diter.next()){      if(*sis.head() == *index){	sis.swap(i,0);      }      else{	for(j=1; (j<sis.size()) && (*sis.next() != *index); j++);	sis.swap(i,j);  // no op if j>size      }    }    sis.head();         // set iterator to head of list    nc += 1;  }  return nc;}floatComparator(const GAGenome& g1, const GAGenome& g2) {  GAListGenome<int> &a = (GAListGenome<int> &)g1;  GAListGenome<int> &b = (GAListGenome<int> &)g2;  int i,j,t1,t2;  float dist=ntowns;  static char CM1[MAX_TOWNS][MAX_TOWNS],CM2[MAX_TOWNS][MAX_TOWNS];  memset(CM1, 0, MAX_TOWNS*MAX_TOWNS*sizeof(char));  memset(CM2, 0, MAX_TOWNS*MAX_TOWNS*sizeof(char));  // create connection matrix CM1  a.head();  for(i=0; i<ntowns; i++) {    t1 = *a.current(); t2 = *a.next();    CM1[t1][t2]=1; CM1[t2][t1]=1;  }  // create connection matrix CM2  b.head();  for(i=0; i<ntowns; i++) {    t1 = *b.current(); t2 = *b.next();    CM2[t1][t2]=1; CM2[t2][t1]=1;  }  //calc distance = how many edges are different  for (i=0; i<ntowns; i++) {    for (j=i; j<ntowns; j++) {      if (CM1[i][j]&CM2[i][j]) dist--;    }  }  return (dist);}//   Here we override the _write method for the List class.  This lets us see// exactly what we want (the default _write method dumps out pointers to the// data rather than the data contents).//   This routine prints out the contents of each element of the list, // separated by a space.  It does not put a newline at the end of the list.//   Notice that you can override ANY function of a template class.  This is// called "specialization" in C++ and it lets you tailor the behaviour of a // template class to better fit the type.template <> intGAListGenome<int>::write(ostream & os) const{  int *cur, *head;  GAListIter<int> tmpiter(*this);  if((head=tmpiter.head()) != 0) {    os << *head << " ";    for(cur=tmpiter.next(); cur && cur != head; cur=tmpiter.next())      os << *cur << " ";  }  return os.fail() ? 1 : 0;}// force instantiations for compilers that do not do auto instantiation// for some compilers (e.g. metrowerks) this must come after any// specializations or you will get 'multiply-defined errors when you compile.#if !defined(GALIB_USE_AUTO_INST)#include <ga/GAList.C>#include <ga/GAListGenome.C>GALIB_INSTANTIATION_PREFIX GAList<int>;GALIB_INSTANTIATION_PREFIX GAListGenome<int>;#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
777a∨成人精品桃花网| 亚洲一区二区在线观看视频 | 国产精品乱人伦中文| 欧美一区二区视频观看视频| 色婷婷久久一区二区三区麻豆| 国产一区二区成人久久免费影院| 国产日产欧美一区二区视频| 自拍偷拍亚洲欧美日韩| 在线不卡一区二区| 日韩中文字幕一区二区三区| 亚洲精品一区在线观看| 国产一二三精品| 在线免费观看日本欧美| 粉嫩久久99精品久久久久久夜| 色丁香久综合在线久综合在线观看| 奇米精品一区二区三区四区| 色婷婷精品大在线视频| 欧美午夜宅男影院| 婷婷亚洲久悠悠色悠在线播放| 亚洲精品一二三| 亚洲欧美一区二区三区国产精品| 日韩欧美在线观看一区二区三区| 欧美午夜片在线看| 欧美日韩免费电影| 亚洲男人的天堂在线aⅴ视频| 亚洲精品成人天堂一二三| 久久99久久久欧美国产| 国产一区二区免费在线| 国产综合久久久久久鬼色 | 国产精品视频一区二区三区不卡| 欧美精品一区二区高清在线观看| 在线播放国产精品二区一二区四区| 欧美午夜影院一区| 777亚洲妇女| 欧美第一区第二区| 久久久影院官网| 精品国产免费一区二区三区四区| 久久婷婷久久一区二区三区| 久久久精品国产99久久精品芒果| 久久久久久久久岛国免费| 亚洲国产成人在线| 亚洲精品一二三| 久久机这里只有精品| 久久99精品一区二区三区| 国产真实乱偷精品视频免| 高清国产一区二区三区| 93久久精品日日躁夜夜躁欧美| 在线免费观看成人短视频| 精品精品国产高清a毛片牛牛 | 国产精品剧情在线亚洲| 一区二区三区小说| 丝袜美腿成人在线| 日韩主播视频在线| 国产一区二区免费看| 国产不卡在线视频| 欧美日韩国产区一| 在线播放日韩导航| 国产精品久久久久9999吃药| 一区二区三区在线免费播放| 国产乱码精品一区二区三区五月婷| 成人精品一区二区三区中文字幕| 欧美最新大片在线看| 精品久久久久久最新网址| 亚洲欧美一区二区三区国产精品| 日韩电影在线观看电影| 成人h动漫精品| 91国偷自产一区二区开放时间 | 亚洲一区二区在线视频| 久久国产精品99精品国产| 色婷婷精品久久二区二区蜜臀av| 91精品视频网| 日韩一区在线播放| 日韩电影网1区2区| 91蜜桃免费观看视频| 精品国产乱码久久久久久蜜臀| 一区二区三区不卡视频| 国产一区二区免费在线| 国产在线播放一区| 91精品国产手机| 中文字幕欧美日韩一区| 久久99国产乱子伦精品免费| 色综合欧美在线| 欧美国产精品劲爆| 麻豆中文一区二区| 欧美日韩成人高清| 国产精品国产三级国产普通话三级| 久久精品国产77777蜜臀| 一本色道久久综合精品竹菊| 久久久91精品国产一区二区精品| 偷拍与自拍一区| 欧美性一二三区| 国产精品网曝门| 日韩影院免费视频| 色久综合一二码| 国产精品嫩草影院av蜜臀| 国产一本一道久久香蕉| 欧美一区二区三区免费观看视频| 亚洲国产一区二区在线播放| av成人免费在线观看| 中文字幕精品一区二区精品绿巨人 | 欧美性xxxxxxxx| 一区二区三区在线免费播放 | 北条麻妃国产九九精品视频| 日韩美一区二区三区| 午夜在线电影亚洲一区| 色综合久久久久综合| 国产情人综合久久777777| 秋霞影院一区二区| 国产高清视频一区| 日韩三区在线观看| 丝袜诱惑制服诱惑色一区在线观看| 99精品视频在线播放观看| 国产精品久久久久久久久免费樱桃| 日本免费在线视频不卡一不卡二| 欧美色视频在线观看| 亚洲精品国产精华液| 成人午夜免费av| 欧美激情在线观看视频免费| 国产一区二区三区黄视频 | 色婷婷久久久久swag精品| 亚洲精品大片www| 91看片淫黄大片一级在线观看| 亚洲三级在线观看| 91美女福利视频| 国产精品人成在线观看免费| 成人性生交大片免费看中文网站| 精品国产一区二区三区忘忧草 | 国产精品亚洲专一区二区三区| 久久亚洲一区二区三区四区| 久久99精品久久久| 国产日韩欧美一区二区三区综合| 国产在线观看一区二区| 国产欧美一区视频| 成人免费毛片高清视频| 国产精品三级av| 色美美综合视频| 亚洲综合色视频| 91精品国产综合久久精品图片| 日韩电影在线一区二区三区| 欧美日韩免费观看一区二区三区| 免费成人av资源网| 久久新电视剧免费观看| www.亚洲色图| 亚洲另类春色校园小说| 成人三级伦理片| 亚洲激情欧美激情| 欧美日韩精品一区视频| 久久99精品国产麻豆婷婷| 国产欧美一区二区三区在线看蜜臀| 97精品国产露脸对白| 亚洲图片自拍偷拍| 2023国产精品| 暴力调教一区二区三区| 日本在线播放一区二区三区| 精品久久一区二区| 色天天综合色天天久久| 视频一区二区三区在线| 国产精品青草久久| 91国偷自产一区二区使用方法| 久久99精品国产麻豆婷婷| 国产精品免费网站在线观看| 欧美精品日韩一区| 国产精品白丝av| 午夜国产精品一区| 国产精品亲子乱子伦xxxx裸| 91精品国产品国语在线不卡| 成人综合婷婷国产精品久久| 亚洲精品高清在线观看| 国产一区二区三区美女| 成人福利视频在线看| 久久精品一区二区三区四区| 成人性生交大片免费看中文| 欧美国产一区视频在线观看| 欧美日韩1区2区| 国产精品一区二区果冻传媒| 一区二区三区在线免费播放| 精品少妇一区二区三区日产乱码 | 欧美日韩成人综合| 国产精品一区免费在线观看| 亚洲一区二区欧美激情| 久久精品视频免费观看| 制服丝袜中文字幕一区| 日本韩国欧美三级| 国产精品正在播放| 免费在线观看成人| 亚洲国产一二三| 日韩毛片精品高清免费| 国产蜜臀av在线一区二区三区| 欧美精品在线观看一区二区| 色网综合在线观看| 国产成人精品三级| 国产伦精品一区二区三区视频青涩| 日日夜夜精品视频免费| 亚洲曰韩产成在线| 亚洲精品第1页| 日韩一区精品字幕| 亚洲综合在线电影| 中文字幕在线观看一区| 国产日产欧美一区二区视频| 日韩欧美视频在线|