多目标遗传算法 ------ 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 ...
随机推荐
- 【转】XSHELL下直接下载文件到本地(Windows)
XSHELL下直接下载文件到本地(Windows) http://www.cnblogs.com/davytitan/p/3966606.html
- java中的随机数Random
java中一般有两种随机数,一个是Math中random()方法,一个是Random类. 一.Math.random() : 随即生成0<x<1的小数 实例:如何写,生成随机生成 ...
- Oracle 使用PDB 的情况下进行备份恢复的使用.
1. 关于directory: pdb 需要在container 上面创建directory才可以使用 CDB里面创建的directory是会无反应. 在PDB 里面创建: cmd 之后运行 set ...
- 《mysql从入门到精通》提高
第一 游标的使用 delimiter $$ DROP PROCEDURE IF EXISTS product_in_sheet_handler; CREATE PROCEDURE product_in ...
- 借鉴 学习 DELPHI 通用函数 哈哈
[转]关于Delphi通用涵数 http://m.blog.csdn.net/blog/dragonjiang5460/1196927 2006-9-8阅读2016 评论0 DELPHI程序注册码设计 ...
- python之tkinter使用-滚动条
# GUI:tkinter使用 # 通过调节滚动条改变标签中字体大小 import tkinter as tk def resize(ev=None): '''改变label字体大小''' label ...
- selenium之封装登陆操作
# selenium 封装登录操作举例 import os, time # from selenium import webdriver class LoginPage(): '''登录模块''' d ...
- Python——反射
反射的定义:使用字符串类型的名字 去操作变量 hasattr 函数 与getatter配合使用,用来判断变量是否存在 if hasatter(my,'a'):#如果为真执行 getatter(my,' ...
- ansible系列6-用户管理
第一种:新增用户 ansible host -m user -a "name=zhang shell=/bin/bash groups=admin,root append=yes home= ...
- BZOJ1552[Cerc2007]robotic sort&BZOJ3506[Cqoi2014]排序机械臂——非旋转treap
题目描述 输入 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000. 第二行为N个用空格隔开的正整数,表示N个物品最初排列的编号. 输出 输出共一行,N个用空格隔开 ...