/* 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. OA学习笔记-001-项目介绍

    基本知识 框架工具 解决方案(经典应用) 项目 12天 ========================================== OA项目, 12天 BBS 一.什么是OA? 辅助管理.提 ...

  2. Android应用架构

    Android开发生态圈的节奏非常之快.每周都会有新的工具诞生,类库的更新,博客的发表以及技术探讨.如果你外出度假一个月,当你回来的时候可能已经发布了新版本的Support Library或者Play ...

  3. 用MATLAB画函数的曲线

    用MATLAB画函数曲线 2013年8月11日 命令funtool 这是单变量函数分析的交互界面,比较方便,特别适用于y=f(x)型,即y与x分开的函数形式.见下图

  4. redis+PHP实现的一个优先级去重队列

    主要思路是用一个set做前端去重缓冲, 若干个list做后端的多优先级消息队列, 用一个进程来进行分发, 即从set中分发消息到队列. set缓冲的设计为当天有效, 所以有个零点问题,有可能在零点前s ...

  5. 一台机器上运行多个ActiveMq

    由于业务需要一台机器上运行多个ActiveMq,这里主要说一下有什么地方不重复: 1.brokerName名称不能重复 2.端口号不能重复uri = tcp://localhost:50509 3.k ...

  6. mysql 限制并发select patch

    限制并发select的patch,代码量很少,主要是为了学习mysql的源码,yy一下. 增加两个全局控制变量: thread_limit_min thread_limit_max 增加一个条件变量: ...

  7. Color the ball HDOJ--1556

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. Rank of Tetris HDU--1881

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. 《C语言程序设计现代方法》第1章 C语言概述

    C语言的特点:C语言是一种底层语言.C语言是一种小型语言.C语言是一种包容性语言. C语言的优点:高效.可移植.功能强大.灵活.标准库.与UNIX系统集成. C语言的缺点:C程序更容易隐藏错误.C程序 ...

  10. Java中Map遍历的四种方案

    在Java中如何遍历Map对象 方式一 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. Map<Integer, Integer> map = new HashM ...