/* 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. import information website

    1. 一个很好的展示如何review paper和response to reviewer的网站:openview 该网站给出了许多paper review的例子(如何你是reviewer,那么可以参 ...

  2. 解决Deprecated: preg_replace(): The /e modifier is deprecated, use

    使用php5.5运行ecshop的时候出现如下错误Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace ...

  3. 自定义 Lint 规则简介

    上个月,笔者在巴黎 Droidcon 的 BarCamp 研讨会上聆听了 Matthew Compton 关于编写自己的 Lint 规则的讲话.深受启发之后,笔者想就此话题做进一步的探索. 定义 如果 ...

  4. POJ - 2711 Leapin' Lizards

    题目大意: 在一个网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一 ...

  5. C#中的WebBrowser控件加载ActiveX插件

    C#中WebBrowser控件,将项目输入更改为x86输出,在页面打开时即可自动加载ActiveX控件

  6. ANDROID_MARS学习笔记_S01原始版_005_RadioGroup\CheckBox\Toast

    一.代码 1.xml(1)radio.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  7. 3.5MM/2.5MM耳机插头定义

    自2009年国内手机耳机接口统一以来,现在国内销售耳机基本就3.5MM和2.5MM两种,当然也有很少BT厂家,就是不用这两种,比如使用MiniUSB等接口作为耳机接口.3.5mm耳机插头按照结构划分, ...

  8. 从 C++ 到 Qt(命令行编译)good

    从 C++ 到 Qt 转载自:http://hi.baidu.com/cyclone/blog/item/8f8f08fa52d22f8758ee9006.html Qt 是 C++ 的库,Qt在an ...

  9. Android-相册效果(图片缩放 自由滑动)

    先上图: 很多时候 我们会有这么一个需求: 展示一组图片 每个Item的图片 可以自由拉伸 滑动 焦点不冲突 网上有很多实现方法 通过自定义Gallery和ImageView来实现 个人不是很推荐 在 ...

  10. 【HDOJ】3909 Sudoku

    DLX的应用,基本题,注意maxnode开大点儿. /* 3909 */ #include <iostream> #include <string> #include < ...