多目标遗传算法 ------ NSGA-II (部分源码解析) 快速排序代码 sort.c
/* Routines for randomized recursive quick-sort */ # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" /* Randomized quick sort routine to sort a population based on a particular objective chosen */
void quicksort_front_obj(population *pop, int objcount, int obj_array[], int obj_array_size)
{
q_sort_front_obj (pop, objcount, obj_array, , obj_array_size-);
return;
} /* Actual implementation of the randomized quick sort used to sort a population based on a particular objective chosen */
void q_sort_front_obj(population *pop, int objcount, int obj_array[], int left, int right)
{
int index;
int temp;
int i, j;
double pivot;
if (left<right)
{
index = rnd (left, right);
temp = obj_array[right];
obj_array[right] = obj_array[index];
obj_array[index] = temp;
pivot = pop->ind[obj_array[right]].obj[objcount];
i = left-;
for (j=left; j<right; j++)
{
if (pop->ind[obj_array[j]].obj[objcount] <= pivot)
{
i+=;
temp = obj_array[j];
obj_array[j] = obj_array[i];
obj_array[i] = temp;
}
}
index=i+;
temp = obj_array[index];
obj_array[index] = obj_array[right];
obj_array[right] = temp;
q_sort_front_obj (pop, objcount, obj_array, left, index-);
q_sort_front_obj (pop, objcount, obj_array, index+, right);
}
return;
}
按照个体的不同 目标函数 序号(objcount), 对种群序号数组obj_array按照拥挤距离进行快速排序。
/* Randomized quick sort routine to sort a population based on crowding distance */
void quicksort_dist(population *pop, int *dist, int front_size)
{
q_sort_dist (pop, dist, , front_size-);
return;
} /* Actual implementation of the randomized quick sort used to sort a population based on crowding distance */
void q_sort_dist(population *pop, int *dist, int left, int right)
{
int index;
int temp;
int i, j;
double pivot;
if (left<right)
{
index = rnd (left, right);
temp = dist[right];
dist[right] = dist[index];
dist[index] = temp;
pivot = pop->ind[dist[right]].crowd_dist;
i = left-;
for (j=left; j<right; j++)
{
if (pop->ind[dist[j]].crowd_dist <= pivot)
{
i+=;
temp = dist[j];
dist[j] = dist[i];
dist[i] = temp;
}
}
index=i+;
temp = dist[index];
dist[index] = dist[right];
dist[right] = temp;
q_sort_dist (pop, dist, left, index-);
q_sort_dist (pop, dist, index+, right);
}
return;
}
将带排序的个体索引序号 按照 拥挤距离 排序。(快速排序法)
多目标遗传算法 ------ NSGA-II (部分源码解析) 快速排序代码 sort.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> ...
随机推荐
- unicode转中文
<pre name="code" class="html">[root@dr-mysql01 ~]# cat a1.pl my $str=" ...
- android Service开机启动及debug
开机启动一个service需要做的工作如下: 1.开发一个receiver用于接收系统广播: public class BootReceiver extends BroadcastReceiver { ...
- JS判断浏览器是否支持某一个CSS3属性
1.引子 css3的出现让浏览器的表现更加的丰富多彩,表现冲击最大的就是动画了,在日常书写动画的时候,很有必要去事先判断浏览器是否支持,尤其是在写CSS3动画库的时候.比如transition的ani ...
- Mac 下配置XAMPP
1:去官方下载 2:安装dmg 3:安装完成后, 网页上提示, 要设置相应的密码, 设置完成. 4:打开对应的app程序, 把 mysql Database运行起来, 不然, 网页上看到的就是未运行状 ...
- HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Relative atomic mass Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- Unity给力插件之Final IK
Final IK细节: 1.Aim IK:设定一个目标,关节末端始终朝向该目标,一般用来做头部的朝向. 步骤: a.在模型头节点处添加Aim空物体并reset b.给模型添加Aim IK组件,并填上A ...
- JavaScript高级程序设计46.pdf
鼠标按钮 只有在主鼠标按钮被单击(或键盘回车键被按下)是才会触发click事件,对于mousedown和mouseup事件,其event对象存在一个button属性,表示按下或者释放按钮.DOM的bu ...
- Hadoop-Map/Reduce之单表连接的实现
MapReduce程序就是根据其特性对数据进行一个简单的逻辑处理,其中最为重要的一个特性就是根据key值将value值进行合并,其次就是在shuffle阶段有排序. 遇到一个MR程序就是要巧妙利用合并 ...
- MySQL数据库建立外键失败的原因总结
在MySQL数据库创建外键时,经常会发生一些错误,这是一件很令人头疼的事.一个典型的错误就是:Can’t create table... 的错误.在很多实例中,这种错误的发生都是因为mysql一直以来 ...
- angular2自学笔记---官网项目(一)
1.单向数据绑定的'插值表达式' angular中最典型的数据显示方式:把HTML模板(template)的控件绑定到angular组件的属性(component相当于一个构造函数,下面例子中的这个构 ...