遗传算法在函数优化中的应用

人工智能大作业

《基本遗传算法在函数优化中的应用》

一.算法简介

1基本概念

遗传算法(Genetic Algorithm)是一类借鉴生物界的进化规律(适者生存,优胜劣汰遗传机制)演化而来的随机化搜索方法。遗传算法是一种群体型操作,该操作以群体中的所有个体为对象。选择(Selection)、交叉(Crossover)和变异(Mutation)是遗传算法的3个主要操作算子,它们构成了所谓的遗传操作(genetic operation),使遗传算法具有了其它传统方法所没有的特性。

2 遗传算法的特点

其主要特点是直接对结构对象进行操作,不存在求导和函数连续性的限定;具有内在的隐并行性和更好的全局寻优能力;采用概率化的寻优方法,能自动获取和指导优化的搜索空间,自适应地调整搜索方向,不需要确定的规则。

3遗传算法的应用

函数优化,组合优化,机器人智能控制,及组合图像处理和模式识别等。

4简单遗传算法的求解步骤

Step1:参数设置及种群初始化;

Step2:适应度评价;

Step3:选择操作;

Step4:交叉操作;

Step5:变异操作;

Step6:终止条件判断,若未达到终止条件,则转到Step3;

Step7:输出结果。

5停机准则

(1)完成了预先给定的进化代数则停止;

(2)群体中的最优个体在连续若干代没有改进或平均适应度在连续若干代基本没有改进时停止。

6基本遗传算法框图

二.算法代码

#include

#include

#include

#include

#define POPSIZE 500

#define chromlength 5

int popsize ;

int maxgeneration;

double pc = 0.0;

double pm = 0.0;

struct individual

{

int chrom[chromlength];

double value;

double fitness;

};

int generation;

int best_index;

int worst_index;

struct individual bestindividual;

struct individual worstindividual; struct individual currentbest; t

struct individual population[POPSIZE];

void generateinitialpopulation();

void generatenextpopulation();

void evaluatepopulation();

void calculateobjectfitness();

double decodechromosome(int,int); void findbestandworstindividual(); void performevolution();

void selectoperator();

void crossoveroperator();

void mutationoperator();

void input();

void outputtextreport();

void main()

{

int i;

相关文档
最新文档