多目标遗传算法 ------ 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> ...
随机推荐
- Hibernate:组合模式解决树的映射
树经常用来展示目录结构,那么在Hibernate中怎样解决树的映射问题呢? 先来看一个分销商的树形结构的例子 所有分销商 东北区 辽宁省 沈阳医药 吉林省 华北区 北京市 北京医药 河北省 华南区 那 ...
- 【HDOJ】1175 连连看
BFS.wa了一下午,原来是YES,写成了Yes. #include <iostream> #include <cstdio> #include <cstring> ...
- ChannelFactory.Endpoint 上的地址属性为空。ChannelFactory 的终结点必须指定一个有效的地址。
主体代码如下 IServiceA proxyA; ChannelFactory<IServiceA> factoryA = new ChannelFactory<IServiceA& ...
- lsof 拥有更多的功能
lsof 拥有更多的功能# lsof -i 看系统中有哪些开放的端口,哪些进程.用户在使用它们,比 netstat -lptu 的输出详细. # lsof -i 4 查看IPv4类型的进程COMMA ...
- TCP三次握手四次断开
今天被问到三次握手了,当时只是脑子里有印象,却忘了一些SYN细节,手动微笑. 这么下去还怎么混...赶紧复习个... 三次握手是什么? TCP是面向连接的,无论哪一方向另一方发送数据之前,都必须先在双 ...
- FFT小结
先上模板 #include<cstdio> #include<cmath> <<)*+; typedef long long ll; ll power(ll t,; ...
- easyui-lang-zh_CN.js导入后还是英文提示
<script src="/js/easyUI1.3.3/jquery.easyui.min.js" type="text/javascript"> ...
- xcode5.1 armv7 armv7s arm64 类型, 区分, 概念等
官方: https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/In ...
- win8下光驱消失
导入这个注册表后重启,总算能读了..reg add "HKLM\System\CurrentControlSet\Services\atapi\Controller0" /f /v ...
- ASP.NET生命周期详解 [转]
最近一直在学习ASP.NET MVC的生命周期,发现ASP.NET MVC是建立在ASP.NET Framework基础之上的,所以原来对于ASP.NET WebForm中的很多处理流程,如管道事件等 ...