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

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

?? ex26.c

?? 解兩類組合優(yōu)化問題的遺傳算法,希望有關(guān)學(xué)習(xí)這方面的同學(xué)參考。
?? C
字號(hào):
/* ----------------------------------------------------------------------------  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>// 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.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;}#ifdef NO_AUTO_INST#include <ga/GAList.C>#include <ga/GAListGenome.C>#if defined(__GNUG__)template class GAList<int>;template class GAListGenome<int>;#elseGAList<int>;GAListGenome<int>;#endif#endif

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产无人区一区二区三区| 青青青伊人色综合久久| 日日夜夜免费精品| 国产乱子伦视频一区二区三区 | 国产欧美视频一区二区| 亚洲一区在线观看免费 | 99精品偷自拍| 亚洲色欲色欲www| 91精品久久久久久蜜臀| 欧美久久久久久久久久| 亚洲国产精品一区二区www| 精品人伦一区二区色婷婷| 91麻豆国产福利精品| 精品国产伦一区二区三区观看体验 | 91色porny蝌蚪| 久久影院视频免费| 日产精品久久久久久久性色| 99精品国产一区二区三区不卡| 欧美大度的电影原声| 亚洲成人免费视| 欧洲精品在线观看| 亚洲欧美aⅴ...| 99re视频精品| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲一区二区三区四区在线观看 | 蜜臀av一级做a爰片久久| 91激情在线视频| 综合久久一区二区三区| 成人永久看片免费视频天堂| 久久丝袜美腿综合| 国产资源精品在线观看| 精品国产一区二区三区av性色| 日韩**一区毛片| 日韩视频在线你懂得| 亚洲第一福利一区| 欧美日韩一区三区四区| 亚洲曰韩产成在线| 91国产丝袜在线播放| 亚洲成av人综合在线观看| 在线免费亚洲电影| 日韩一区在线看| 91美女精品福利| 一区二区三区四区视频精品免费 | 美洲天堂一区二卡三卡四卡视频| 欧美丰满少妇xxxbbb| 五月天丁香久久| 日韩午夜在线播放| 精品一区二区在线观看| 久久精品视频一区二区三区| 国内外成人在线| 亚洲国产精品国自产拍av| 99这里都是精品| 亚洲一卡二卡三卡四卡| 日韩精品一区二区三区在线观看 | 中文字幕中文字幕在线一区| 99精品一区二区三区| 亚洲福利视频一区| 5月丁香婷婷综合| 国产一区二区网址| 自拍偷拍亚洲激情| 欧美巨大另类极品videosbest| 美女mm1313爽爽久久久蜜臀| 国产欧美日韩视频在线观看| 91丨porny丨首页| 奇米精品一区二区三区在线观看| 欧美精品一区二区在线播放| av一二三不卡影片| 日韩高清电影一区| 中文在线资源观看网站视频免费不卡 | 日韩av网站在线观看| 久久久亚洲综合| 欧美三级一区二区| 国产成人小视频| 日韩中文字幕麻豆| 中文字幕一区二区在线观看| 69堂精品视频| 国产精品一区一区| 欧美精品日韩一区| 亚洲啪啪综合av一区二区三区| 91丨porny丨首页| 免费成人在线观看视频| 中文字幕一区二区三区不卡 | 国产成人亚洲综合a∨婷婷| 亚洲精品国产视频| 精品三级av在线| 在线观看欧美精品| 粉嫩蜜臀av国产精品网站| 亚洲国产成人tv| 国产精品水嫩水嫩| 精品福利一区二区三区免费视频| 欧美三区在线观看| 91视视频在线观看入口直接观看www | 久久先锋影音av| 欧美精品123区| av一区二区三区四区| 精品亚洲aⅴ乱码一区二区三区| 亚洲精品视频在线观看网站| 国产亚洲欧美一区在线观看| 3d动漫精品啪啪一区二区竹菊 | 国产sm精品调教视频网站| 亚洲成人三级小说| 亚洲综合在线免费观看| 国产精品视频在线看| 国产午夜一区二区三区| 精品剧情v国产在线观看在线| 欧美日韩极品在线观看一区| 91福利国产成人精品照片| 成人av电影在线网| 国产**成人网毛片九色| 国模娜娜一区二区三区| 久久成人18免费观看| 蜜臀国产一区二区三区在线播放| 亚洲国产精品久久一线不卡| 一区二区三区四区视频精品免费 | 国产一区二区免费看| 麻豆传媒一区二区三区| 亚洲成人自拍网| 日韩在线一区二区三区| 樱花草国产18久久久久| 日本欧美大码aⅴ在线播放| 国产精品伦一区| eeuss国产一区二区三区| 国产成人综合自拍| 风间由美一区二区av101| 丁香婷婷综合网| 色综合久久久网| 色综合久久久网| 欧美影视一区在线| 欧美精品在线观看播放| 欧美一区二区三区婷婷月色| 欧美一级免费大片| 日韩美女在线视频| 久久久99久久| 亚洲婷婷综合久久一本伊一区| 亚洲激情欧美激情| 亚洲国产精品一区二区久久恐怖片| 亚洲成人黄色小说| 久热成人在线视频| 成人综合婷婷国产精品久久 | 麻豆一区二区在线| 国产乱子轮精品视频| 99久久国产综合色|国产精品| 色婷婷亚洲精品| 日韩欧美美女一区二区三区| 久久这里只有精品6| 国产精品不卡在线观看| 亚洲成人动漫一区| 国产麻豆成人精品| 在线看不卡av| 精品奇米国产一区二区三区| 国产精品午夜在线| 亚洲成年人影院| 国产老肥熟一区二区三区| 99麻豆久久久国产精品免费| 欧美日韩久久一区| 欧美激情在线一区二区| 亚洲第一福利视频在线| 国产成人在线观看免费网站| 欧美吻胸吃奶大尺度电影| 久久―日本道色综合久久| 亚洲综合区在线| 国产综合久久久久影院| 欧美日韩专区在线| 国产亚洲成年网址在线观看| 亚洲成av人影院| 成人av网站免费| 久久影视一区二区| 亚洲第一会所有码转帖| 成人国产精品免费网站| 91麻豆精品国产自产在线| 国产精品女主播av| 久久国产精品99久久人人澡| 一本色道综合亚洲| 国产亚洲午夜高清国产拍精品| 日本美女一区二区三区视频| 色综合久久88色综合天天6| 国产日韩影视精品| 蜜桃传媒麻豆第一区在线观看| 欧美在线免费观看视频| 国产精品久久久久久久久动漫 | 在线欧美一区二区| 夫妻av一区二区| 亚洲国产综合色| 天天影视涩香欲综合网| 99国内精品久久| 国产网站一区二区三区| 黄页网站大全一区二区| 欧美久久久久免费| 亚洲伊人色欲综合网| 91网站黄www| 国产精品久久久久久妇女6080| 国产一区 二区| 精品国产1区二区| 精品影视av免费| 精品不卡在线视频| 美国十次了思思久久精品导航| 欧美日本视频在线| 亚洲一本大道在线| 欧美麻豆精品久久久久久| 亚洲一区二区四区蜜桃|