#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();