自学内容网 自学内容网

标准遗传算法-c++源程序

#include〈stdio.h>

#include<stdlib.h>

#include<time.h>

#include<fstream。h〉

#include<windows。h〉

#define POPSIZE 500

#define MAXIMIZATION 1

#define MINIMIZATION 2

#define random(x) (rand()%(x))

#define Cmax 100   /*最大值函数适应度的设置*/

#define Cmin 0     /*最小值函数适应度的设置*/

#define LENGTH1 10

#define LENGTH2 10

#define CHROMLENGTH LENGTH1+LENGTH2

int FunctionMode=MAXIMIZATION;

/*optimization type即函数类型,是求最大值函数还是最小值函数*/

int a=100;

int PopSize=80;

int MaxGeneration=200;

double Pc=0。6;

double Pm=0.001;

struct individual

char chrom[CHROMLENGTH+1];

double value;

  double fitness;

};

int generation;

int best_index;

int worst_index;

struct individual bestindividual;

struct individual worstindividual;

struct individual currentbest;

struct individual population[POPSIZE];

void GenerateInitialPopulation(void);

void GenerateNextPopulation(void);

void EvaluatePopulation(void);

long DecodeChromosome(char *,int,int);

void CaculateObjectValue(void);

void CaculateFitnessValue(void);

void FindBestAndWorstIndividual(void);

void PerformEvolution(void);

void SelectionOperator(void);

void CrossoverOperator(void);

void MutationOperator(void);

void OutputTextReport(void);

void main()

    srand((unsigned)time(NULL));  //随时间而改变随机数

generation=0;

    GenerateInitialPopulation();


原文地址:https://blog.csdn.net/m0_38073539/article/details/143636152

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!