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

📄 es.cpp

📁 遗传策略的最小路径(tsp)的实际应用
💻 CPP
字号:
// 这是使用应用程序向导生成的 VC++ 
// 应用程序项目的主项目文件。

#include "stdafx.h" 
#include <iostream>
#include <fstream>
#include <time.h>       //产生随机数要用到time(int),使每次产生的数不同
#include "Individual.h" 
#include "Population.h" 
    
using namespace std; 

int main() {

    int gen=0;
	int max_gen;
   ofstream clear("记录.txt");
	cout<<"输入终止代数:"<<endl;

    cin>>max_gen;

    srand( (unsigned)time( NULL ) );
 
    Population a;

    a.report();
  ofstream myf("记录.txt",ios::app);
    for(int i = 1; i <=max_gen; i++) {
    myf<<"第"<<i<<"代:"<<endl;
	cout<<"第"<<i<<"代:"<<endl;
	   a.Recombination();

       a.Mutation();

	   a.Selection();

       a.report();

       gen++;
	   if(a.getMax().FitnessEvaluate()-a.getMin().FitnessEvaluate()<0.00001) 
       break;    
	   
    }

    cout << "The maximum is:\n";

    a.getMax().print();

	cout<<"After "<<gen<<" generations."<<endl;

    return 0;

}

⌨️ 快捷键说明

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