/* Nond-domination based selection routines */

 # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" /* Routine to perform non-dominated sorting */
void fill_nondominated_sort (population *mixed_pop, population *new_pop)
{
int flag;
int i, j;
int end;
int front_size;
int archieve_size;
int rank=;
list *pool;
list *elite;
list *temp1, *temp2;
pool = (list *)malloc(sizeof(list));
elite = (list *)malloc(sizeof(list));
front_size = ;
archieve_size=;
pool->index = -;
pool->parent = NULL;
pool->child = NULL;
elite->index = -;
elite->parent = NULL;
elite->child = NULL;
temp1 = pool;
for (i=; i<*popsize; i++)
{
insert (temp1,i);
temp1 = temp1->child;
}
i=;
do
{
temp1 = pool->child;
insert (elite, temp1->index);
front_size = ;
temp2 = elite->child;
temp1 = del (temp1);
temp1 = temp1->child;
do
{
temp2 = elite->child;
if (temp1==NULL)
{
break;
}
do
{
end = ;
flag = check_dominance (&(mixed_pop->ind[temp1->index]), &(mixed_pop->ind[temp2->index]));
if (flag == )
{
insert (pool, temp2->index);
temp2 = del (temp2);
front_size--;
temp2 = temp2->child;
}
if (flag == )
{
temp2 = temp2->child;
}
if (flag == -)
{
end = ;
}
}
while (end!= && temp2!=NULL);
if (flag == || flag == )
{
insert (elite, temp1->index);
front_size++;
temp1 = del (temp1);
}
temp1 = temp1->child;
}
while (temp1 != NULL);
temp2 = elite->child;
j=i;
if ( (archieve_size+front_size) <= popsize)
{
do
{
copy_ind (&mixed_pop->ind[temp2->index], &new_pop->ind[i]);
new_pop->ind[i].rank = rank;
archieve_size+=;
temp2 = temp2->child;
i+=;
}
while (temp2 != NULL);
assign_crowding_distance_indices (new_pop, j, i-);
rank+=;
}
else
{
crowding_fill (mixed_pop, new_pop, i, front_size, elite);
archieve_size = popsize;
for (j=i; j<popsize; j++)
{
new_pop->ind[j].rank = rank;
}
}
temp2 = elite->child;
do
{
temp2 = del (temp2);
temp2 = temp2->child;
}
while (elite->child !=NULL);
}
while (archieve_size < popsize);
while (pool!=NULL)
{
temp1 = pool;
pool = pool->child;
free (temp1);
}
while (elite!=NULL)
{
temp1 = elite;
elite = elite->child;
free (temp1);
}
return;
}

以上代码,83行代码之前和 rank.c 中代码基本一致,其功能就是选出当前种群的非支配解。

85行到99行代码,意思是,如果该层个体加入到新种群中后个体总数不超过设定的种群个体数则直接加入,

97行代码,调用  assign_crowding_distance_indices , 计算加入个体的拥挤距离。

101行代码 到  108行代码,如果超出总体数量则对该层个体进行选择,并对选择出的个体计算拥挤距离。

此功能  调用

crowding_fill (mixed_pop, new_pop, i, front_size, elite)  函数实现,对该函数分析详见下面分析。
 /* Routine to fill a population with individuals in the decreasing order of crowding distance */
void crowding_fill (population *mixed_pop, population *new_pop, int count, int front_size, list *elite)
{
int *dist;
list *temp;
int i, j;
assign_crowding_distance_list (mixed_pop, elite->child, front_size);
dist = (int *)malloc(front_size*sizeof(int));
temp = elite->child;
for (j=; j<front_size; j++)
{
dist[j] = temp->index;
temp = temp->child;
}
quicksort_dist (mixed_pop, dist, front_size);
for (i=count, j=front_size-; i<popsize; i++, j--)
{
copy_ind(&mixed_pop->ind[dist[j]], &new_pop->ind[i]);
}
free (dist);
return;
}

首先,对该层个体进行拥挤距离判断,由于这些个体还没有加入到新种群中(矩阵),仍然使用链表保持所以调用函数

assign_crowding_distance_list (mixed_pop, elite->child, front_size);

对该层个体进行拥挤距离计算,计算后的距离信息保存在临时种群中  mixed_pop  。

10行 到  14 行 , 用  数组  dist 保存  链表中对应个体的序号(mixed_pop中的序号)。

