/* 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的更多相关文章

  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 ...

  10. 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c

    /* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...

随机推荐

  1. UML 中关系详解以及在visio中的表示

    http://www.cnblogs.com/kittywei/archive/2013/05/15/3079536.html

  2. 学会使用git

    廖雪峰Git教程 这个教程较为简单,循序渐进 易百Git教程 较为系统 在线代码格式化 可以下载全球最大视频网站的视频支持搜索 点这里

  3. Android Training精要(六)如何防止Bitmap对象出现OOM

    1.使用AsyncTask異步加載bitmap圖片避免OOM: class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> ...

  4. Lua table pair和ipair区别

    官方描述: ipairs (t) Returns three values: an iterator function, the table t, and 0, so that the constru ...

  5. dom4j中 selectSingleNode 或selectNodes获取不到节点的原因总结 (转)

    没想到搞个dom4j会出这么多怪错.. 最近在研究XBRL GL的有关内容,在项目中要求吧XBRL GL导入到11179注册库中,根据11179建立数据库,然后从XBRL GL分类标准中导入数据到数据 ...

  6. wps操作记录

    WPS Excel 1.点击插入---形状:画好方框,选中后右键“编辑文字”,在方框中加入你需要的文字信息 2.点击插入---形状:画出连接线,按住SHIFT拖动可以水平或垂直的直线 3.调整位置.选 ...

  7. 【转】 viewpage禁止滑动--android

    原文网址:http://blog.csdn.net/weiyage/article/details/8175108 最近写一个项目,涉及到viewpager,而变态的客户要求不滑动. 方法很简单 重写 ...

  8. IIS6、IIS7和IIS8各版本的差别

    一.写在前面 目前市面上所用的IIS版本估计都是>=6.0的.所以我们主要以下面三个版本进行讲解 服务器版本 IIS默认版本 server2003 6.0 server2008 7.0 serv ...

  9. ubuntu12.04编译rtems doc目录

    我的rtem的版本是rtems-4.10.2:首先安装textinfo:sudo apt-get install texinfo 然后: cd rtems-4.10.2/doc../bootstrap ...

  10. Java多线程异步调度程序分析(二)

    源自:http://blog.sina.com.cn/s/blog_4cc16fc50100c0uh.html public abstract class Result {   //抽象的结果类 pu ...