多目标遗传算法 ------ 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 ...
随机推荐
- Sql语句报ORA-01795: 列表中的最大表达式数为 1000
错误信息:java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000,错误信息如下: serviceid是:work -------------other W ...
- 小学四则运算APP 第二阶段冲刺-第三天
团队成员:陈淑筠.杨家安.陈曦 团队选题:小学四则运算APP 第二次冲刺阶段时间:11.29~12.09 本次发布的是判断题的部分代码 panduanset.java import com.examp ...
- B01-java学习-阶段2-面向对象
对象内存分析 构造方法 类的深入解释 预定义类型和自定义类型深入分析和解释 预定义类源码的查看 预定义类和自定义类的对比 跨过类中使用自定义类型作为属性类型的门槛 构造方法的定义和执行过程 编译器提供 ...
- Maven的课堂笔记2
5 maven的核心概念 5.1 项目对象模型 说明: maven根据pom.xml文件,把它转化成项目对象模型(POM),这个时候要解析依赖关系,然后去相对应的maven库中查找到依赖的jar包. ...
- PAT (Basic Level) Practice 1001 害死人不偿命的(3n+1)猜想
https://pintia.cn/problem-sets/994805260223102976/problems/994805325918486528 卡拉兹(Callatz)猜想: 对任何一个自 ...
- PHP + JS 实现大文件分割上传
服务器上传文件会有一定的限制.避免内存消耗过大影响性能,在 php.ini 配置文件中,有几个影响参数: upload_max_filesize = 2M //PHP最大能接受的文件大小 post_m ...
- 关于supervisor 的使用以及配置
首先我个人认为,用python实现的supervisor使用了守护进程这个概念去实现一个包裹进程的概念. 他可以帮助你的进程完成失效重启,日志记录,确保在线,关机自启动等一系列的功能. 当使用supe ...
- __new__ __init__区别
1 class A(object): 2 def __init__(self,*args, **kwargs): 3 print "init A" 4 def __new__(cl ...
- BZOJ4399魔法少女LJJ——线段树合并+并查集
题目描述 在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女LJJ已经觉得自己见过世界上的所有稀奇古怪的事情了LJJ感叹道“这里真是个迷人的绿色世界,空气清新.淡雅,到处散发着醉人的奶浆味: ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...