/* 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. mongodb MongoDB 聚合 group

    MongoDB 聚合 MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*). 基本语法为:db.col ...

  2. 简单的php表单

    表单的三种传递机制: $_GET:不安全,传递的参数会显示在url中. $_POST:相对安全,隐形传递. $_REQUEST:宽松的,包含所有 GET.POST.COOKIE 和 FILE 的数据. ...

  3. 十款优秀的在线JavaScript工具介绍

    JavaScript是Web开发者不可或缺的一项技能,它可以为你的网站添加丰富的交互功能和绚丽的视觉效果,以此来增强用户体验. 本文整理了10款非常优秀的在线JavaScript代码工具,涵盖编辑.压 ...

  4. php 数组指针相关函数current(),next(),prev(),end()

    mixed current(array target_array) current()函数返回位于target_array数组当前指针位置的数组值.与next().prev().和end()函数不同, ...

  5. ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件

    一.简介 1.在onListItemClick()中new Intent,Intent以存储序列化后的mp2Info对象作为参数,启动serivce 2.DownloadService在onStart ...

  6. 分析Java的类加载器与ClassLoader(二):classpath与查找类字节码的顺序,分析ExtClassLoader与AppClassLoader的源码

    先回顾一下classpath classpath的作用: classpath的作用是指定查找类的路径:当使用java命令执行一个类(类中的main方法)时,会从classpath中进行查找这个类. 指 ...

  7. C#反射实例应用--------获取程序集信息和通过类名创建类实例

    AppDomain.CurrentDomain.GetAssemblies();获取程序集,但是获取的只是已经加载的dll,引用的获取不到. System.Reflection.Assembly.Ge ...

  8. 更换手机号或者更换手机后QQ设备锁的设置问题

    更换手机号 一步到位,更改密保手机号,OK了 更换手机 老卡插入 登录QQ,OK了 更换手机号和手机 老卡插入新手机 登录QQ 新卡插入新手机 更改密保手机号,OK了

  9. 阿里云数加平台——BI报表使用概述和总结

    先声明一点,本人写此文章初衷只为对前段时间的工作做些总结,并做个记录,以备日后查用,此外也顺便与他人分享一下.当然间接上也为阿里云的大数据平台做了个免费广告.以下开始正文. 首先进入数加服务的控制面板 ...

  10. mac book air 装win7

    1. 使用mac book air A1465中 bootCamp制作启动U盘: 需要U盘一个8G,windows 7 原版镜像ISO安装文件一个,根据bootcamp操作提示选择文件及U盘, 注意U ...