多目标遗传算法 ------ NSGA-II (部分源码解析) 实数、二进制编码的变异操作 mutation.c
遗传算法的变异操作
/* Mutation routines */ # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" /* Function to perform mutation in a population */
void mutation_pop (population *pop)
{
int i;
for (i=; i<popsize; i++)
{
mutation_ind(&(pop->ind[i]));
}
return;
}
一次进化过程中的 变异操作, 需要调用 变异函数 mutation_ind 种群个数popsize 次。
函数包装,判断是实数编码还是二进制编码并调用不同的变异函数。
/* Function to perform mutation of an individual */
void mutation_ind (individual *ind)
{
if (nreal!=)
{
real_mutate_ind(ind);
}
if (nbin!=)
{
bin_mutate_ind(ind);
}
return;
}
二进制编码 的 变异操作:
每个个体 的 每个变量 的 二进制编码段 的 每个比特位, 以变异概率 pmut_bin 进行变异。
(单点变异)
/* Routine for binary mutation of an individual */
void bin_mutate_ind (individual *ind)
{
int j, k;
double prob;
for (j=; j<nbin; j++)
{
for (k=; k<nbits[j]; k++)
{
prob = randomperc();
if (prob <=pmut_bin)
{
if (ind->gene[j][k] == )
{
ind->gene[j][k] = ;
}
else
{
ind->gene[j][k] = ;
}
nbinmut+=;
}
}
}
return;
}
实数编码 情况下的 变异操作:
(多项式变异)
/* Routine for real polynomial mutation of an individual */
void real_mutate_ind (individual *ind)
{
int j;
double rnd, delta1, delta2, mut_pow, deltaq;
double delta;
double y, yl, yu, val, xy;
for (j=; j<nreal; j++)
{
rnd = randomperc();
if (rnd <= pmut_real)
{
y = ind->xreal[j];
yl = min_realvar[j];
yu = max_realvar[j];
delta1 = (y-yl)/(yu-yl);
delta2 = (yu-y)/(yu-yl);
delta = minimum (delta1,delta2);
rnd = randomperc();
mut_pow = 1.0/(eta_m+1.0);
if (rnd <= 0.5)
{
xy = 1.0-delta1;
val = 2.0*rnd+(1.0-2.0*rnd)*(pow(xy,(eta_m+1.0)));
deltaq = pow(val,mut_pow) - 1.0;
}
else
{
xy = 1.0-delta2;
val = 2.0*(1.0-rnd)+2.0*(rnd-0.5)*(pow(xy,(eta_m+1.0)));
deltaq = 1.0 - (pow(val,mut_pow));
}
y = y + deltaq*(yu-yl);
if (y<yl)
{
y = yl;
}
if (y>yu)
{
y = yu;
}
ind->xreal[j] = y;
nrealmut+=;
}
}
return;
}
eta_m 为 实数编码的 多项式变异的 参数, 为全局设定。
(该变异方式是为了模拟二进制编码的单点变异,逻辑比较简单,数学含义不明) 每个个体 的 每个变量 的 实数表示, 以变异概率 pmut_real 进行变异 。
多目标遗传算法 ------ NSGA-II (部分源码解析) 实数、二进制编码的变异操作 mutation.c的更多相关文章
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 二进制编码的个体解码操作 decode.c
种群解码函数 decode_pop 为包装函数, 核心调用函数为 decode_ind , 对每个个体进行解码. /* Routines to decode the population */ ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)辅助变量 双链表操作 list.c
/* A custom doubly linked list implemenation */ # include <stdio.h> # include <stdlib.h> ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)介绍
NSGA(非支配排序遗传算法).NSGA-II(带精英策略的快速非支配排序遗传算法),都是基于遗传算法的多目标优化算法,是基于pareto最优解讨论的多目标优化. 在官网: http://www.ii ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 交叉操作 crossover.c
遗传算法中的交叉操作是 对NSGA-II 源码分析的 最后一部分, 这一部分也是我 从读该算法源代码和看该算法论文理解偏差最大的 函数模块. 这里,首先提一下,遗传算法的 交叉操作.变异操作都 ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)目标函数 problemdef.c
/* Test problem definitions */ # include <stdio.h> # include <stdlib.h> # include <ma ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c
/* Routines for storing population data into files */ # include <stdio.h> # include <stdlib ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 拥挤距离计算 crowddist.c
/* Crowding distance computation routines */ # include <stdio.h> # include <stdlib.h> # ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)README 算法的部分英文解释
This is the Readme file for NSGA-II code. About the Algorithm--------------------------------------- ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c
/* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...
随机推荐
- Vector,ArrayList, LinkedList的区别
1.Vector.ArrayList都是以类似数组的形式存储在内存中,LinkedList则以链表的形式进行存储. 2.List中的元素有序.允许有重复的元素,Set中的元素无序.不允许有重复元素. ...
- ajax跨域请求数据
最近开始接触ajax的跨域请求问题,相比网上说的一大堆,我这里就说得比较浅显了. 关于为什么要跨域这个问题,实际的需求是当网站项目部署在一个域名上的时候,分域可以很好地解决网站卡顿问题(拥有多台服务器 ...
- 个人作业 - Week3 - 案例分析
调研与评测 真实用户采访: 用户姓名: 刘斯盾 用户的背景和需求: 用户是一位计算机专业学生,需要浏览技术博客来扩充自己的学识. 用户使用博客园证明: 产品是否解决用户问题: 在码代码过程中遇到的很多 ...
- python 协程库gevent学习--源码学习(一)
总算还是要来梳理一下这几天深入研究之后学习到的东西了. 这几天一直在看以前跟jd对接的项目写的那个gevent代码.为了查错,基本上深入浅出了一次gevent几个重要部件的实现和其工作的原理. 这里用 ...
- jquery 選擇器
jquery 選擇器有: 元素選擇器: $("p")選擇所有<p> $("p.intro")選擇所有class=“intro”的<p> ...
- .net 手机滑动加载
$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).h ...
- day26 多继承
class A(object): def test(self): print('from A') class B(A): def test(self): print('from B') class C ...
- Linux开机自动挂载存储的两种方式
登录服务器,给查看了下,发现确实是没有自动加载,df -h只能显示本地硬盘的分区,fdisk -l 还是能看到存储空间,这说明这个服务器连接存储是木有问题的. 输入history | grep mou ...
- STM32外设地址查询
问题的提出 DMA传输SDIO驱动的SD卡的数据,其中外设地址的确定 问题的解决 打开数据参考手册,在存储器和总线架构一章存储器映像小节,有一个寄存器组起始地址表,列举所有外设对应的起始地址,再到相应 ...
- bzoj1003/luogu1772 物流运输 (dijkstra+dp)
先求出某一段时间[i,j]一直用同一个路径的最短路,乘上天数,记作cost[i,j] 那就可以设f[i]是前i天的最小代价,f[i]=f[j]+cost[j+1,i]+K #include<bi ...