多目标遗传算法 ------ NSGA-II (部分源码解析) 非支配排序、分层 rank.c
/* Rank assignment routine */ # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" /* Function to assign rank and crowding distance to a population of size pop_size*/
void assign_rank_and_crowding_distance (population *new_pop)
{
int flag;
int i;
int end;
int front_size;
int rank=;
list *orig;
list *cur;
list *temp1, *temp2;
orig = (list *)malloc(sizeof(list));
cur = (list *)malloc(sizeof(list));
front_size = ;
orig->index = -;
orig->parent = NULL;
orig->child = NULL;
cur->index = -;
cur->parent = NULL;
cur->child = NULL;
temp1 = orig; /* 对orig 链表中的个体进行初始化,元素赋值相对的个体序号 */
for (i=; i<popsize; i++)
{
insert (temp1,i);
temp1 = temp1->child;
} /* 支配关系分层的主循环函数 */
do
{
/*
如果orig链表中只有一个个体,则直接对其分层赋值,
因为该层只有一个个体对其拥挤度直接赋值为无穷,并break主循环
*/
if (orig->child->child == NULL)
{
new_pop->ind[orig->child->index].rank = rank;
new_pop->ind[orig->child->index].crowd_dist = INF;
break;
} /*
orig 中的元素为待分层的元素, 此时 cur 链表为空。 取出 orig 链表中的头一个个体插入到 cur 链表中,该操作相当于对以下内循环的初始化
此时,cur链表中只有一个元素
*/
temp1 = orig->child;
insert (cur, temp1->index);
front_size = ;
temp2 = cur->child;
temp1 = del (temp1);
temp1 = temp1->child; do
{
/*temp2 指向cur链表的第一个节点*/
temp2 = cur->child;
do
{
/*结束标志位 归0 */
end = ;
/*判断 orig 和 cur 链表中 temp1, temp2 指针指向的节点元素所对应的个体支配关系 */
flag = check_dominance (&(new_pop->ind[temp1->index]), &(new_pop->ind[temp2->index])); /*若 a支配b ,在orig中插入a,在cur中删除b */
if (flag == )
{
insert (orig, temp2->index);
temp2 = del (temp2);
front_size--;
temp2 = temp2->child; /*个体a b互不支配, cur链表指针下移一位*/
if (flag == )
{
temp2 = temp2->child;
} /*个体b 支配 个体a , 结束该次循环*/
if (flag == -)
{
end = ;
}
}
/*
个体b 被 个体a 支配即 flag==-1, 将该层循环结束位 end置1,结束该层循环。
cur 链表中 所有个体均已遍历,没有b个体,结束循环。
*/
while (end!= && temp2!=NULL); /*
个体a 支配 个体b 或者 互不支配
将个体a 插入到 cur链表最前端,同时移除orig链表中的a个体
*/
if (flag == || flag == )
{
insert (cur, temp1->index);
front_size++;
temp1 = del (temp1);
} /*orig链表中所指向个体的指针后移一位*/
temp1 = temp1->child;
}
/*temp1指针指向NULL意味着orig链表中所有元素对应的个体均被 cur链表中对应的个体 支配*/
while (temp1 != NULL); /*
temp2重新指向 cur 列表中第一个元素,cur列表中的元素为当前已分层的元素
*/
temp2 = cur->child;
do
{
new_pop->ind[temp2->index].rank = rank;
temp2 = temp2->child;
}
while (temp2 != NULL);
/* 对当前层的个体进行拥挤度判断 */
assign_crowding_distance_list (new_pop, cur->child, front_size); /* 对 cur 链表中的个体释放内存空间 */
temp2 = cur->child;
do
{
temp2 = del (temp2);
temp2 = temp2->child;
}
while (cur->child !=NULL);
/* 分层的排序值 加1 */
rank+=;
}
/* 循环判断,直到orig链表中出头节点外为空,即所有个体全部分层 */
while (orig->child!=NULL); /* 将链表orig cur的头结点内存空间释放掉 */
free (orig);
free (cur);
return;
}
该非支配分层基本思想是设置两个双向链表(orig cur),orig 链表里面存放所有待分层排序的个体索引,cur链表中的元素为分层结束后该层的个体索引。
每次在orig 中取出的元素对应的个体为 a, cur 中取出的元素对应的个体为 b 。
若 b支配于 a ,则取 orig 中对应的下一个个体作为 a ,
若 a b 互不支配 ,则依次取 cur 中对应的下一个个体作为 b , 遍历cur 中所有个体(cur 中的个体为待分层的个体,其互不支配),若a 与 cur 中所有个体互不支配则将个体a移除orig链表并插入到cur链表的最前端。
若a 支配于 b, 则将b 个体移除cur 链表并插入到 orig 链表的最前端,同时取cur 中的下一个个体作为 b 。
当遍历orig 中的所有元素,此时 cur 中个体便是此时的非支配解。
多目标遗传算法 ------ NSGA-II (部分源码解析) 非支配排序、分层 rank.c的更多相关文章
- 多目标遗传算法 ------ 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 (部分源码解析) 实数、二进制编码的变异操作 mutation.c
遗传算法的变异操作 /* Mutation routines */ # include <stdio.h> # include <stdlib.h> # include < ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c
/* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)二元锦标赛选择 tourselect.c
tourselect.c 文件中共有两个函数: selection (population *old_pop, population *new_pop) individual* tournament ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c
/* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...
随机推荐
- HAProxy 的负载均衡服务器,Redis 的缓存服务器
问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...
- hadoop2.4.0 安装配置 (2)
hdfs-site.xml 配置如下: <?xml version="1.0" encoding="UTF-8"?> <?xml-styles ...
- RPM是RedHat Package Manager(RedHat软件包管理工具)
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种 ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- linux挂载详解
一 .linux文件结构 文件结构是文件存放在磁盘等存贮设备上的组织方法.主要体现在对文件和目录的组织上.目录提供了管理文件的一个方便而有效的途径. linux使用标准的目录结构,在安装的时候,安装程 ...
- Yours 的博客开张啦!
虽然申请博客已经1个月了,但是一直没有来写,没办法,题都刷不完,哪有心思写啊``` 现在集训终于完了,有了属于自己的时间了.所以该把以前做的题,学的算法好好的整理整理了.一来顺顺思路,二来也可以给后来 ...
- Unity3D游戏UI开发经验谈
原地址:http://news.9ria.com/2013/0629/27679.html 在Unity专场上,108km创始人梁伟国发表了<Unity3D游戏UI开发经验谈>主题演讲.他 ...
- 推荐一本书《深入理解PHP内核》
<深入理解PHP内核> 在线网址:http://www.php-internals.com/
- 网络编程(一) 利用NSURLSession发送GET POST请求
Xcode 7.0后,http链接不能直接访问(https可以),需要在Info.plist增加下面一项才能正确访问. 使用NSURLSession进行网络请求的流程: 1.构造NSURL 2.构造N ...
- 李洪强漫谈iOS开发[C语言-015]-变量的使用