多目标遗传算法 ------ 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> ...
随机推荐
- windows下安装php真正的多线程扩展pthreads教程
扩展地址:http://docs.php.net/manual/zh/book.pthreads.php 注意事项php5.3或以上,且为线程安全版本.apache和php使用的编译器必须一致.通过p ...
- AD认证
这两天接触到一个新的知识点,AD验证.什么是AD验证?Active Directory——活动目录,活动目录只是LDAP的一个实现,提供LDAP认证.Radius认证和NTML认证,都是标准认证方式 ...
- AC-BM算法原理与代码实现(模式匹配)
AC-BM算法原理与代码实现(模式匹配) AC-BM算法将待匹配的字符串集合转换为一个类似于Aho-Corasick算法的树状有限状态自动机,但构建时不是基于字符串的后缀而是前缀.匹配 时,采取自后向 ...
- android webview js交互 第一节 (java和js交互)
转载请注明出处 挺帅的移动开发专栏 http://blog.csdn.net/wangtingshuai/article/details/8631835 在androi ...
- WCF简单教程
WCF是DotNet体系中很重要的一项技术,但是组内很多组员通过书籍自学的时候 感觉涉及面太广.配置文件太复杂,新名词太多.抓不到头绪,有感于此,决定进行一次组内技术培训,顺便把培训讲义整理到blog ...
- logstash快速入门 (这篇文章很不错 ) | 两种方式往logstash传输数据实例:Apache 日志(从文件获取)、Syslog方式
原文地址:http://www.2cto.com/os/201411/352015.html 原文地址:http://logstash.net/docs/1.4.2/tutorials/getting ...
- JavaScript高级程序设计39.pdf
第13章 事件 JavaScript与HTML之间的交互式通过事件来实现的. 事件流 事件流描述的是从页面中接收事件的顺序,IE和Netscape提出了完全相反的事件流概念,IE是事件冒泡流,Nets ...
- Android JNI 由C/C++本地代码向Java层传递数据
最近做的Android项目需要调用C代码,进行串口通信及与硬件设备通信,因此要用到JNI,其中本地代码需要向Java层返回三个参数,分别为 参数一:int型: 参数二: 通信指令,本地代码中为unsi ...
- Tornado自定义分布式session框架
一.session框架处理请求执行的流程: 1.服务器端生成随机的cookie字符串 2.浏览器发送请求,服务器将cookie返回给浏览器. 3.服务器在生成一个字典.字典的key为cookie,va ...
- 什么时候使用Shell
因为Shell似乎是各UNIX系统之间通用的功能,并且经过了POSIX的标准化.因此,Shell脚本只要“用心写”一次,即可应用到很多系统上.因此,之所以要使用Shell脚本是基于: 简单性:Shel ...