15行, 对 mixed_pop  中的  dist对应的个体进行拥挤距离排序, 之后dist数组对应个个体序号便是根据拥挤距离排序的。

16行  到  19行, 对排序后的个体索引 dist, 从最大拥挤距离开始选择个体填入到新种群中直到填满为止 。

多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c的更多相关文章

  1. 多目标遗传算法 ------ NSGA-II (部分源码解析)介绍

    NSGA(非支配排序遗传算法).NSGA-II(带精英策略的快速非支配排序遗传算法),都是基于遗传算法的多目标优化算法,是基于pareto最优解讨论的多目标优化. 在官网: http://www.ii ...

  2. 多目标遗传算法 ------ NSGA-II (部分源码解析) 交叉操作 crossover.c

    遗传算法中的交叉操作是 对NSGA-II  源码分析的  最后一部分, 这一部分也是我 从读该算法源代码和看该算法论文理解偏差最大的  函数模块. 这里,首先提一下,遗传算法的  交叉操作.变异操作都 ...

  3. 多目标遗传算法 ------ NSGA-II (部分源码解析)目标函数 problemdef.c

    /* Test problem definitions */ # include <stdio.h> # include <stdlib.h> # include <ma ...

  4. 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c

    /* Routines for storing population data into files */ # include <stdio.h> # include <stdlib ...

  5. 多目标遗传算法 ------ NSGA-II (部分源码解析) 拥挤距离计算 crowddist.c

    /* Crowding distance computation routines */ # include <stdio.h> # include <stdlib.h> # ...

  6. 多目标遗传算法 ------ NSGA-II (部分源码解析)README 算法的部分英文解释

    This is the Readme file for NSGA-II code. About the Algorithm--------------------------------------- ...

  7. 多目标遗传算法 ------ NSGA-II (部分源码解析) 实数、二进制编码的变异操作 mutation.c

    遗传算法的变异操作 /* Mutation routines */ # include <stdio.h> # include <stdlib.h> # include < ...

  8. 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c

    /* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...

  9. 多目标遗传算法 ------ NSGA-II (部分源码解析)二元锦标赛选择 tourselect.c

    tourselect.c  文件中共有两个函数: selection (population *old_pop, population *new_pop) individual* tournament ...

随机推荐

  1. sql里条件is null 在thinkphp里

    $map['字段名'] = array('exp',' is NULL'); 譬如:$condition['url']  = array('exp',' is NULL');

  2. Firefly官方教程之DBentrust使用文档

    原地址: http://bbs.gameres.com/thread_224185.html 1.dbentrust说明该模块主要是对数据库与memcached存储的处理.里面封装了从memcache ...

  3. PIXLCLOUND

    http://pixlcloud.com/main/career/ https://www.recordedfuture.com/siem-threat-intelligence-part-1/

  4. linux下查看机器的硬件信息:

    查看CPU信息(型号) # cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c       8  Intel(R) Xeon(R) CPU    ...

  5. C#博文搜集

    1. abstract (抽象类) 参考1 2. interface (接口) 参考1 3. 委托 C#委托学习

  6. 交叉编译 小米路由器mini 的 python(MIPS)

    看了很多文章,要么说的是用opkg安装python,要么说的是小米路由器的交叉编译,就是没有mini的.学习了这篇文章(http://me.deepgully.com/post/56389167868 ...

  7. misc_register、 register_chrdev 的区别总结

    参考: http://longer.spaces.eepw.com.cn/articles/article/item/60415 http://imganquan.org/blog/?p=350 网上 ...

  8. Drawable(1)各种Drawable Resource介绍

    简介 Drawable Resources(可绘资源) 是一系列可以在屏幕上被绘制的资源文件,它不只是图片,可以是 xml文件,在xml文件中配置各种绘制参数. 常见Drawable Resource ...

  9. Android开发UI之Fragment-Tabbed Activity的使用

    使用ADT新建的时候,可以选择Tabbed Activity,选择新建一个工程. 新建的工程中,选择不同的Tab页显示不同的内容,主要是通过SectionsPagerAdapter类中的Fragmen ...

  10. XCode中Architecturs配置及常见问题

    http://lanvige.github.io/2014/03/19/architecturs-in-xcode/ XCode 5.1升级后因arm64和CocoaPods的原因,痛了一天,终于解决 ...