用浮点数编码解决遗传算法问题.docVIP

  • 1
  • 0
  • 约1.06万字
  • 约 10页
  • 2017-02-07 发布于江苏
  • 举报
遗传算法作业 一:用浮点数编码解决以下问题。 二:构造过程。 第一步:确定决策变量和约束条件。 题目中已给出了该问题的决策变量及约束条件。 第二步:建立优化模型。 既是题目给出所要求的。 第三步:确定编码方法。 第四步:确定解码方法。 第五步:确定个体评价方法。 这里可将个体的适应度直接取为对应的目标函数值,并且不再对它做其他变化处理,即有:F(X)=f(x1,x2) 第六步:设计遗传算子。 选择运算使用比例运算算子; 交叉运算是用单点交叉算子; 变异运算使用基本位变异算子。 第七步:确定遗传算法的运行参数。 对于本例,设计基本遗传算法的运行参数如下: MAXGENS=80 /* 最大世代数 */ POPSIZE=20 /* 种群大小*/ NVARS=2 /* 变量个数 */ PXOVER=0.2 /* 交叉概率 */ PMUTATION=0.1 /* 变异概率 */ 三:代码如下。 #include stdafx.h #include stdio.h #include stdlib.h #include math.h #define MAXGENS 80 /* 最大世代数 */ #define POPSIZE 20 /* 种群大小*/ #define NVARS 2 /* 变量个数 */ #define PXOVER 0.2 /* 交叉概率 */ #define PMUTATION 0.1 /* 变异概率 */ #define FALSE 0 #define TRUE 1 int generation; /*当前世代 */ int cur_best; /* 最佳个体*/ struct genotype { double gene[NVARS]; double fitness; double upper[NVARS]; double lower[NVARS]; double rfitness; double cfitness; }; struct genotype population[POPSIZE+1]; struct genotype newpopulation[POPSIZE+1]; void initialize(void); double randval(double, double); void evaluate(void); void keep_the_best(void); void elitist(void); void select(void); void crossover(void); void Xover(int,int); void swap(double *, double *); void mutate(void); void report(void); void initialize(void) { int i, j; double lbound, ubound; for (i = 0; i NVARS; i++) { scanf(%lf,lbound); scanf(%lf,ubound); for (j = 0; j POPSIZE; j++) { population[j].fitness = 0; population[j].rfitness = 0; population[j].cfitness = 0; population[j].lower[i] = lbound; population[j].upper[i]= ubound; population[j].gene[i] = randval(p

文档评论(0)

1亿VIP精品文档

相关文档